当前位置: 首页>>代码示例>>C++>>正文


C++ Mat::transform方法代码示例

本文整理汇总了C++中arma::Mat::transform方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::transform方法的具体用法?C++ Mat::transform怎么用?C++ Mat::transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arma::Mat的用法示例。


在下文中一共展示了Mat::transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Forward

  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output)
  {
    arma::mat maxInput = arma::repmat(arma::max(input), input.n_rows, 1);
    output = (maxInput - input);

    // Approximation of the hyperbolic tangent. The acuracy however is
    // about 0.00001 lower as using tanh. Credits go to Leon Bottou.
    output.transform( [](double x)
    {
      //! Fast approximation of exp(-x) for x positive.
      static constexpr double A0 = 1.0;
      static constexpr double A1 = 0.125;
      static constexpr double A2 = 0.0078125;
      static constexpr double A3 = 0.00032552083;
      static constexpr double A4 = 1.0172526e-5;

      if (x < 13.0)
      {
        double y = A0 + x * (A1 + x * (A2 + x * (A3 + x * A4)));
        y *= y;
        y *= y;
        y *= y;
        y = 1 / y;

        return y;
      }

      return 0.0;
    } );

    output = input - (maxInput + std::log(arma::accu(output)));
  }
开发者ID:AmesianX,项目名称:mlpack,代码行数:32,代码来源:log_softmax_layer.hpp

示例2: Fn

 void Fn(const arma::Mat<eT>& x, arma::Mat<eT>& y)
 {
   y = x;
   y.transform( [&](eT val) { return std::min(
       std::max( val, minValue ), maxValue ); } );
 }
开发者ID:DeepCV,项目名称:mlpack,代码行数:6,代码来源:hard_tanh_layer.hpp


注:本文中的arma::Mat::transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。