45 #include "Teuchos_GlobalMPISession.hpp"
56 Real
value(
const std::vector<Real> &x, Real &tol ) {
57 Real half(0.5), quad(0);
58 unsigned size = x.size();
59 for (
unsigned i = 0; i < size; i++ ) {
65 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
66 g.assign(x.begin(),x.end());
69 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
70 hv.assign(v.begin(),v.end());
77 Real
value(
const std::vector<Real> &x, Real &tol ) {
79 unsigned size = x.size();
80 for (
unsigned i = 0; i < size; i++ ) {
86 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
90 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
91 hv.assign(x.size(),0);
98 Real
value(
const std::vector<Real> &x, Real &tol ) {
99 return std::log(x[0]) * std::exp(x[1]);
102 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
103 g[0] = std::exp(x[1])/x[0];
104 g[1] = std::exp(x[1]) * std::log(x[0]);
107 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
108 Real H11 = -std::exp(x[1])/(x[0]*x[0]);
109 Real H12 = std::exp(x[1])/x[0];
110 Real H21 = std::exp(x[1])/x[0];
111 Real H22 = std::exp(x[1]) * std::log(x[0]);
112 hv[0] = H11*v[0] + H12*v[1];
113 hv[1] = H21*v[0] + H22*v[1];
118 unsigned dim = x.size();
119 for (
unsigned i = 0; i < dim; i++ ) {
124 int main(
int argc,
char* argv[]) {
126 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
129 int iprint = argc - 1;
130 ROL::Ptr<std::ostream> outStream;
133 outStream = ROL::makePtrFromRef(std::cout);
135 outStream = ROL::makePtrFromRef(bhs);
145 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(dim,0.0);
146 ROL::Ptr<ROL::Vector<RealT> > x = ROL::makePtr<ROL::StdVector<RealT>>(x_ptr);
148 ROL::Ptr<std::vector<RealT> > d_ptr = ROL::makePtr<std::vector<RealT>>(dim,0.0);
149 ROL::Ptr<ROL::Vector<RealT> > d = ROL::makePtr<ROL::StdVector<RealT>>(d_ptr);
152 std::vector<ROL::Ptr<ROL::Objective<RealT> > > vec_obj(2,ROL::nullPtr);
153 vec_obj[0] = ROL::makePtr<ObjectiveFunctionTest07_1<RealT>>();
154 vec_obj[1] = ROL::makePtr<ObjectiveFunctionTest07_2<RealT>>();
155 ROL::Ptr<ROL::StdObjective<RealT> > obj_scalarize
156 = ROL::makePtr<ObjectiveFunctionTest07_scalarize<RealT>>();
157 ROL::Ptr<ROL::Objective<RealT> > obj
158 = ROL::makePtr<ROL::CompositeObjective<RealT>>(vec_obj,obj_scalarize);
160 *outStream <<
"Check Derivatives of CompositeObjective\n";
161 obj->checkGradient(*x,*d,
true,*outStream);
162 obj->checkHessVec(*x,*d,
true,*outStream);
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 hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
void setRandomVector(std::vector< RealT > &x)
Real value(const std::vector< Real > &x, Real &tol)
Real value(const std::vector< Real > &x, Real &tol)
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
Real value(const std::vector< Real > &x, Real &tol)
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)