11 #include "Teuchos_GlobalMPISession.hpp"
24 ROL::Ptr<const std::vector<Real> > up
26 ROL::Ptr<const std::vector<Real> > zp
28 Real half(0.5), quadu(0), quadz(0);
29 unsigned usize = up->size();
30 for (
unsigned i = 0; i < usize; i++ ) {
31 quadu += (*up)[i]*(*up)[i];
33 unsigned zsize = zp->size();
34 for (
unsigned i = 0; i < zsize; i++ ) {
35 quadz += (*zp)[i]*(*zp)[i];
37 return half*(quadu + quadz);
41 ROL::Ptr<std::vector<Real> > gp
43 ROL::Ptr<const std::vector<Real> > up
45 gp->assign(up->begin(),up->end());
49 ROL::Ptr<std::vector<Real> > gp
51 ROL::Ptr<const std::vector<Real> > zp
53 gp->assign(zp->begin(),zp->end());
58 ROL::Ptr<std::vector<Real> > hvp
60 ROL::Ptr<const std::vector<Real> > vp
62 hvp->assign(vp->begin(),vp->end());
77 ROL::Ptr<std::vector<Real> > hvp
79 ROL::Ptr<const std::vector<Real> > vp
81 hvp->assign(vp->begin(),vp->end());
89 ROL::Ptr<const std::vector<Real> > up
91 ROL::Ptr<const std::vector<Real> > zp
93 Real linu(0), linz(0);
94 unsigned usize = up->size();
95 for (
unsigned i = 0; i < usize; i++ ) {
98 unsigned zsize = zp->size();
99 for (
unsigned i = 0; i < zsize; i++ ) {
106 ROL::Ptr<std::vector<Real> > gp
108 ROL::Ptr<const std::vector<Real> > up
110 gp->assign(up->size(),1);
114 ROL::Ptr<std::vector<Real> > gp
116 ROL::Ptr<const std::vector<Real> > zp
118 gp->assign(zp->size(),1);
145 Real
value(
const std::vector<Real> &x, Real &tol ) {
146 return std::log(x[0]) * std::exp(x[1]);
149 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
150 g[0] = std::exp(x[1])/x[0];
151 g[1] = std::exp(x[1]) * std::log(x[0]);
154 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
155 Real H11 = -std::exp(x[1])/(x[0]*x[0]);
156 Real H12 = std::exp(x[1])/x[0];
157 Real H21 = std::exp(x[1])/x[0];
158 Real H22 = std::exp(x[1]) * std::log(x[0]);
159 hv[0] = H11*v[0] + H12*v[1];
160 hv[1] = H21*v[0] + H22*v[1];
165 unsigned dim = x.size();
166 for (
unsigned i = 0; i <
dim; i++ ) {
171 int main(
int argc,
char* argv[]) {
173 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
176 int iprint = argc - 1;
177 ROL::Ptr<std::ostream> outStream;
180 outStream = ROL::makePtrFromRef(std::cout);
182 outStream = ROL::makePtrFromRef(bhs);
192 ROL::Ptr<std::vector<RealT> > u_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
193 ROL::Ptr<ROL::Vector<RealT> > u = ROL::makePtr<ROL::StdVector<RealT>>(u_ptr);
195 ROL::Ptr<std::vector<RealT> > z_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
196 ROL::Ptr<ROL::Vector<RealT> > z = ROL::makePtr<ROL::StdVector<RealT>>(z_ptr);
198 ROL::Ptr<ROL::Vector<RealT> > x = ROL::makePtr<ROL::Vector_SimOpt<RealT>>(u,z);
199 ROL::Ptr<std::vector<RealT> > du_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
200 ROL::Ptr<ROL::Vector<RealT> > du = ROL::makePtr<ROL::StdVector<RealT>>(du_ptr);
202 ROL::Ptr<std::vector<RealT> > dz_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
203 ROL::Ptr<ROL::Vector<RealT> > dz = ROL::makePtr<ROL::StdVector<RealT>>(dz_ptr);
205 ROL::Ptr<ROL::Vector<RealT> > d = ROL::makePtr<ROL::Vector_SimOpt<RealT>>(du,dz);
207 std::vector<ROL::Ptr<ROL::Objective_SimOpt<RealT> > > vec_obj(2,ROL::nullPtr);
208 vec_obj[0] = ROL::makePtr<ObjectiveFunctionTest08_1<RealT>>();
209 vec_obj[1] = ROL::makePtr<ObjectiveFunctionTest08_2<RealT>>();
210 ROL::Ptr<ROL::StdObjective<RealT> > obj_scalarize
211 = ROL::makePtr<ObjectiveFunctionTest08_scalarize<RealT>>();
212 ROL::Ptr<ROL::CompositeObjective_SimOpt<RealT> > obj
213 = ROL::makePtr<ROL::CompositeObjective_SimOpt<RealT>>(vec_obj,obj_scalarize);
215 *outStream <<
"Check Derivatives of CompositeObjective_SimOpt\n";
216 obj->checkGradient(*x,*d,
true,*outStream);
217 obj->checkHessVec(*x,*d,
true,*outStream);
219 catch (std::logic_error& err) {
220 *outStream << err.what() <<
"\n";
225 std::cout <<
"End Result: TEST FAILED\n";
227 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...
basic_nullstream< char, std::char_traits< char >> nullstream
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.
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.