本文整理汇总了C++中arr::elem方法的典型用法代码示例。如果您正苦于以下问题:C++ arr::elem方法的具体用法?C++ arr::elem怎么用?C++ arr::elem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arr
的用法示例。
在下文中一共展示了arr::elem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: step
bool sRprop::step(arr& w, const arr& grad, uint *singleI) {
if(!stepSize.N) { //initialize
stepSize.resize(w.N);
lastGrad.resize(w.N);
lastGrad.setZero();
stepSize = delta0;
}
CHECK(grad.N==stepSize.N, "Rprop: gradient dimensionality changed!");
CHECK(w.N==stepSize.N , "Rprop: parameter dimensionality changed!");
uint i=0, I=w.N;
if(singleI) {
i=*(singleI);
I=i+1;
}
for(; i<I; i++) {
if(grad.elem(i) * lastGrad(i) > 0) { //same direction as last time
if(rMax) dMax=fabs(rMax*w.elem(i));
stepSize(i) = _mymin(dMax, incr * stepSize(i)); //increase step size
w.elem(i) += stepSize(i) * -_sgn(grad.elem(i)); //step in right direction
lastGrad(i) = grad.elem(i); //memorize gradient
} else if(grad.elem(i) * lastGrad(i) < 0) { //change of direction
stepSize(i) = _mymax(dMin, decr * stepSize(i)); //decrease step size
w.elem(i) += stepSize(i) * -_sgn(grad.elem(i)); //step in right direction (undo half the step)
lastGrad(i) = 0; //memorize to continue below next time
} else { //after change of direcion
w.elem(i) += stepSize(i) * -_sgn(grad.elem(i)); //step in right direction
lastGrad(i) = grad.elem(i); //memorize gradient
}
}
return stepSize.max() < incr*dMin;
}