ROL
ROL_NonlinearLeastSquaresObjective_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_NONLINEARLEASTSQUARESOBJECTIVE_SIMOPT_H
45 #define ROL_NONLINEARLEASTSQUARESOBJECTIVE_SIMOPT_H
46 
47 #include "ROL_Objective.hpp"
49 #include "ROL_Types.hpp"
50 
70 namespace ROL {
71 
72 template <class Real>
73 class Constraint_SimOpt;
74 
75 template <class Real>
77 private:
78  const ROL::Ptr<Constraint_SimOpt<Real> > con_;
79  const bool GaussNewtonHessian_;
80 
81  ROL::Ptr<Vector<Real> > c1_, c2_, cdual_, udual_, z_;
82 
83 public:
92  const Vector<Real> &uvec,
93  const Vector<Real> &zvec,
94  const Vector<Real> &cvec,
95  const bool GNH = false)
96  : con_(con), GaussNewtonHessian_(GNH) {
97  c1_ = cvec.clone();
98  c2_ = cvec.clone();
99  z_ = zvec.clone(); z_->set(zvec);
100  cdual_ = cvec.dual().clone();
101  udual_ = uvec.dual().clone();
102  }
103 
104  void update( const Vector<Real> &u, bool flag = true, int iter = -1 ) {
105  Real tol = std::sqrt(ROL_EPSILON<Real>());
106  con_->update_1(u,flag,iter);
107  con_->value(*c1_,u,*z_,tol);
108  cdual_->set(c1_->dual());
109  }
110 
111  Real value( const Vector<Real> &x, Real &tol ) {
112  Real half(0.5);
113  return half*(c1_->dot(*cdual_));
114  }
115 
116  void gradient( Vector<Real> &g, const Vector<Real> &u, Real &tol ) {
117  con_->applyAdjointJacobian_1(g,*cdual_,u,*z_,tol);
118  }
119 
120  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &u, Real &tol ) {
121  con_->applyJacobian_1(*c2_,v,u,*z_,tol);
122  con_->applyAdjointJacobian_1(hv,c2_->dual(),u,*z_,tol);
123  if ( !GaussNewtonHessian_ ) {
124  con_->applyAdjointHessian_11(*udual_,*cdual_,v,u,*z_,tol);
125  hv.plus(*udual_);
126  }
127  }
128 
129  void precond( Vector<Real> &pv, const Vector<Real> &v, const Vector<Real> &u, Real &tol ) {
130  con_->applyInverseAdjointJacobian_1(*cdual_,v,u,*z_,tol);
131  con_->applyInverseJacobian_1(pv,cdual_->dual(),u,*z_,tol);
132  }
133 
134 // Definitions for parametrized (stochastic) equality constraints
135 public:
136  void setParameter(const std::vector<Real> &param) {
138  con_->setParameter(param);
139  }
140 };
141 
142 } // namespace ROL
143 
144 #endif
Provides the interface to evaluate objective functions.
NonlinearLeastSquaresObjective_SimOpt(const ROL::Ptr< Constraint_SimOpt< Real > > &con, const Vector< Real > &uvec, const Vector< Real > &zvec, const Vector< Real > &cvec, const bool GNH=false)
Constructor.
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 ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void plus(const Vector &x)=0
Compute , where .
void update(const Vector< Real > &u, bool flag=true, int iter=-1)
Update objective function.
Contains definitions of custom data types in ROL.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, Real &tol)
Apply Hessian approximation to vector.
Provides the interface to evaluate nonlinear least squares objective functions.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
void gradient(Vector< Real > &g, const Vector< Real > &u, Real &tol)
Compute gradient.
void precond(Vector< Real > &pv, const Vector< Real > &v, const Vector< Real > &u, Real &tol)
Apply preconditioner to vector.
virtual void setParameter(const std::vector< Real > &param)
Defines the constraint operator interface for simulation-based optimization.
Real value(const Vector< Real > &x, Real &tol)
Compute value.