61 Real
value(
const V &x, Real &tol ) {
67 void hessVec( V &hv,
const V &v,
const V &x, Real &tol ) {
74 Teuchos::RCP<const std::vector<Real> > xp =
77 for(
size_t i=0; i<xp->size(); ++i ) {
78 outStream << (*xp)[i] << std::endl;
87 int main(
int argc,
char *argv[]) {
89 typedef std::vector<RealT> vector;
96 typedef Teuchos::ParameterList PL;
98 using Teuchos::RCP;
using Teuchos::rcp;
100 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
102 int iprint = argc - 1;
103 RCP<std::ostream> outStream;
104 Teuchos::oblackholestream bhs;
106 outStream = rcp(&std::cout,
false);
108 outStream = rcp(&bhs,
false);
115 PL &iplist = parlist.sublist(
"Step").sublist(
"Primal Dual Interior Point");
116 PL &lblist = iplist.sublist(
"Barrier Objective");
119 RealT kappaD = 1.e-4;
120 bool useLinearDamping =
true;
122 lblist.set(
"Use Linear Damping", useLinearDamping);
123 lblist.set(
"Linear Damping Coefficient",kappaD);
124 lblist.set(
"Initial Barrier Parameter",mu);
126 RealT ninf = ROL::ROL_NINF<RealT>();
127 RealT inf = ROL::ROL_INF<RealT>();
130 int numTestVectors = 19;
132 RCP<vector> x_rcp = rcp(
new vector(dim, 0.0) );
133 RCP<vector> d_rcp = rcp(
new vector(dim, 0.0) );
134 RCP<vector> v_rcp = rcp(
new vector(dim, 0.0) );
135 RCP<vector> l_rcp = rcp(
new vector(dim, 0.0) );
136 RCP<vector> u_rcp = rcp(
new vector(dim, 0.0) );
137 RCP<vector> e0_rcp = rcp(
new vector(dim, 0.0) );
144 (*l_rcp)[0] = ninf; (*u_rcp)[0] = 5.0;
145 (*l_rcp)[1] = ninf; (*u_rcp)[1] = inf;
146 (*l_rcp)[2] = -5.0; (*u_rcp)[2] = inf;
147 (*l_rcp)[3] = -5.0; (*u_rcp)[3] = 5.0;
153 RCP<V> x = rcp(
new SV( x_rcp ) );
154 RCP<V> d = rcp(
new SV( d_rcp ) );
155 RCP<V> v = rcp(
new SV( v_rcp ) );
156 RCP<V> l = rcp(
new SV( l_rcp ) );
157 RCP<V> u = rcp(
new SV( u_rcp ) );
159 RCP<const V> maskL, maskU;
164 std::vector<RealT> values(numTestVectors);
165 std::vector<RealT> exact_values(numTestVectors);
167 std::vector<RCP<V> > x_test;
169 for(
int i=0; i<numTestVectors; ++i) {
170 x_test.push_back(x->clone());
171 RealT t =
static_cast<RealT>(i)/static_cast<RealT>(numTestVectors-1);
172 RealT fillValue = xmax*(2.0*t-1.0);
173 x_test[i]->applyUnary(ROL::Elementwise::Fill<RealT>(fillValue));
184 RCP<const std::vector<RealT> > maskL_rcp = Teuchos::dyn_cast<
const SV>(*maskL).getVector();
185 RCP<const std::vector<RealT> > maskU_rcp = Teuchos::dyn_cast<
const SV>(*maskU).getVector();
187 *outStream <<
"\nLower bound vector" << std::endl;
190 *outStream <<
"\nUpper bound vector" << std::endl;
193 *outStream <<
"\nLower mask vector" << std::endl;
196 *outStream <<
"\nUpper mask vector" << std::endl;
199 *outStream <<
"\nChecking Objective value" << std::endl;
201 RealT tol = std::sqrt(ROL::ROL_EPSILON<RealT>());
202 *outStream << std::setw(16) <<
"x[i], i=0,1,2,3" 203 << std::setw(20) <<
"Computed Objective" 204 << std::setw(20) <<
"Exact Objective" << std::endl;
206 RealT valueError(0.0);
208 for(
int i=0; i<numTestVectors; ++i) {
209 values[i] = ipobj.
value(*(x_test[i]),tol);
214 RealT xval = x_test[i]->dot(e0);
217 for(
int j=0; j<dim; ++j) {
218 if( (*maskL_rcp)[j] ) {
219 RealT diff = xval-(*l_rcp)[j];
220 exact_values[i] -= mu*std::log(diff);
222 if( useLinearDamping && !(*maskU_rcp)[j] ) {
223 exact_values[i] += mu*kappaD*diff;
227 if( (*maskU_rcp)[j] ) {
228 RealT diff = (*u_rcp)[j]-xval;
229 exact_values[i] -= mu*std::log(diff);
231 if(useLinearDamping && !(*maskL_rcp)[j] ) {
232 exact_values[i] += mu*kappaD*diff;
238 *outStream << std::setw(16) << xval
239 << std::setw(20) << values[i]
240 << std::setw(20) << exact_values[i] << std::endl;
241 RealT valDiff = exact_values[i] - values[i];
242 valueError += valDiff*valDiff;
245 if(valueError>ROL::ROL_EPSILON<RealT>()) {
249 *outStream <<
"\nPerforming finite difference checks" << std::endl;
251 ipobj.
checkGradient(*x,*v,
true,*outStream); *outStream << std::endl;
252 ipobj.
checkHessVec(*x,*d,
true,*outStream); *outStream << std::endl;
253 ipobj.
checkHessSym(*x,*d,*v,
true,*outStream); *outStream << std::endl;
256 catch (std::logic_error err) {
257 *outStream << err.what() << std::endl;
262 std::cout <<
"End Result: TEST FAILED" << std::endl;
264 std::cout <<
"End Result: TEST PASSED" << std::endl;
Provides the interface to evaluate objective functions.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
void gradient(V &g, const V &x, Real &tol)
Compute gradient.
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
int main(int argc, char *argv[])
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Real value(const V &x, Real &tol)
Compute value.
Provides the interface to evaluate the Interior Pointy log barrier penalty function with upper and lo...
Teuchos::RCP< const Vector< Real > > getLowerMask(void) const
Provides the interface to apply upper and lower bound constraints.
void hessVec(V &hv, const V &v, const V &x, Real &tol)
Apply Hessian approximation to vector.
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
void printVector(const ROL::Vector< Real > &x, std::ostream &outStream)
Teuchos::RCP< const Vector< Real > > getUpperMask(void) const
virtual std::vector< Real > checkHessSym(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &w, const bool printToStream=true, std::ostream &outStream=std::cout)
Hessian symmetry check.