44 #include "Teuchos_oblackholestream.hpp" 45 #include "Teuchos_GlobalMPISession.hpp" 58 Teuchos::RCP<const std::vector<Real> > up
60 Teuchos::RCP<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 Teuchos::RCP<std::vector<Real> > gp
77 Teuchos::RCP<const std::vector<Real> > up
79 gp->assign(up->begin(),up->end());
83 Teuchos::RCP<std::vector<Real> > gp
85 Teuchos::RCP<const std::vector<Real> > zp
87 gp->assign(zp->begin(),zp->end());
92 Teuchos::RCP<std::vector<Real> > hvp
94 Teuchos::RCP<const std::vector<Real> > vp
96 hvp->assign(vp->begin(),vp->end());
111 Teuchos::RCP<std::vector<Real> > hvp
113 Teuchos::RCP<const std::vector<Real> > vp
115 hvp->assign(vp->begin(),vp->end());
123 Teuchos::RCP<const std::vector<Real> > up
125 Teuchos::RCP<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 Teuchos::RCP<std::vector<Real> > gp
142 Teuchos::RCP<const std::vector<Real> > up
144 gp->assign(up->size(),1);
148 Teuchos::RCP<std::vector<Real> > gp
150 Teuchos::RCP<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 Teuchos::RCP<std::ostream> outStream;
212 Teuchos::oblackholestream bhs;
214 outStream = Teuchos::rcp(&std::cout,
false);
216 outStream = Teuchos::rcp(&bhs,
false);
226 Teuchos::RCP<std::vector<RealT> > u_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
229 Teuchos::RCP<std::vector<RealT> > z_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
233 Teuchos::RCP<std::vector<RealT> > du_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
236 Teuchos::RCP<std::vector<RealT> > dz_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
241 std::vector<Teuchos::RCP<ROL::Objective_SimOpt<RealT> > > vec_obj(2,Teuchos::null);
244 Teuchos::RCP<ROL::StdObjective<RealT> > obj_scalarize
246 Teuchos::RCP<ROL::CompositeObjective_SimOpt<RealT> > obj
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.
int main(int argc, char *argv[])
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 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.
Defines the linear algebra or vector space interface for simulation-based optimization.
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 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.
Provides the interface to evaluate simulation-based composite objective functions.
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
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.
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.