44 #include "Teuchos_oblackholestream.hpp" 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 Teuchos::RCP<std::ostream> outStream;
131 Teuchos::oblackholestream bhs;
133 outStream = Teuchos::rcp(&std::cout,
false);
135 outStream = Teuchos::rcp(&bhs,
false);
145 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
148 Teuchos::RCP<std::vector<RealT> > d_rcp = Teuchos::rcp(
new std::vector<RealT>(dim,0.0) );
152 std::vector<Teuchos::RCP<ROL::Objective<RealT> > > vec_obj(2,Teuchos::null);
155 Teuchos::RCP<ROL::StdObjective<RealT> > obj_scalarize
157 Teuchos::RCP<ROL::Objective<RealT> > obj
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)
Real value(const std::vector< Real > &x, Real &tol)
void setRandomVector(std::vector< RealT > &x)
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)
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.
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[])
Provides the interface to evaluate composite objective functions.
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)