52 #include "Teuchos_oblackholestream.hpp" 53 #include "Teuchos_GlobalMPISession.hpp" 58 int main(
int argc,
char *argv[]) {
63 typedef std::vector<RealT> vector;
67 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
70 int iprint = argc - 1;
71 Teuchos::RCP<std::ostream> outStream;
72 Teuchos::oblackholestream bhs;
74 outStream = Teuchos::rcp(&std::cout,
false);
76 outStream = Teuchos::rcp(&bhs,
false);
79 Teuchos::oblackholestream oldFormatState;
80 oldFormatState.copyfmt(std::cout);
87 RealT left = 0.1, right = 0.9;
94 RCP<vector> x_rcp = rcp(
new vector(dim,0.0) );
95 RCP<vector> l_rcp = rcp(
new vector(dim,0.0) );
96 RCP<vector> u_rcp = rcp(
new vector(dim,1.0) );
97 RCP<vector> y_rcp = rcp(
new vector(dim,0.0) );
98 RCP<vector> v_rcp = rcp(
new vector(dim,0.0) );
99 RCP<vector> d_rcp = rcp(
new vector(dim,0.0) );
100 RCP<vector> gx_rcp = rcp(
new vector(dim,0.0) );
101 RCP<vector> gy_rcp = rcp(
new vector(dim,0.0) );
102 RCP<vector> hv_rcp = rcp(
new vector(dim,0.0) );
116 RCP<V> l = rcp(
new SV(l_rcp) );
117 RCP<V> u = rcp(
new SV(u_rcp) );
132 *outStream <<
"Test of single logarithmic penalty objective" << std::endl;
133 log_obj.
checkGradient(x, d,
true, *outStream); *outStream <<
"\n";
134 log_obj.
checkHessVec(x, v,
true, *outStream); *outStream <<
"\n";
136 *outStream <<
"Test of bound constraint as logarithmic penalty objective" << std::endl;
137 bc_obj.
checkGradient(x, d,
true, *outStream); *outStream <<
"\n";
138 bc_obj.
checkHessVec(x, v,
true, *outStream); *outStream <<
"\n";
157 RealT graderr = (fy - fx)/delta - gx.dot(d);
160 RCP<V> dg = gx.clone();
164 RealT hesserr = ( dg->dot(v) )/delta - hv.dot(d);
171 if( std::abs(graderr) > errtol ) {
175 if( std::abs(hesserr) > errtol ) {
180 catch (std::logic_error err) {
181 *outStream << err.what() <<
"\n";
186 std::cout <<
"End Result: TEST FAILED\n";
188 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.
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].
static const double ROL_THRESHOLD
Tolerance for various equality tests.
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.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Provides the interface to apply upper and lower bound constraints.
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.
Create a logarithmic penalty objective from upper and lower bound vectors.