ROL
ROL_Objective_SimOpt.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_OBJECTIVE_SIMOPT_H
45 #define ROL_OBJECTIVE_SIMOPT_H
46 
47 #include "ROL_Objective.hpp"
48 #include "ROL_Vector_SimOpt.hpp"
49 
56 namespace ROL {
57 
58 template <class Real>
59 class Objective_SimOpt : public Objective<Real> {
60 public:
61 
68  virtual void update( const Vector<Real> &u, const Vector<Real> &z, bool flag = true, int iter = -1 ) {}
69 
70  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
71  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
72  dynamic_cast<const ROL::Vector<Real>&>(x));
73  this->update(*(xs.get_1()),*(xs.get_2()),flag,iter);
74  }
75 
76  virtual void update( const Vector<Real> &u, const Vector<Real> &z, UpdateType type, int iter = -1 ) {}
77 
78  void update( const Vector<Real> &x, UpdateType type, int iter = -1 ) {
79  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
80  dynamic_cast<const ROL::Vector<Real>&>(x));
81  this->update(*(xs.get_1()),*(xs.get_2()),type,iter);
82  }
83 
84 
87  virtual Real value( const Vector<Real> &u, const Vector<Real> &z, Real &tol ) = 0;
88 
89  Real value( const Vector<Real> &x, Real &tol ) {
90  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
91  dynamic_cast<const ROL::Vector<Real>&>(x));
92  return this->value(*(xs.get_1()),*(xs.get_2()),tol);
93  }
94 
95 
98  virtual void gradient_1( Vector<Real> &g, const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
99  Real ftol = std::sqrt(ROL_EPSILON<Real>());
100  Real h = 0.0;
101  this->update(u,z,UpdateType::Temp);
102  Real v = this->value(u,z,ftol);
103  Real deriv = 0.0;
104  ROL::Ptr<Vector<Real> > unew = u.clone();
105  g.zero();
106  for (int i = 0; i < g.dimension(); i++) {
107  h = u.dot(*u.basis(i))*tol;
108  unew->set(u);
109  unew->axpy(h,*(u.basis(i)));
110  this->update(*unew,z,UpdateType::Temp);
111  deriv = (this->value(*unew,z,ftol) - v)/h;
112  g.axpy(deriv,*(g.basis(i)));
113  }
114  this->update(u,z,UpdateType::Temp);
115  }
118  virtual void gradient_2( Vector<Real> &g, const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
119  Real ftol = std::sqrt(ROL_EPSILON<Real>());
120  Real h = 0.0;
121  this->update(u,z,UpdateType::Temp);
122  Real v = this->value(u,z,ftol);
123  Real deriv = 0.0;
124  ROL::Ptr<Vector<Real> > znew = z.clone();
125  g.zero();
126  for (int i = 0; i < g.dimension(); i++) {
127  h = z.dot(*z.basis(i))*tol;
128  znew->set(z);
129  znew->axpy(h,*(z.basis(i)));
130  this->update(u,*znew,UpdateType::Temp);
131  deriv = (this->value(u,*znew,ftol) - v)/h;
132  g.axpy(deriv,*(g.basis(i)));
133  }
134  this->update(u,z,UpdateType::Temp);
135  }
136 
137  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
139  dynamic_cast<ROL::Vector<Real>&>(g));
140  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
141  dynamic_cast<const ROL::Vector<Real>&>(x));
142  ROL::Ptr<Vector<Real> > g1 = gs.get_1()->clone();
143  ROL::Ptr<Vector<Real> > g2 = gs.get_2()->clone();
144  this->gradient_1(*g1,*(xs.get_1()),*(xs.get_2()),tol);
145  this->gradient_2(*g2,*(xs.get_1()),*(xs.get_2()),tol);
146  gs.set_1(*g1);
147  gs.set_2(*g2);
148  }
149 
150 
153  virtual void hessVec_11( Vector<Real> &hv, const Vector<Real> &v,
154  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
155  Real gtol = std::sqrt(ROL_EPSILON<Real>());
156  // Compute step length
157  Real h = tol;
158  if (v.norm() > std::sqrt(ROL_EPSILON<Real>())) {
159  h = std::max(1.0,u.norm()/v.norm())*tol;
160  }
161  // Evaluate gradient of first component at (u+hv,z)
162  ROL::Ptr<Vector<Real> > unew = u.clone();
163  unew->set(u);
164  unew->axpy(h,v);
165  this->update(*unew,z,UpdateType::Temp);
166  hv.zero();
167  this->gradient_1(hv,*unew,z,gtol);
168  // Evaluate gradient of first component at (u,z)
169  ROL::Ptr<Vector<Real> > g = hv.clone();
170  this->update(u,z,UpdateType::Temp);
171  this->gradient_1(*g,u,z,gtol);
172  // Compute Newton quotient
173  hv.axpy(-1.0,*g);
174  hv.scale(1.0/h);
175  }
176 
177  virtual void hessVec_12( Vector<Real> &hv, const Vector<Real> &v,
178  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
179  Real gtol = std::sqrt(ROL_EPSILON<Real>());
180  // Compute step length
181  Real h = tol;
182  if (v.norm() > std::sqrt(ROL_EPSILON<Real>())) {
183  h = std::max(1.0,u.norm()/v.norm())*tol;
184  }
185  // Evaluate gradient of first component at (u,z+hv)
186  ROL::Ptr<Vector<Real> > znew = z.clone();
187  znew->set(z);
188  znew->axpy(h,v);
189  this->update(u,*znew,UpdateType::Temp);
190  hv.zero();
191  this->gradient_1(hv,u,*znew,gtol);
192  // Evaluate gradient of first component at (u,z)
193  ROL::Ptr<Vector<Real> > g = hv.clone();
194  this->update(u,z,UpdateType::Temp);
195  this->gradient_1(*g,u,z,gtol);
196  // Compute Newton quotient
197  hv.axpy(-1.0,*g);
198  hv.scale(1.0/h);
199  }
200 
201  virtual void hessVec_21( Vector<Real> &hv, const Vector<Real> &v,
202  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
203  Real gtol = std::sqrt(ROL_EPSILON<Real>());
204  // Compute step length
205  Real h = tol;
206  if (v.norm() > std::sqrt(ROL_EPSILON<Real>())) {
207  h = std::max(1.0,u.norm()/v.norm())*tol;
208  }
209  // Evaluate gradient of first component at (u+hv,z)
210  ROL::Ptr<Vector<Real> > unew = u.clone();
211  unew->set(u);
212  unew->axpy(h,v);
213  this->update(*unew,z,UpdateType::Temp);
214  hv.zero();
215  this->gradient_2(hv,*unew,z,gtol);
216  // Evaluate gradient of first component at (u,z)
217  ROL::Ptr<Vector<Real> > g = hv.clone();
218  this->update(u,z,UpdateType::Temp);
219  this->gradient_2(*g,u,z,gtol);
220  // Compute Newton quotient
221  hv.axpy(-1.0,*g);
222  hv.scale(1.0/h);
223  }
224 
225  virtual void hessVec_22( Vector<Real> &hv, const Vector<Real> &v,
226  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
227  Real gtol = std::sqrt(ROL_EPSILON<Real>());
228  // Compute step length
229  Real h = tol;
230  if (v.norm() > std::sqrt(ROL_EPSILON<Real>())) {
231  h = std::max(1.0,u.norm()/v.norm())*tol;
232  }
233  // Evaluate gradient of first component at (u,z+hv)
234  ROL::Ptr<Vector<Real> > znew = z.clone();
235  znew->set(z);
236  znew->axpy(h,v);
237  this->update(u,*znew,UpdateType::Temp);
238  hv.zero();
239  this->gradient_2(hv,u,*znew,gtol);
240  // Evaluate gradient of first component at (u,z)
241  ROL::Ptr<Vector<Real> > g = hv.clone();
242  this->update(u,z,UpdateType::Temp);
243  this->gradient_2(*g,u,z,gtol);
244  // Compute Newton quotient
245  hv.axpy(-1.0,*g);
246  hv.scale(1.0/h);
247  }
248 
249  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
251  dynamic_cast<ROL::Vector<Real>&>(hv));
252  const ROL::Vector_SimOpt<Real> &vs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
253  dynamic_cast<const ROL::Vector<Real>&>(v));
254  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
255  dynamic_cast<const ROL::Vector<Real>&>(x));
256  ROL::Ptr<Vector<Real> > h11 = (hvs.get_1())->clone();
257  this->hessVec_11(*h11,*(vs.get_1()),*(xs.get_1()),*(xs.get_2()),tol);
258  ROL::Ptr<Vector<Real> > h12 = (hvs.get_1())->clone();
259  this->hessVec_12(*h12,*(vs.get_2()),*(xs.get_1()),*(xs.get_2()),tol);
260  ROL::Ptr<Vector<Real> > h21 = (hvs.get_2())->clone();
261  this->hessVec_21(*h21,*(vs.get_1()),*(xs.get_1()),*(xs.get_2()),tol);
262  ROL::Ptr<Vector<Real> > h22 = (hvs.get_2())->clone();
263  this->hessVec_22(*h22,*(vs.get_2()),*(xs.get_1()),*(xs.get_2()),tol);
264  h11->plus(*h12);
265  hvs.set_1(*h11);
266  h22->plus(*h21);
267  hvs.set_2(*h22);
268  }
269 
270  std::vector<std::vector<Real> > checkGradient_1( const Vector<Real> &u,
271  const Vector<Real> &z,
272  const Vector<Real> &d,
273  const bool printToStream = true,
274  std::ostream & outStream = std::cout,
275  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
276  const int order = 1 ) {
277  return checkGradient_1(u, z, u.dual(), d, printToStream, outStream, numSteps, order);
278  }
279 
280  std::vector<std::vector<Real> > checkGradient_1( const Vector<Real> &u,
281  const Vector<Real> &z,
282  const Vector<Real> &g,
283  const Vector<Real> &d,
284  const bool printToStream,
285  std::ostream & outStream,
286  const int numSteps,
287  const int order ) {
288  std::vector<Real> steps(numSteps);
289  for(int i=0;i<numSteps;++i) {
290  steps[i] = pow(10,-i);
291  }
292 
293  return checkGradient_1(u,z,g,d,steps,printToStream,outStream,order);
294  } // checkGradient_1
295 
296  std::vector<std::vector<Real> > checkGradient_1( const Vector<Real> &u,
297  const Vector<Real> &z,
298  const Vector<Real> &g,
299  const Vector<Real> &d,
300  const std::vector<Real> &steps,
301  const bool printToStream,
302  std::ostream & outStream,
303  const int order ) {
304  ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
305  "Error: finite difference order must be 1,2,3, or 4" );
306 
309 
310  Real tol = std::sqrt(ROL_EPSILON<Real>());
311 
312  int numSteps = steps.size();
313  int numVals = 4;
314  std::vector<Real> tmp(numVals);
315  std::vector<std::vector<Real> > gCheck(numSteps, tmp);
316 
317  // Save the format state of the original outStream.
318  ROL::nullstream oldFormatState;
319  oldFormatState.copyfmt(outStream);
320 
321  // Evaluate objective value at x.
322  this->update(u,z,UpdateType::Temp);
323  Real val = this->value(u,z,tol);
324 
325  // Compute gradient at x.
326  ROL::Ptr<Vector<Real> > gtmp = g.clone();
327  this->gradient_1(*gtmp, u, z, tol);
328  //Real dtg = d.dot(gtmp->dual());
329  Real dtg = d.apply(*gtmp);
330 
331  // Temporary vectors.
332  ROL::Ptr<Vector<Real> > unew = u.clone();
333 
334  for (int i=0; i<numSteps; i++) {
335 
336  Real eta = steps[i];
337 
338  unew->set(u);
339 
340  // Compute gradient, finite-difference gradient, and absolute error.
341  gCheck[i][0] = eta;
342  gCheck[i][1] = dtg;
343 
344  gCheck[i][2] = weights[order-1][0] * val;
345 
346  for(int j=0; j<order; ++j) {
347  // Evaluate at x <- x+eta*c_i*d.
348  unew->axpy(eta*shifts[order-1][j], d);
349 
350  // Only evaluate at shifts where the weight is nonzero
351  if( weights[order-1][j+1] != 0 ) {
352  this->update(*unew,z,UpdateType::Temp);
353  gCheck[i][2] += weights[order-1][j+1] * this->value(*unew,z,tol);
354  }
355  }
356  gCheck[i][2] /= eta;
357 
358  gCheck[i][3] = std::abs(gCheck[i][2] - gCheck[i][1]);
359 
360  if (printToStream) {
361  if (i==0) {
362  outStream << std::right
363  << std::setw(20) << "Step size"
364  << std::setw(20) << "grad'*dir"
365  << std::setw(20) << "FD approx"
366  << std::setw(20) << "abs error"
367  << "\n"
368  << std::setw(20) << "---------"
369  << std::setw(20) << "---------"
370  << std::setw(20) << "---------"
371  << std::setw(20) << "---------"
372  << "\n";
373  }
374  outStream << std::scientific << std::setprecision(11) << std::right
375  << std::setw(20) << gCheck[i][0]
376  << std::setw(20) << gCheck[i][1]
377  << std::setw(20) << gCheck[i][2]
378  << std::setw(20) << gCheck[i][3]
379  << "\n";
380  }
381 
382  }
383 
384  // Reset format state of outStream.
385  outStream.copyfmt(oldFormatState);
386 
387  return gCheck;
388  } // checkGradient_1
389 
390 
391  std::vector<std::vector<Real> > checkGradient_2( const Vector<Real> &u,
392  const Vector<Real> &z,
393  const Vector<Real> &d,
394  const bool printToStream = true,
395  std::ostream & outStream = std::cout,
396  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
397  const int order = 1 ) {
398  return checkGradient_2(u, z, z.dual(), d, printToStream, outStream, numSteps, order);
399  }
400 
401  std::vector<std::vector<Real> > checkGradient_2( const Vector<Real> &u,
402  const Vector<Real> &z,
403  const Vector<Real> &g,
404  const Vector<Real> &d,
405  const bool printToStream,
406  std::ostream & outStream,
407  const int numSteps,
408  const int order ) {
409  std::vector<Real> steps(numSteps);
410  for(int i=0;i<numSteps;++i) {
411  steps[i] = pow(10,-i);
412  }
413 
414  return checkGradient_2(u,z,g,d,steps,printToStream,outStream,order);
415  } // checkGradient_2
416 
417  std::vector<std::vector<Real> > checkGradient_2( const Vector<Real> &u,
418  const Vector<Real> &z,
419  const Vector<Real> &g,
420  const Vector<Real> &d,
421  const std::vector<Real> &steps,
422  const bool printToStream,
423  std::ostream & outStream,
424  const int order ) {
425  ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
426  "Error: finite difference order must be 1,2,3, or 4" );
427 
430 
431  Real tol = std::sqrt(ROL_EPSILON<Real>());
432 
433  int numSteps = steps.size();
434  int numVals = 4;
435  std::vector<Real> tmp(numVals);
436  std::vector<std::vector<Real> > gCheck(numSteps, tmp);
437 
438  // Save the format state of the original outStream.
439  ROL::nullstream oldFormatState;
440  oldFormatState.copyfmt(outStream);
441 
442  // Evaluate objective value at x.
443  this->update(u,z,UpdateType::Temp);
444  Real val = this->value(u,z,tol);
445 
446  // Compute gradient at x.
447  ROL::Ptr<Vector<Real> > gtmp = g.clone();
448  this->gradient_2(*gtmp, u, z, tol);
449  //Real dtg = d.dot(gtmp->dual());
450  Real dtg = d.apply(*gtmp);
451 
452  // Temporary vectors.
453  ROL::Ptr<Vector<Real> > znew = z.clone();
454 
455  for (int i=0; i<numSteps; i++) {
456 
457  Real eta = steps[i];
458 
459  znew->set(z);
460 
461  // Compute gradient, finite-difference gradient, and absolute error.
462  gCheck[i][0] = eta;
463  gCheck[i][1] = dtg;
464 
465  gCheck[i][2] = weights[order-1][0] * val;
466 
467  for(int j=0; j<order; ++j) {
468  // Evaluate at x <- x+eta*c_i*d.
469  znew->axpy(eta*shifts[order-1][j], d);
470 
471  // Only evaluate at shifts where the weight is nonzero
472  if( weights[order-1][j+1] != 0 ) {
473  this->update(u,*znew,UpdateType::Temp);
474  gCheck[i][2] += weights[order-1][j+1] * this->value(u,*znew,tol);
475  }
476  }
477  gCheck[i][2] /= eta;
478 
479  gCheck[i][3] = std::abs(gCheck[i][2] - gCheck[i][1]);
480 
481  if (printToStream) {
482  if (i==0) {
483  outStream << std::right
484  << std::setw(20) << "Step size"
485  << std::setw(20) << "grad'*dir"
486  << std::setw(20) << "FD approx"
487  << std::setw(20) << "abs error"
488  << "\n"
489  << std::setw(20) << "---------"
490  << std::setw(20) << "---------"
491  << std::setw(20) << "---------"
492  << std::setw(20) << "---------"
493  << "\n";
494  }
495  outStream << std::scientific << std::setprecision(11) << std::right
496  << std::setw(20) << gCheck[i][0]
497  << std::setw(20) << gCheck[i][1]
498  << std::setw(20) << gCheck[i][2]
499  << std::setw(20) << gCheck[i][3]
500  << "\n";
501  }
502 
503  }
504 
505  // Reset format state of outStream.
506  outStream.copyfmt(oldFormatState);
507 
508  return gCheck;
509  } // checkGradient_2
510 
511 
512  std::vector<std::vector<Real> > checkHessVec_11( const Vector<Real> &u,
513  const Vector<Real> &z,
514  const Vector<Real> &v,
515  const bool printToStream = true,
516  std::ostream & outStream = std::cout,
517  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
518  const int order = 1 ) {
519 
520  return checkHessVec_11(u, z, u.dual(), v, printToStream, outStream, numSteps, order);
521 
522  }
523 
524  std::vector<std::vector<Real> > checkHessVec_11( const Vector<Real> &u,
525  const Vector<Real> &z,
526  const Vector<Real> &v,
527  const std::vector<Real> &steps,
528  const bool printToStream = true,
529  std::ostream & outStream = std::cout,
530  const int order = 1 ) {
531 
532  return checkHessVec_11(u, z, u.dual(), v, steps, printToStream, outStream, order);
533  }
534 
535 
536  std::vector<std::vector<Real> > checkHessVec_11( const Vector<Real> &u,
537  const Vector<Real> &z,
538  const Vector<Real> &hv,
539  const Vector<Real> &v,
540  const bool printToStream,
541  std::ostream & outStream,
542  const int numSteps,
543  const int order ) {
544  std::vector<Real> steps(numSteps);
545  for(int i=0;i<numSteps;++i) {
546  steps[i] = pow(10,-i);
547  }
548 
549  return checkHessVec_11(u,z,hv,v,steps,printToStream,outStream,order);
550  } // checkHessVec_11
551 
552 
553  std::vector<std::vector<Real> > checkHessVec_11( const Vector<Real> &u,
554  const Vector<Real> &z,
555  const Vector<Real> &hv,
556  const Vector<Real> &v,
557  const std::vector<Real> &steps,
558  const bool printToStream,
559  std::ostream & outStream,
560  const int order ) {
561 
562  ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
563  "Error: finite difference order must be 1,2,3, or 4" );
564 
567 
568 
569  Real tol = std::sqrt(ROL_EPSILON<Real>());
570 
571  int numSteps = steps.size();
572  int numVals = 4;
573  std::vector<Real> tmp(numVals);
574  std::vector<std::vector<Real> > hvCheck(numSteps, tmp);
575 
576  // Save the format state of the original outStream.
577  ROL::nullstream oldFormatState;
578  oldFormatState.copyfmt(outStream);
579 
580  // Compute gradient at x.
581  ROL::Ptr<Vector<Real> > g = hv.clone();
582  this->update(u,z,UpdateType::Temp);
583  this->gradient_1(*g, u, z, tol);
584 
585  // Compute (Hessian at x) times (vector v).
586  ROL::Ptr<Vector<Real> > Hv = hv.clone();
587  this->hessVec_11(*Hv, v, u, z, tol);
588  Real normHv = Hv->norm();
589 
590  // Temporary vectors.
591  ROL::Ptr<Vector<Real> > gdif = hv.clone();
592  ROL::Ptr<Vector<Real> > gnew = hv.clone();
593  ROL::Ptr<Vector<Real> > unew = u.clone();
594 
595  for (int i=0; i<numSteps; i++) {
596 
597  Real eta = steps[i];
598 
599  // Evaluate objective value at x+eta*d.
600  unew->set(u);
601 
602  gdif->set(*g);
603  gdif->scale(weights[order-1][0]);
604 
605  for(int j=0; j<order; ++j) {
606 
607  // Evaluate at x <- x+eta*c_i*d.
608  unew->axpy(eta*shifts[order-1][j], v);
609 
610  // Only evaluate at shifts where the weight is nonzero
611  if( weights[order-1][j+1] != 0 ) {
612  this->update(*unew,z,UpdateType::Temp);
613  this->gradient_1(*gnew, *unew, z, tol);
614  gdif->axpy(weights[order-1][j+1],*gnew);
615  }
616 
617  }
618 
619  gdif->scale(1.0/eta);
620 
621  // Compute norms of hessvec, finite-difference hessvec, and error.
622  hvCheck[i][0] = eta;
623  hvCheck[i][1] = normHv;
624  hvCheck[i][2] = gdif->norm();
625  gdif->axpy(-1.0, *Hv);
626  hvCheck[i][3] = gdif->norm();
627 
628  if (printToStream) {
629  if (i==0) {
630  outStream << std::right
631  << std::setw(20) << "Step size"
632  << std::setw(20) << "norm(Hess*vec)"
633  << std::setw(20) << "norm(FD approx)"
634  << std::setw(20) << "norm(abs error)"
635  << "\n"
636  << std::setw(20) << "---------"
637  << std::setw(20) << "--------------"
638  << std::setw(20) << "---------------"
639  << std::setw(20) << "---------------"
640  << "\n";
641  }
642  outStream << std::scientific << std::setprecision(11) << std::right
643  << std::setw(20) << hvCheck[i][0]
644  << std::setw(20) << hvCheck[i][1]
645  << std::setw(20) << hvCheck[i][2]
646  << std::setw(20) << hvCheck[i][3]
647  << "\n";
648  }
649 
650  }
651 
652  // Reset format state of outStream.
653  outStream.copyfmt(oldFormatState);
654 
655  return hvCheck;
656  } // checkHessVec_11
657 
658 
659  std::vector<std::vector<Real> > checkHessVec_12( const Vector<Real> &u,
660  const Vector<Real> &z,
661  const Vector<Real> &v,
662  const bool printToStream = true,
663  std::ostream & outStream = std::cout,
664  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
665  const int order = 1 ) {
666  return checkHessVec_12(u, z, u.dual(), v, printToStream, outStream, numSteps, order);
667  }
668 
669  std::vector<std::vector<Real> > checkHessVec_12( const Vector<Real> &u,
670  const Vector<Real> &z,
671  const Vector<Real> &v,
672  const std::vector<Real> &steps,
673  const bool printToStream = true,
674  std::ostream & outStream = std::cout,
675  const int order = 1 ) {
676  return checkHessVec_12(u, z, u.dual(), v, steps, printToStream, outStream, order);
677  }
678 
679 
680  std::vector<std::vector<Real> > checkHessVec_12( const Vector<Real> &u,
681  const Vector<Real> &z,
682  const Vector<Real> &hv,
683  const Vector<Real> &v,
684  const bool printToStream,
685  std::ostream & outStream,
686  const int numSteps,
687  const int order ) {
688  std::vector<Real> steps(numSteps);
689  for(int i=0;i<numSteps;++i) {
690  steps[i] = pow(10,-i);
691  }
692 
693  return checkHessVec_12(u,z,hv,v,steps,printToStream,outStream,order);
694  } // checkHessVec_12
695 
696 
697  std::vector<std::vector<Real> > checkHessVec_12( const Vector<Real> &u,
698  const Vector<Real> &z,
699  const Vector<Real> &hv,
700  const Vector<Real> &v,
701  const std::vector<Real> &steps,
702  const bool printToStream,
703  std::ostream & outStream,
704  const int order ) {
705 
706  ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
707  "Error: finite difference order must be 1,2,3, or 4" );
708 
711 
712 
713  Real tol = std::sqrt(ROL_EPSILON<Real>());
714 
715  int numSteps = steps.size();
716  int numVals = 4;
717  std::vector<Real> tmp(numVals);
718  std::vector<std::vector<Real> > hvCheck(numSteps, tmp);
719 
720  // Save the format state of the original outStream.
721  ROL::nullstream oldFormatState;
722  oldFormatState.copyfmt(outStream);
723 
724  // Compute gradient at x.
725  ROL::Ptr<Vector<Real> > g = hv.clone();
726  this->update(u,z,UpdateType::Temp);
727  this->gradient_1(*g, u, z, tol);
728 
729  // Compute (Hessian at x) times (vector v).
730  ROL::Ptr<Vector<Real> > Hv = hv.clone();
731  this->hessVec_12(*Hv, v, u, z, tol);
732  Real normHv = Hv->norm();
733 
734  // Temporary vectors.
735  ROL::Ptr<Vector<Real> > gdif = hv.clone();
736  ROL::Ptr<Vector<Real> > gnew = hv.clone();
737  ROL::Ptr<Vector<Real> > znew = z.clone();
738 
739  for (int i=0; i<numSteps; i++) {
740 
741  Real eta = steps[i];
742 
743  // Evaluate objective value at x+eta*d.
744  znew->set(z);
745 
746  gdif->set(*g);
747  gdif->scale(weights[order-1][0]);
748 
749  for(int j=0; j<order; ++j) {
750 
751  // Evaluate at x <- x+eta*c_i*d.
752  znew->axpy(eta*shifts[order-1][j], v);
753 
754  // Only evaluate at shifts where the weight is nonzero
755  if( weights[order-1][j+1] != 0 ) {
756  this->update(u,*znew,UpdateType::Temp);
757  this->gradient_1(*gnew, u, *znew, tol);
758  gdif->axpy(weights[order-1][j+1],*gnew);
759  }
760 
761  }
762 
763  gdif->scale(1.0/eta);
764 
765  // Compute norms of hessvec, finite-difference hessvec, and error.
766  hvCheck[i][0] = eta;
767  hvCheck[i][1] = normHv;
768  hvCheck[i][2] = gdif->norm();
769  gdif->axpy(-1.0, *Hv);
770  hvCheck[i][3] = gdif->norm();
771 
772  if (printToStream) {
773  if (i==0) {
774  outStream << std::right
775  << std::setw(20) << "Step size"
776  << std::setw(20) << "norm(Hess*vec)"
777  << std::setw(20) << "norm(FD approx)"
778  << std::setw(20) << "norm(abs error)"
779  << "\n"
780  << std::setw(20) << "---------"
781  << std::setw(20) << "--------------"
782  << std::setw(20) << "---------------"
783  << std::setw(20) << "---------------"
784  << "\n";
785  }
786  outStream << std::scientific << std::setprecision(11) << std::right
787  << std::setw(20) << hvCheck[i][0]
788  << std::setw(20) << hvCheck[i][1]
789  << std::setw(20) << hvCheck[i][2]
790  << std::setw(20) << hvCheck[i][3]
791  << "\n";
792  }
793 
794  }
795 
796  // Reset format state of outStream.
797  outStream.copyfmt(oldFormatState);
798 
799  return hvCheck;
800  } // checkHessVec_12
801 
802 
803  std::vector<std::vector<Real> > checkHessVec_21( const Vector<Real> &u,
804  const Vector<Real> &z,
805  const Vector<Real> &v,
806  const bool printToStream = true,
807  std::ostream & outStream = std::cout,
808  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
809  const int order = 1 ) {
810 
811  return checkHessVec_21(u, z, z.dual(), v, printToStream, outStream, numSteps, order);
812 
813  }
814 
815  std::vector<std::vector<Real> > checkHessVec_21( const Vector<Real> &u,
816  const Vector<Real> &z,
817  const Vector<Real> &v,
818  const std::vector<Real> &steps,
819  const bool printToStream = true,
820  std::ostream & outStream = std::cout,
821  const int order = 1 ) {
822 
823  return checkHessVec_21(u, z, z.dual(), v, steps, printToStream, outStream, order);
824  }
825 
826 
827  std::vector<std::vector<Real> > checkHessVec_21( const Vector<Real> &u,
828  const Vector<Real> &z,
829  const Vector<Real> &hv,
830  const Vector<Real> &v,
831  const bool printToStream,
832  std::ostream & outStream,
833  const int numSteps,
834  const int order ) {
835  std::vector<Real> steps(numSteps);
836  for(int i=0;i<numSteps;++i) {
837  steps[i] = pow(10,-i);
838  }
839 
840  return checkHessVec_21(u,z,hv,v,steps,printToStream,outStream,order);
841  } // checkHessVec_21
842 
843 
844  std::vector<std::vector<Real> > checkHessVec_21( const Vector<Real> &u,
845  const Vector<Real> &z,
846  const Vector<Real> &hv,
847  const Vector<Real> &v,
848  const std::vector<Real> &steps,
849  const bool printToStream,
850  std::ostream & outStream,
851  const int order ) {
852 
853  ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
854  "Error: finite difference order must be 1,2,3, or 4" );
855 
858 
859 
860  Real tol = std::sqrt(ROL_EPSILON<Real>());
861 
862  int numSteps = steps.size();
863  int numVals = 4;
864  std::vector<Real> tmp(numVals);
865  std::vector<std::vector<Real> > hvCheck(numSteps, tmp);
866 
867  // Save the format state of the original outStream.
868  ROL::nullstream oldFormatState;
869  oldFormatState.copyfmt(outStream);
870 
871  // Compute gradient at x.
872  ROL::Ptr<Vector<Real> > g = hv.clone();
873  this->update(u,z,UpdateType::Temp);
874  this->gradient_2(*g, u, z, tol);
875 
876  // Compute (Hessian at x) times (vector v).
877  ROL::Ptr<Vector<Real> > Hv = hv.clone();
878  this->hessVec_21(*Hv, v, u, z, tol);
879  Real normHv = Hv->norm();
880 
881  // Temporary vectors.
882  ROL::Ptr<Vector<Real> > gdif = hv.clone();
883  ROL::Ptr<Vector<Real> > gnew = hv.clone();
884  ROL::Ptr<Vector<Real> > unew = u.clone();
885 
886  for (int i=0; i<numSteps; i++) {
887 
888  Real eta = steps[i];
889 
890  // Evaluate objective value at x+eta*d.
891  unew->set(u);
892 
893  gdif->set(*g);
894  gdif->scale(weights[order-1][0]);
895 
896  for(int j=0; j<order; ++j) {
897 
898  // Evaluate at x <- x+eta*c_i*d.
899  unew->axpy(eta*shifts[order-1][j], v);
900 
901  // Only evaluate at shifts where the weight is nonzero
902  if( weights[order-1][j+1] != 0 ) {
903  this->update(*unew,z,UpdateType::Temp);
904  this->gradient_2(*gnew, *unew, z, tol);
905  gdif->axpy(weights[order-1][j+1],*gnew);
906  }
907 
908  }
909 
910  gdif->scale(1.0/eta);
911 
912  // Compute norms of hessvec, finite-difference hessvec, and error.
913  hvCheck[i][0] = eta;
914  hvCheck[i][1] = normHv;
915  hvCheck[i][2] = gdif->norm();
916  gdif->axpy(-1.0, *Hv);
917  hvCheck[i][3] = gdif->norm();
918 
919  if (printToStream) {
920  if (i==0) {
921  outStream << std::right
922  << std::setw(20) << "Step size"
923  << std::setw(20) << "norm(Hess*vec)"
924  << std::setw(20) << "norm(FD approx)"
925  << std::setw(20) << "norm(abs error)"
926  << "\n"
927  << std::setw(20) << "---------"
928  << std::setw(20) << "--------------"
929  << std::setw(20) << "---------------"
930  << std::setw(20) << "---------------"
931  << "\n";
932  }
933  outStream << std::scientific << std::setprecision(11) << std::right
934  << std::setw(20) << hvCheck[i][0]
935  << std::setw(20) << hvCheck[i][1]
936  << std::setw(20) << hvCheck[i][2]
937  << std::setw(20) << hvCheck[i][3]
938  << "\n";
939  }
940 
941  }
942 
943  // Reset format state of outStream.
944  outStream.copyfmt(oldFormatState);
945 
946  return hvCheck;
947  } // checkHessVec_21
948 
949 
950  std::vector<std::vector<Real> > checkHessVec_22( const Vector<Real> &u,
951  const Vector<Real> &z,
952  const Vector<Real> &v,
953  const bool printToStream = true,
954  std::ostream & outStream = std::cout,
955  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
956  const int order = 1 ) {
957 
958  return checkHessVec_22(u, z, z.dual(), v, printToStream, outStream, numSteps, order);
959 
960  }
961 
962  std::vector<std::vector<Real> > checkHessVec_22( const Vector<Real> &u,
963  const Vector<Real> &z,
964  const Vector<Real> &v,
965  const std::vector<Real> &steps,
966  const bool printToStream = true,
967  std::ostream & outStream = std::cout,
968  const int order = 1 ) {
969 
970  return checkHessVec_22(u, z, z.dual(), v, steps, printToStream, outStream, order);
971  }
972 
973 
974  std::vector<std::vector<Real> > checkHessVec_22( const Vector<Real> &u,
975  const Vector<Real> &z,
976  const Vector<Real> &hv,
977  const Vector<Real> &v,
978  const bool printToStream,
979  std::ostream & outStream,
980  const int numSteps,
981  const int order ) {
982  std::vector<Real> steps(numSteps);
983  for(int i=0;i<numSteps;++i) {
984  steps[i] = pow(10,-i);
985  }
986 
987  return checkHessVec_22(u,z,hv,v,steps,printToStream,outStream,order);
988  } // checkHessVec_22
989 
990 
991  std::vector<std::vector<Real> > checkHessVec_22( const Vector<Real> &u,
992  const Vector<Real> &z,
993  const Vector<Real> &hv,
994  const Vector<Real> &v,
995  const std::vector<Real> &steps,
996  const bool printToStream,
997  std::ostream & outStream,
998  const int order ) {
999 
1000  ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
1001  "Error: finite difference order must be 1,2,3, or 4" );
1002 
1005 
1006 
1007  Real tol = std::sqrt(ROL_EPSILON<Real>());
1008 
1009  int numSteps = steps.size();
1010  int numVals = 4;
1011  std::vector<Real> tmp(numVals);
1012  std::vector<std::vector<Real> > hvCheck(numSteps, tmp);
1013 
1014  // Save the format state of the original outStream.
1015  ROL::nullstream oldFormatState;
1016  oldFormatState.copyfmt(outStream);
1017 
1018  // Compute gradient at x.
1019  ROL::Ptr<Vector<Real> > g = hv.clone();
1020  this->update(u,z,UpdateType::Temp);
1021  this->gradient_2(*g, u, z, tol);
1022 
1023  // Compute (Hessian at x) times (vector v).
1024  ROL::Ptr<Vector<Real> > Hv = hv.clone();
1025  this->hessVec_22(*Hv, v, u, z, tol);
1026  Real normHv = Hv->norm();
1027 
1028  // Temporary vectors.
1029  ROL::Ptr<Vector<Real> > gdif = hv.clone();
1030  ROL::Ptr<Vector<Real> > gnew = hv.clone();
1031  ROL::Ptr<Vector<Real> > znew = z.clone();
1032 
1033  for (int i=0; i<numSteps; i++) {
1034 
1035  Real eta = steps[i];
1036 
1037  // Evaluate objective value at x+eta*d.
1038  znew->set(z);
1039 
1040  gdif->set(*g);
1041  gdif->scale(weights[order-1][0]);
1042 
1043  for(int j=0; j<order; ++j) {
1044 
1045  // Evaluate at x <- x+eta*c_i*d.
1046  znew->axpy(eta*shifts[order-1][j], v);
1047 
1048  // Only evaluate at shifts where the weight is nonzero
1049  if( weights[order-1][j+1] != 0 ) {
1050  this->update(u,*znew,UpdateType::Temp);
1051  this->gradient_2(*gnew, u, *znew, tol);
1052  gdif->axpy(weights[order-1][j+1],*gnew);
1053  }
1054 
1055  }
1056 
1057  gdif->scale(1.0/eta);
1058 
1059  // Compute norms of hessvec, finite-difference hessvec, and error.
1060  hvCheck[i][0] = eta;
1061  hvCheck[i][1] = normHv;
1062  hvCheck[i][2] = gdif->norm();
1063  gdif->axpy(-1.0, *Hv);
1064  hvCheck[i][3] = gdif->norm();
1065 
1066  if (printToStream) {
1067  if (i==0) {
1068  outStream << std::right
1069  << std::setw(20) << "Step size"
1070  << std::setw(20) << "norm(Hess*vec)"
1071  << std::setw(20) << "norm(FD approx)"
1072  << std::setw(20) << "norm(abs error)"
1073  << "\n"
1074  << std::setw(20) << "---------"
1075  << std::setw(20) << "--------------"
1076  << std::setw(20) << "---------------"
1077  << std::setw(20) << "---------------"
1078  << "\n";
1079  }
1080  outStream << std::scientific << std::setprecision(11) << std::right
1081  << std::setw(20) << hvCheck[i][0]
1082  << std::setw(20) << hvCheck[i][1]
1083  << std::setw(20) << hvCheck[i][2]
1084  << std::setw(20) << hvCheck[i][3]
1085  << "\n";
1086  }
1087 
1088  }
1089 
1090  // Reset format state of outStream.
1091  outStream.copyfmt(oldFormatState);
1092 
1093  return hvCheck;
1094  } // checkHessVec_22
1095 
1096 }; // class Objective_SimOpt
1097 
1098 } // namespace ROL
1099 
1100 #endif
Provides the interface to evaluate objective functions.
Provides the interface to evaluate simulation-based objective functions.
std::vector< std::vector< Real > > checkGradient_2(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &g, const Vector< Real > &d, const std::vector< Real > &steps, const bool printToStream, std::ostream &outStream, const int order)
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:226
virtual void scale(const Real alpha)=0
Compute where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::Ptr< const Vector< Real > > get_2() const
std::vector< std::vector< Real > > checkGradient_1(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
virtual int dimension() const
Return dimension of the vector space.
Definition: ROL_Vector.hpp:196
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
Definition: ROL_Vector.hpp:238
virtual ROL::Ptr< Vector > basis(const int i) const
Return i-th basis vector.
Definition: ROL_Vector.hpp:182
const double weights[4][5]
Definition: ROL_Types.hpp:868
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153
Defines the linear algebra or vector space interface for simulation-based optimization.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
std::vector< std::vector< Real > > checkHessVec_21(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
std::vector< std::vector< Real > > checkHessVec_12(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
virtual void hessVec_12(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
virtual void update(const Vector< Real > &u, const Vector< Real > &z, UpdateType type, int iter=-1)
void set_1(const Vector< Real > &vec)
std::vector< std::vector< Real > > checkGradient_2(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
virtual void gradient_2(Vector< Real > &g, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Compute gradient with respect to second component.
std::vector< std::vector< Real > > checkHessVec_21(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:167
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
std::vector< std::vector< Real > > checkHessVec_22(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
std::vector< std::vector< Real > > checkHessVec_12(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const bool printToStream, std::ostream &outStream, const int numSteps, const int order)
virtual Real dot(const Vector &x) const =0
Compute where .
std::vector< std::vector< Real > > checkHessVec_12(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream, std::ostream &outStream, const int order)
std::vector< std::vector< Real > > checkHessVec_11(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
virtual void hessVec_21(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
virtual Real value(const Vector< Real > &u, const Vector< Real > &z, Real &tol)=0
Compute value.
std::vector< std::vector< Real > > checkHessVec_11(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
std::vector< std::vector< Real > > checkHessVec_12(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
std::vector< std::vector< Real > > checkHessVec_22(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const bool printToStream, std::ostream &outStream, const int numSteps, const int order)
std::vector< std::vector< Real > > checkHessVec_22(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
std::vector< std::vector< Real > > checkHessVec_11(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream, std::ostream &outStream, const int order)
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual void gradient_1(Vector< Real > &g, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Compute gradient with respect to first component.
virtual void hessVec_22(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Definition: ROL_Types.hpp:74
std::vector< std::vector< Real > > checkGradient_1(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &g, const Vector< Real > &d, const std::vector< Real > &steps, const bool printToStream, std::ostream &outStream, const int order)
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1)
Update objective function. u is an iterate, z is an iterate, flag = true if the iterate has changed...
basic_nullstream< char, char_traits< char >> nullstream
Definition: ROL_Stream.hpp:72
std::vector< std::vector< Real > > checkHessVec_21(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream, std::ostream &outStream, const int order)
virtual Real norm() const =0
Returns where .
Real value(const Vector< Real > &x, Real &tol)
Compute value.
std::vector< std::vector< Real > > checkHessVec_22(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream, std::ostream &outStream, const int order)
std::vector< std::vector< Real > > checkGradient_2(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &g, const Vector< Real > &d, const bool printToStream, std::ostream &outStream, const int numSteps, const int order)
virtual void hessVec_11(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply Hessian approximation to vector.
std::vector< std::vector< Real > > checkHessVec_21(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const bool printToStream, std::ostream &outStream, const int numSteps, const int order)
std::vector< std::vector< Real > > checkGradient_1(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &g, const Vector< Real > &d, const bool printToStream, std::ostream &outStream, const int numSteps, const int order)
std::vector< std::vector< Real > > checkHessVec_11(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &hv, const Vector< Real > &v, const bool printToStream, std::ostream &outStream, const int numSteps, const int order)
void set_2(const Vector< Real > &vec)
ROL::Ptr< const Vector< Real > > get_1() const