本文整理汇总了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)));
}
示例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 ); } );
}