57 #include "Teuchos_oblackholestream.hpp" 58 #include "Teuchos_GlobalMPISession.hpp" 59 #include "Teuchos_XMLParameterListHelpers.hpp" 65 int main(
int argc,
char *argv[]) {
67 using namespace Teuchos;
69 typedef std::vector<RealT> vector;
73 GlobalMPISession mpiSession(&argc, &argv);
76 int iprint = argc - 1;
77 Teuchos::RCP<std::ostream> outStream;
78 Teuchos::oblackholestream bhs;
80 outStream = Teuchos::rcp(&std::cout,
false);
82 outStream = Teuchos::rcp(&bhs,
false);
92 RCP<ParameterList> parlist = rcp(
new ParameterList());
93 std::string paramfile =
"parameters.xml";
94 updateParametersFromXmlFile(paramfile,parlist.ptr());
100 RCP<vector> x_rcp = rcp(
new vector(dim, 0.0) );
103 RCP<vector> k_rcp = rcp(
new vector(dim, 0.0) );
106 RCP<vector> xtest_rcp = rcp(
new vector(dim, 0.0) );
107 RCP<vector> d_rcp = rcp(
new vector(dim, 0.0) );
108 RCP<vector> v_rcp = rcp(
new vector(dim, 0.0) );
109 RCP<vector> hv_rcp = rcp(
new vector(dim, 0.0) );
110 RCP<vector> ihhv_rcp = rcp(
new vector(dim, 0.0) );
113 RealT left = -1e0, right = 1e0;
114 for (
int i=0; i<dim; i++) {
119 RCP<V> k = rcp(
new SV(k_rcp) );
135 obj.
checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
136 obj.
checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
137 obj.
checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
144 *outStream <<
"Checking inverse Hessian" << std::endl;
145 *outStream <<
"||H^{-1}Hv-v|| = " << ihhv.norm() << std::endl;
149 algo.run(x, obj,
true, *outStream);
152 RCP<vector> xtrue_rcp = rcp(
new vector(dim, 0.0) );
158 RealT abserr = x.norm();
159 *outStream << std::scientific <<
"\n Absolute Error: " << abserr << std::endl;
160 if ( abserr > sqrt(ROL::ROL_EPSILON<RealT>()) ) {
164 catch (std::logic_error err) {
165 *outStream << err.what() <<
"\n";
170 std::cout <<
"End Result: TEST FAILED\n";
172 std::cout <<
"End Result: TEST PASSED\n";
void invHessVec(Vector< Real > &ihv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply 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,upper].
Defines the linear algebra or vector space interface.
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.
Provides the std::vector implementation of the ROL::Vector interface.
Provides an interface to run optimization algorithms.
Contains definitions for the Zakharov function as evaluated using only the ROL::Vector interface...
int main(int argc, char *argv[])
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.
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.