56#include "ROL_ParameterList.hpp"
59#include "Teuchos_GlobalMPISession.hpp"
65int main(
int argc,
char *argv[]) {
67 using namespace Teuchos;
69 typedef std::vector<RealT> vector;
73 GlobalMPISession mpiSession(&argc, &argv);
76 auto outStream = ROL::makeStreamPtr( std::cout, argc > 1 );
86 std::string paramfile =
"parameters.xml";
87 auto parlist = ROL::getParametersFromXmlFile( paramfile );
90 ROL::Ptr<ROL::Step<RealT>>
91 step = ROL::makePtr<ROL::TrustRegionStep<RealT>>(*parlist);
92 ROL::Ptr<ROL::StatusTest<RealT>>
93 status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
97 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(
dim, 0.0);
100 ROL::Ptr<vector> k_ptr = ROL::makePtr<vector>(
dim, 0.0);
103 ROL::Ptr<vector> xtest_ptr = ROL::makePtr<vector>(
dim, 0.0);
104 ROL::Ptr<vector> d_ptr = ROL::makePtr<vector>(
dim, 0.0);
105 ROL::Ptr<vector> v_ptr = ROL::makePtr<vector>(
dim, 0.0);
106 ROL::Ptr<vector> hv_ptr = ROL::makePtr<vector>(
dim, 0.0);
107 ROL::Ptr<vector> ihhv_ptr = ROL::makePtr<vector>(
dim, 0.0);
110 RealT left = -1e0, right = 1e0;
111 for (
int i=0; i<
dim; i++) {
116 ROL::Ptr<V> k = ROL::makePtr<SV>(k_ptr);
132 obj.
checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
133 obj.
checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
134 obj.
checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
141 *outStream <<
"Checking inverse Hessian" << std::endl;
142 *outStream <<
"||H^{-1}Hv-v|| = " << ihhv.norm() << std::endl;
146 algo.
run(x, obj,
true, *outStream);
149 ROL::Ptr<vector> xtrue_ptr = ROL::makePtr<vector>(
dim, 0.0);
155 RealT abserr = x.norm();
156 *outStream << std::scientific <<
"\n Absolute Error: " << abserr << std::endl;
157 if ( abserr > sqrt(ROL::ROL_EPSILON<RealT>()) ) {
161 catch (std::logic_error& err) {
162 *outStream << err.what() <<
"\n";
167 std::cout <<
"End Result: TEST FAILED\n";
169 std::cout <<
"End Result: TEST PASSED\n";
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Contains definitions for the Zakharov function as evaluated using only the ROL::Vector interface.
Provides an interface to run optimization algorithms.
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
virtual std::vector< Real > checkHessSym(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &w, const bool printToStream=true, std::ostream &outStream=std::cout)
Hessian symmetry check.
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Defines the linear algebra or vector space interface.
void invHessVec(Vector< Real > &ihv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,...
int main(int argc, char *argv[])