53 #include "Teuchos_oblackholestream.hpp"
54 #include "Teuchos_GlobalMPISession.hpp"
60 int main(
int argc,
char *argv[]) {
62 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
65 int iprint = argc - 1;
66 Teuchos::RCP<std::ostream> outStream;
67 Teuchos::oblackholestream bhs;
69 outStream = Teuchos::rcp(&std::cout,
false);
71 outStream = Teuchos::rcp(&bhs,
false);
81 Teuchos::ParameterList parlist;
83 parlist.set(
"Descent Type",
"Nonlinear-CG");
84 parlist.set(
"Nonlinear CG Type",
"Oren-Luenberger");
85 parlist.set(
"Linesearch Type",
"Cubic Interpolation");
86 parlist.set(
"Linesearch Curvature Condition",
"Wolfe");
88 parlist.set(
"Maximum Number of Function Evaluations", 20);
89 parlist.set(
"Sufficient Decrease Parameter", 1.e-4);
90 parlist.set(
"Curvature Conditions Parameter", 0.9);
91 parlist.set(
"Backtracking Rate", 0.5);
92 parlist.set(
"Initial Linesearch Parameter", 1.0);
93 parlist.set(
"User Defined Linesearch Parameter",
false);
95 parlist.set(
"Absolute Krylov Tolerance", 1.e-4);
96 parlist.set(
"Relative Krylov Tolerance", 1.e-2);
97 parlist.set(
"Maximum Number of Krylov Iterations", 10);
111 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
114 Teuchos::RCP<std::vector<RealT> > k_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
117 Teuchos::RCP<std::vector<RealT> > xtest_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
118 Teuchos::RCP<std::vector<RealT> > d_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
119 Teuchos::RCP<std::vector<RealT> > v_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
120 Teuchos::RCP<std::vector<RealT> > hv_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
121 Teuchos::RCP<std::vector<RealT> > ihhv_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
123 RealT left = -1e0, right = 1e0;
124 for (
int i=0; i<dim; i++) {
128 (*xtest_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
129 (*d_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
130 (*v_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
145 obj.
checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
146 obj.
checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
147 obj.
checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
154 std::cout <<
"Checking inverse Hessian" << std::endl;
155 std::cout <<
"||H^{-1}Hv-v|| = " << ihhv.
norm() << std::endl;
159 std::vector<std::string> output = algo.
run(x, obj,
false);
160 for (
unsigned i = 0; i < output.size(); i++ ) {
161 std::cout << output[i];
165 Teuchos::RCP<std::vector<RealT> > xtrue_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
172 *outStream << std::scientific <<
"\n Absolute Error: " << abserr;
177 catch (std::logic_error err) {
178 *outStream << err.what() <<
"\n";
183 std::cout <<
"End Result: TEST FAILED\n";
185 std::cout <<
"End Result: TEST PASSED\n";
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
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.
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 interface to compute optimization steps with line search.
Real norm() const
Returns where .
Provides the std::vector implementation of the ROL::Vector interface.
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
Provides an interface to check status of 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.
static const double ROL_EPSILON
Platform-dependent machine epsilon.