50 #include "Teuchos_oblackholestream.hpp" 51 #include "Teuchos_GlobalMPISession.hpp" 55 int main(
int argc,
char *argv[]) {
60 typedef std::vector<RealT> vector;
62 typedef Teuchos::RCP<ROL::Vector<RealT> > PVector;
64 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
67 int iprint = argc - 1;
68 Teuchos::RCP<std::ostream> outStream;
69 Teuchos::oblackholestream bhs;
71 outStream = Teuchos::rcp(&std::cout,
false);
73 outStream = Teuchos::rcp(&bhs,
false);
76 Teuchos::oblackholestream oldFormatState;
77 oldFormatState.copyfmt(std::cout);
82 RealT left = 0.1, right = 1.1;
89 RCP<vector> x_rcp = rcp(
new vector(dim,0.0) );
90 RCP<vector> y_rcp = rcp(
new vector(dim,0.0) );
91 RCP<vector> v_rcp = rcp(
new vector(dim,0.0) );
92 RCP<vector> d_rcp = rcp(
new vector(dim,0.0) );
93 RCP<vector> gx_rcp = rcp(
new vector(dim,0.0) );
94 RCP<vector> gy_rcp = rcp(
new vector(dim,0.0) );
95 RCP<vector> hv_rcp = rcp(
new vector(dim,0.0) );
97 for(
int i=0; i<dim; ++i ) {
98 (*x_rcp)[i] = 2+( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
99 (*d_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
100 (*v_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
107 StdVector gx(gx_rcp);
108 StdVector gy(gy_rcp);
109 StdVector hv(hv_rcp);
120 obj.
checkGradient(x, d,
true, *outStream); *outStream <<
"\n";
121 obj.
checkHessVec(x, v,
true, *outStream); *outStream <<
"\n";
139 RealT graderr = (fy - fx)/delta - gx.dot(d);
142 PVector dg = gx.clone();
146 RealT hesserr = ( dg->dot(v) )/delta - hv.dot(d);
148 if( std::abs(graderr) > 1e-8 ) {
152 if( std::abs(hesserr) > 1e-8 ) {
157 catch (std::logic_error err) {
158 *outStream << err.what() <<
"\n";
163 std::cout <<
"End Result: TEST FAILED\n";
165 std::cout <<
"End Result: TEST PASSED\n";
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
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 std::vector implementation of the ROL::Vector interface.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
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.
Log barrier objective for interior point methods.