本文整理汇总了C++中nox::abstract::Group::computeGradient方法的典型用法代码示例。如果您正苦于以下问题:C++ Group::computeGradient方法的具体用法?C++ Group::computeGradient怎么用?C++ Group::computeGradient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nox::abstract::Group
的用法示例。
在下文中一共展示了Group::computeGradient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throwError
bool NOX::Direction::QuasiNewton::compute(NOX::Abstract::Vector& dir,
NOX::Abstract::Group& soln,
const Solver::Generic& solver)
{
NOX::Abstract::Group::ReturnType status;
// Compute F at current solution
status = soln.computeF();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute F");
// Compute Jacobian at current solution.
status = soln.computeJacobian();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute Jacobian");
// Compute the gradient at the current solution
status = soln.computeGradient();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute gradient");
// Push the old information onto the memory, but only after at least one previous iteration
if (solver.getNumIterations() > 0)
{
const NOX::Abstract::Group& oldSoln = solver.getPreviousSolutionGroup();
if (oldSoln.isGradient())
memory.add(soln.getX(), oldSoln.getX(), soln.getGradient(), oldSoln.getGradient());
}
// *** Calculate the QN direction ***
// d = -g
dir = soln.getGradient();
dir.scale(-1.0);
if (!memory.empty())
{
int m = memory.size();
vector<double> alpha(m);
double beta;
for (int i = m-1; i >= 0; i --)
{
alpha[i] = memory[i].rho() * dir.innerProduct( memory[i].s() );
dir.update(-1.0 * alpha[i], memory[i].y(), 1.0);
}
dir.scale( memory[m-1].sdoty() / memory[m-1].ydoty() );
for (int i = 0; i < m; i ++)
{
beta = memory[i].rho() * dir.innerProduct( memory[i].y() );
dir.update(alpha[i] - beta, memory[i].s(), 1.0);
}
}
return true;
}