44 #include "Teuchos_oblackholestream.hpp" 45 #include "Teuchos_GlobalMPISession.hpp" 55 Real
value(
const std::vector<Real> &x, Real &tol ) {
57 unsigned size = x.size();
58 std::vector<Real> p(size+2,1);
59 for (
unsigned i = 0; i < size; i++ ) {
63 return std::exp(p[0])*quad + lin + p[size+1];
66 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
67 unsigned size = x.size();
68 std::vector<Real> p(size+2,1);
70 for (
unsigned i = 0; i < size; i++ ) {
71 g[i] = two*std::exp(p[0])*x[i] + p[i+1];
75 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
76 unsigned size = x.size();
77 std::vector<Real> p(size+2,1);
79 for (
unsigned i = 0; i < size; i++ ) {
80 hv[i] = two*std::exp(p[0])*v[i];
86 unsigned dim = x.size();
87 for (
unsigned i = 0; i < dim; i++ ) {
92 int main(
int argc,
char* argv[]) {
94 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
97 int iprint = argc - 1;
98 Teuchos::RCP<std::ostream> outStream;
99 Teuchos::oblackholestream bhs;
101 outStream = Teuchos::rcp(&std::cout,
false);
103 outStream = Teuchos::rcp(&bhs,
false);
113 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
116 Teuchos::RCP<std::vector<RealT> > d_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
120 Teuchos::RCP<ROL::StdObjective<RealT> > obj =
123 *outStream <<
"Check Derivatives of StdObjective\n";
124 obj->checkGradient(*x,*d,
true,*outStream);
125 obj->checkHessVec(*x,*d,
true,*outStream);
127 catch (std::logic_error err) {
128 *outStream << err.what() <<
"\n";
133 std::cout <<
"End Result: TEST FAILED\n";
135 std::cout <<
"End Result: TEST PASSED\n";
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
void setRandomVector(std::vector< RealT > &x)
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
Provides the std::vector implementation of the ROL::Vector interface.
Real value(const std::vector< Real > &x, Real &tol)
int main(int argc, char *argv[])