45 #include "Teuchos_GlobalMPISession.hpp"
58 ROL::Ptr<const std::vector<Real> > up
60 ROL::Ptr<const std::vector<Real> > zp
62 Real half(0.5), quadu(0), quadz(0);
63 unsigned usize = up->size();
64 for (
unsigned i = 0; i < usize; i++ ) {
65 quadu += (*up)[i]*(*up)[i];
67 unsigned zsize = zp->size();
68 for (
unsigned i = 0; i < zsize; i++ ) {
69 quadz += (*zp)[i]*(*zp)[i];
71 return half*(quadu + quadz);
75 ROL::Ptr<std::vector<Real> > gp
77 ROL::Ptr<const std::vector<Real> > up
79 gp->assign(up->begin(),up->end());
83 ROL::Ptr<std::vector<Real> > gp
85 ROL::Ptr<const std::vector<Real> > zp
87 gp->assign(zp->begin(),zp->end());
92 ROL::Ptr<std::vector<Real> > hvp
94 ROL::Ptr<const std::vector<Real> > vp
96 hvp->assign(vp->begin(),vp->end());
111 ROL::Ptr<std::vector<Real> > hvp
113 ROL::Ptr<const std::vector<Real> > vp
115 hvp->assign(vp->begin(),vp->end());
123 ROL::Ptr<const std::vector<Real> > up
125 ROL::Ptr<const std::vector<Real> > zp
127 Real linu(0), linz(0);
128 unsigned usize = up->size();
129 for (
unsigned i = 0; i < usize; i++ ) {
132 unsigned zsize = zp->size();
133 for (
unsigned i = 0; i < zsize; i++ ) {
140 ROL::Ptr<std::vector<Real> > gp
142 ROL::Ptr<const std::vector<Real> > up
144 gp->assign(up->size(),1);
148 ROL::Ptr<std::vector<Real> > gp
150 ROL::Ptr<const std::vector<Real> > zp
152 gp->assign(zp->size(),1);
179 Real
value(
const std::vector<Real> &x, Real &tol ) {
180 return std::log(x[0]) * std::exp(x[1]);
183 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
184 g[0] = std::exp(x[1])/x[0];
185 g[1] = std::exp(x[1]) * std::log(x[0]);
188 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
189 Real H11 = -std::exp(x[1])/(x[0]*x[0]);
190 Real H12 = std::exp(x[1])/x[0];
191 Real H21 = std::exp(x[1])/x[0];
192 Real H22 = std::exp(x[1]) * std::log(x[0]);
193 hv[0] = H11*v[0] + H12*v[1];
194 hv[1] = H21*v[0] + H22*v[1];
199 unsigned dim = x.size();
200 for (
unsigned i = 0; i <
dim; i++ ) {
205 int main(
int argc,
char* argv[]) {
207 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
210 int iprint = argc - 1;
211 ROL::Ptr<std::ostream> outStream;
214 outStream = ROL::makePtrFromRef(std::cout);
216 outStream = ROL::makePtrFromRef(bhs);
226 ROL::Ptr<std::vector<RealT> > u_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
227 ROL::Ptr<ROL::Vector<RealT> > u = ROL::makePtr<ROL::StdVector<RealT>>(u_ptr);
229 ROL::Ptr<std::vector<RealT> > z_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
230 ROL::Ptr<ROL::Vector<RealT> > z = ROL::makePtr<ROL::StdVector<RealT>>(z_ptr);
232 ROL::Ptr<ROL::Vector<RealT> > x = ROL::makePtr<ROL::Vector_SimOpt<RealT>>(u,z);
233 ROL::Ptr<std::vector<RealT> > du_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
234 ROL::Ptr<ROL::Vector<RealT> > du = ROL::makePtr<ROL::StdVector<RealT>>(du_ptr);
236 ROL::Ptr<std::vector<RealT> > dz_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
237 ROL::Ptr<ROL::Vector<RealT> > dz = ROL::makePtr<ROL::StdVector<RealT>>(dz_ptr);
239 ROL::Ptr<ROL::Vector<RealT> > d = ROL::makePtr<ROL::Vector_SimOpt<RealT>>(du,dz);
241 std::vector<ROL::Ptr<ROL::Objective_SimOpt<RealT> > > vec_obj(2,ROL::nullPtr);
242 vec_obj[0] = ROL::makePtr<ObjectiveFunctionTest08_1<RealT>>();
243 vec_obj[1] = ROL::makePtr<ObjectiveFunctionTest08_2<RealT>>();
244 ROL::Ptr<ROL::StdObjective<RealT> > obj_scalarize
245 = ROL::makePtr<ObjectiveFunctionTest08_scalarize<RealT>>();
246 ROL::Ptr<ROL::CompositeObjective_SimOpt<RealT> > obj
247 = ROL::makePtr<ROL::CompositeObjective_SimOpt<RealT>>(vec_obj,obj_scalarize);
249 *outStream <<
"Check Derivatives of CompositeObjective_SimOpt\n";
250 obj->checkGradient(*x,*d,
true,*outStream);
251 obj->checkHessVec(*x,*d,
true,*outStream);
253 catch (std::logic_error& err) {
254 *outStream << err.what() <<
"\n";
259 std::cout <<
"End Result: TEST FAILED\n";
261 std::cout <<
"End Result: TEST PASSED\n";
Provides the interface to evaluate simulation-based objective functions.
void hessVec_12(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void setRandomVector(std::vector< RealT > &x)
void gradient_2(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to second component.
void hessVec_21(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
void gradient_2(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to second component.
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Real value(const std::vector< Real > &x, Real &tol)
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
void gradient_1(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to first component.
void hessVec_12(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void hessVec_11(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply Hessian approximation to vector.
void hessVec_21(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void hessVec_11(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply Hessian approximation to vector.
Real value(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute value.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
void gradient_1(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to first component.
void hessVec_22(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void hessVec_22(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Real value(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute value.