本文整理汇总了C++中nox::abstract::Group类的典型用法代码示例。如果您正苦于以下问题:C++ Group类的具体用法?C++ Group怎么用?C++ Group使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Group类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void NOX::MeritFunction::SumOfSquares::
computeGradient(const NOX::Abstract::Group& grp,
NOX::Abstract::Vector& result) const
{
if ( !(grp.isF()) ) {
utils->err()
<< "ERROR: NOX::MeritFunction::SumOfSquares::computeGradient() - "
<< "F has not been computed yet!. Please call "
<< "computeF() on the group passed into this function."
<< std::endl;
throw "NOX Error";
}
if ( !(grp.isJacobian()) ) {
utils->err()
<< "ERROR: NOX::MeritFunction::SumOfSquares::computeGradient() - "
<< "Jacobian has not been computed yet!. Please call "
<< "computeJacobian() on the group passed into this function."
<< std::endl;
throw "NOX Error";
}
NOX::Abstract::Group::ReturnType status =
grp.applyJacobianTranspose(grp.getF(), result);
if (status != NOX::Abstract::Group::Ok) {
utils->err() << "ERROR: NOX::MeritFunction::SumOfSquares::compute"
<< "Gradient - applyJacobianTranspose failed!" << std::endl;
throw "NOX Error";
}
return;
}
示例2:
double
NOX::Solver::TensorBased::getNormModelResidual(
const NOX::Abstract::Vector& dir,
const NOX::Abstract::Group& soln,
bool isTensorModel) const
{
// Compute residual of Newton model...
Teuchos::RCP<NOX::Abstract::Vector> residualPtr =
soln.getF().clone(ShapeCopy);
soln.applyJacobian(dir, *residualPtr);
numJvMults++;
residualPtr->update(1.0, soln.getF(), 1.0);
// Compute residual of Tensor model, if requested...
if (isTensorModel)
{
double tmp = sVecPtr->innerProduct(dir);
if (utilsPtr->isPrintType(NOX::Utils::Details))
utilsPtr->out() << " sc'*dt = " << utilsPtr->sciformat(tmp, 6) << std::endl;
residualPtr->update(tmp*tmp, *aVecPtr, 1.0);
}
double modelNorm = residualPtr->norm();
return modelNorm;
}
示例3: switch
double NOX::StatusTest::NormF::computeNorm(const NOX::Abstract::Group& grp)
{
if (!grp.isF())
return -1.0;
double norm;
int n = grp.getX().length();
switch (normType)
{
case NOX::Abstract::Vector::TwoNorm:
norm = grp.getNormF();
if (scaleType == Scaled)
norm /= sqrt(1.0 * n);
break;
default:
norm = grp.getF().norm(normType);
if (scaleType == Scaled)
norm /= n;
break;
}
return norm;
}
示例4: if
bool NOX::Direction::ModifiedNewton::
compute(NOX::Abstract::Vector& dir,
NOX::Abstract::Group& soln,
const NOX::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");
maxAgeOfJacobian = paramsPtr->sublist("Modified-Newton").get("Max Age of Jacobian", 10);
if (Teuchos::is_null(oldJacobianGrpPtr)) {
oldJacobianGrpPtr = soln.clone(DeepCopy);
}
NOX::Abstract::Group& oldJacobianGrp = *oldJacobianGrpPtr;
status = NOX::Abstract::Group::Failed;
while (status != NOX::Abstract::Group::Ok) {
// Conditionally compute Jacobian at current solution.
if ( (ageOfJacobian == -1) || (ageOfJacobian == maxAgeOfJacobian) ) {
if (ageOfJacobian > 0)
oldJacobianGrp = soln;
status = oldJacobianGrp.computeJacobian();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute Jacobian");
ageOfJacobian = 1;
}
else
ageOfJacobian++;
// Compute the Modified Newton direction
status = oldJacobianGrp.applyJacobianInverse(paramsPtr->sublist("Modified-Newton").sublist("Linear Solver"), soln.getF(), dir);
dir.scale(-1.0);
// It didn't converge, but maybe we can recover.
if ((status != NOX::Abstract::Group::Ok) &&
(doRescue == false)) {
throwError("compute", "Unable to solve Newton system");
}
else if ((status != NOX::Abstract::Group::Ok) &&
(doRescue == true)) {
if (utils->isPrintType(NOX::Utils::Warning))
utils->out() << "WARNING: NOX::Direction::ModifiedNewton::compute() - "
<< "Linear solve failed to achieve convergence - "
<< "using the step anyway since \"Rescue Bad Newton Solve\" "
<< "is true. Also, flagging recompute of Jacobian." << std::endl;
ageOfJacobian = maxAgeOfJacobian;
status = NOX::Abstract::Group::Ok;
}
}
return true;
}
示例5: if
bool NOX::Direction::Newton::compute(NOX::Abstract::Vector& dir,
NOX::Abstract::Group& soln,
const NOX::Solver::Generic& solver)
{
NOX::Abstract::Group::ReturnType status;
// Compute F at current solution.
status = soln.computeF();
if (status != NOX::Abstract::Group::Ok)
NOX::Direction::Newton::throwError("compute", "Unable to compute F");
// Reset the linear solver tolerance.
if (useAdjustableForcingTerm) {
resetForcingTerm(soln, solver.getPreviousSolutionGroup(),
solver.getNumIterations(), solver);
}
else {
if (utils->isPrintType(Utils::Details)) {
utils->out() << " CALCULATING FORCING TERM" << endl;
utils->out() << " Method: Constant" << endl;
utils->out() << " Forcing Term: " << eta_k << endl;
}
}
// Compute Jacobian at current solution.
status = soln.computeJacobian();
if (status != NOX::Abstract::Group::Ok)
NOX::Direction::Newton::throwError("compute", "Unable to compute Jacobian");
// Compute the Newton direction
status = soln.computeNewton(paramsPtr->sublist("Newton").sublist("Linear Solver"));
// It didn't converge, but maybe we can recover.
if ((status != NOX::Abstract::Group::Ok) &&
(doRescue == false)) {
NOX::Direction::Newton::throwError("compute",
"Unable to solve Newton system");
}
else if ((status != NOX::Abstract::Group::Ok) &&
(doRescue == true)) {
if (utils->isPrintType(NOX::Utils::Warning))
utils->out() << "WARNING: NOX::Direction::Newton::compute() - Linear solve "
<< "failed to achieve convergence - using the step anyway "
<< "since \"Rescue Bad Newton Solve\" is true " << endl;
}
// Set search direction.
dir = soln.getNewton();
return true;
}
示例6: return
double NOX::MeritFunction::SumOfSquares::
computef(const NOX::Abstract::Group& grp) const
{
if ( !(grp.isF()) ) {
utils->err()
<< "ERROR: NOX::MeritFunction::SumOfSquares::computef() - "
<< "F has not been computed yet!. Please call "
<< "computeF() on the group passed into this function."
<< std::endl;
throw "NOX Error";
}
return (0.5 * grp.getNormF() * grp.getNormF());
}
示例7:
bool NOX::LineSearch::Polynomial::
updateGrp(NOX::Abstract::Group& newGrp,
const NOX::Abstract::Group& oldGrp,
const NOX::Abstract::Vector& dir,
double step) const
{
newGrp.computeX(oldGrp, dir, step);
NOX::Abstract::Group::ReturnType status = newGrp.computeF();
if (status != NOX::Abstract::Group::Ok)
return false;
return true;
}
示例8:
bool NOX::Direction::ModifiedNewton::rescueBadNewtonSolve(const NOX::Abstract::Group& grp) const
{
//! Check if the "rescue" option has been selected
if (!doRescue)
return false;
//! See if the group has compute the accuracy
double accuracy;
NOX::Abstract::Group::ReturnType status = oldJacobianGrpPtr->getNormLastLinearSolveResidual(accuracy);
// If this functionality is not supported in the group, return false
/* NOTE FROM TAMMY: We could later modify this to acutally caluclate
the error itself if it's just a matter of the status being
NotDefined. */
if (status != NOX::Abstract::Group::Ok)
return false;
// Check if there is any improvement in the relative residual
double normF = grp.getNormF();
// If we can't reduce the relative norm at all, we're not happy
if (accuracy >= normF)
return false;
// Otherwise, we just print a warning and keep going
if (utils->isPrintType(NOX::Utils::Warning))
utils->out() << "WARNING: NOX::Direction::ModifiedNewton::compute - Unable to achieve desired linear solve accuracy." << std::endl;
return true;
}
示例9: getNormModelResidual
void
NOX::Solver::TensorBased::printDirectionInfo(std::string dirName,
const NOX::Abstract::Vector& dir,
const NOX::Abstract::Group& soln,
bool isTensorModel) const
{
double dirNorm = dir.norm();
double residual = getNormModelResidual(dir, soln, isTensorModel);
double residualRel = residual / soln.getNormF();
double fprime = getDirectionalDerivative(dir, soln);
double fprimeRel = fprime / dirNorm;
if (utilsPtr->isPrintType(NOX::Utils::Details))
{
utilsPtr->out() << " " << dirName << " norm of model residual = "
<< utilsPtr->sciformat(residual, 6) << " (abs) "
<< utilsPtr->sciformat(residualRel, 6) << " (rel)" << std::endl;
utilsPtr->out() << " " << dirName << " directional derivative = "
<< utilsPtr->sciformat(fprime, 6) << " (abs) "
<< utilsPtr->sciformat(fprimeRel, 6) << " (rel)" << std::endl;
utilsPtr->out() << " " << dirName << " norm = "
<< utilsPtr->sciformat(dirNorm, 6) << std::endl;
}
}
示例10: if
double NOX::MeritFunction::SumOfSquares::
computeSlope(const NOX::Abstract::Vector& dir,
const NOX::Abstract::Group& grp) const
{
if (Teuchos::is_null(tmpVecPtr))
tmpVecPtr = grp.getF().clone();
// If the Jacobian is not computed, approximate it with
// directional derivatives. dir^T J^T F = F^T Jd
if (!(grp.isJacobian()))
return this->computeSlopeWithoutJacobian(dir, grp);
// If the Jacobian is computed but doesn't support a gradient,
// employ a different form for the inner product, eg
// return <v, F> = F' * J * dir = <J'F, dir> = <g, dir>
else if(!(grp.isGradient()))
return this->computeSlopeWithoutJacobianTranspose(dir, grp);
this->computeGradient(grp, *(tmpVecPtr.get()));
return dir.innerProduct(*(tmpVecPtr.get()));
}
示例11: 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;
}
示例12: computeNorm
void NOX::StatusTest::NormF::relativeSetup(NOX::Abstract::Group& initialGuess)
{
NOX::Abstract::Group::ReturnType rtype;
rtype = initialGuess.computeF();
if (rtype != NOX::Abstract::Group::Ok)
{
utils.err() << "NOX::StatusTest::NormF::NormF - Unable to compute F"
<< endl;
throw "NOX Error";
}
initialTolerance = computeNorm(initialGuess);
trueTolerance = specifiedTolerance * initialTolerance;
}
示例13: if
bool
NOX::Solver::TensorBased::implementGlobalStrategy(NOX::Abstract::Group& newGrp,
double& in_stepSize,
const NOX::Solver::Generic& s)
{
bool ok;
counter.incrementNumLineSearches();
isNewtonDirection = false;
NOX::Abstract::Vector& searchDirection = *tensorVecPtr;
if ((counter.getNumLineSearches() == 1) || (lsType == Newton))
{
isNewtonDirection = true;
searchDirection = *newtonVecPtr;
}
// Do line search and compute new soln.
if ((lsType != Dual) || (isNewtonDirection))
ok = performLinesearch(newGrp, in_stepSize, searchDirection, s);
else if (lsType == Dual)
{
double fTensor = 0.0;
double fNew = 0.0;
double tensorStep = 1.0;
bool isTensorDescent = false;
const Abstract::Group& oldGrp = s.getPreviousSolutionGroup();
double fprime = slopeObj.computeSlope(searchDirection, oldGrp);
// Backtrack along tensor direction if it is descent direction.
if (fprime < 0)
{
ok = performLinesearch(newGrp, in_stepSize, searchDirection, s);
assert(ok);
fTensor = 0.5 * newGrp.getNormF() * newGrp.getNormF();
tensorStep = in_stepSize;
isTensorDescent = true;
}
// Backtrack along the Newton direction.
ok = performLinesearch(newGrp, in_stepSize, *newtonVecPtr, s);
fNew = 0.5 * newGrp.getNormF() * newGrp.getNormF();
// If backtracking on the tensor step produced a better step, then use it.
if (isTensorDescent && (fTensor <= fNew))
{
newGrp.computeX(oldGrp, *tensorVecPtr, tensorStep);
newGrp.computeF();
}
}
return ok;
}
示例14:
bool NOX::Direction::Broyden::doRestart(NOX::Abstract::Group& soln,
const NOX::Solver::LineSearchBased& solver)
{
// Test 1 - First iteration!
if (solver.getNumIterations() == 0)
return true;
// Test 2 - Frequency
if (cnt >= cntMax)
return true;
// Test 3 - Last step was zero!
if (solver.getStepSize() == 0.0)
return true;
// Test 4 - Check for convergence rate
convRate = soln.getNormF() / solver.getPreviousSolutionGroup().getNormF();
if (convRate > maxConvRate)
return true;
return false;
}
示例15: while
bool NOX::LineSearch::Backtrack::
compute(NOX::Abstract::Group& grp, double& step,
const NOX::Abstract::Vector& dir,
const NOX::Solver::Generic& s)
{
const Abstract::Group& oldGrp = s.getPreviousSolutionGroup();
double oldF = meritFunctionPtr->computef(oldGrp);
double newF;
bool isFailed = false;
step = defaultStep;
grp.computeX(oldGrp, dir, step);
NOX::Abstract::Group::ReturnType rtype;
rtype = grp.computeF();
if (rtype != NOX::Abstract::Group::Ok)
{
utils->err() << "NOX::LineSearch::BackTrack::compute - Unable to compute F"
<< std::endl;
throw "NOX Error";
}
newF = meritFunctionPtr->computef(grp);
int nIters = 1;
if (utils->isPrintType(Utils::InnerIteration))
{
utils->out() << "\n" << Utils::fill(72) << "\n"
<< "-- Backtrack Line Search -- \n";
}
NOX::StatusTest::FiniteValue checkNAN;
while ( ((newF >= oldF) || (checkNAN.finiteNumberTest(newF) !=0))
&& (!isFailed))
{
if (utils->isPrintType(Utils::InnerIteration))
{
utils->out() << std::setw(3) << nIters << ":";
utils->out() << " step = " << utils->sciformat(step);
utils->out() << " old f = " << utils->sciformat(oldF);
utils->out() << " new f = " << utils->sciformat(newF);
utils->out() << std::endl;
}
nIters ++;
step = step * reductionFactor;
if ((step < minStep) || (nIters > maxIters))
{
isFailed = true;
step = recoveryStep;
}
grp.computeX(oldGrp, dir, step);
rtype = grp.computeF();
if (rtype != NOX::Abstract::Group::Ok)
{
utils->err() << "NOX::LineSearch::BackTrack::compute - Unable to compute F" << std::endl;
throw "NOX Error";
}
newF = meritFunctionPtr->computef(grp);
}
if (utils->isPrintType(Utils::InnerIteration))
{
utils->out() << std::setw(3) << nIters << ":";
utils->out() << " step = " << utils->sciformat(step);
utils->out() << " old f = " << utils->sciformat(oldF);
utils->out() << " new f = " << utils->sciformat(newF);
if (isFailed)
utils->out() << " (USING RECOVERY STEP!)" << std::endl;
else
utils->out() << " (STEP ACCEPTED!)" << std::endl;
utils->out() << Utils::fill(72) << "\n" << std::endl;
}
return (!isFailed);
}