44 #ifndef ROL_BPOEOBJECTIVE_HPP 45 #define ROL_BPOEOBJECTIVE_HPP 47 #include "Teuchos_RCP.hpp" 85 pointGrad_ = x.
dual().clone();
86 pointHess_ = x.
dual().clone();
87 gradient0_ = x.
dual().clone();
88 sumGrad0_ = x.
dual().clone();
89 gradient1_ = x.
dual().clone();
90 sumGrad1_ = x.
dual().clone();
91 gradient2_ = x.
dual().clone();
92 sumGrad2_ = x.
dual().clone();
93 hessvec_ = x.
dual().clone();
94 sumHess_ = x.
dual().clone();
102 if ( !initialized_ ) {
108 const std::vector<Real> ¶m, Real &tol) {
109 if ( storage_ && value_storage_.count(param) ) {
110 val = value_storage_[param];
113 ParametrizedObjective_->setParameter(param);
114 val = ParametrizedObjective_->value(x,tol);
116 value_storage_.insert(std::pair<std::vector<Real>,Real>(param,val));
122 const std::vector<Real> ¶m, Real &tol) {
123 if ( storage_ && gradient_storage_.count(param) ) {
124 g.
set(*(gradient_storage_[param]));
127 ParametrizedObjective_->setParameter(param);
128 ParametrizedObjective_->gradient(g,x,tol);
130 Teuchos::RCP<Vector<Real> > tmp = g.
clone();
131 gradient_storage_.insert(std::pair<std::vector<Real>,Teuchos::RCP<
Vector<Real> > >(param,tmp));
132 gradient_storage_[param]->set(g);
138 const std::vector<Real> ¶m, Real &tol) {
139 ParametrizedObjective_->setParameter(param);
140 ParametrizedObjective_->hessVec(hv,v,x,tol);
147 const Real order,
const Real threshold,
151 const bool storage =
true )
152 : ParametrizedObjective_(pObj), order_(order), threshold_(threshold),
153 ValueSampler_(vsampler), GradientSampler_(gsampler), HessianSampler_(hsampler),
154 storage_(storage), initialized_(false) {
155 value_storage_.clear();
156 gradient_storage_.clear();
160 const Real order,
const Real threshold,
163 const bool storage =
true )
164 : ParametrizedObjective_(pObj), order_(order), threshold_(threshold),
165 ValueSampler_(vsampler), GradientSampler_(gsampler), HessianSampler_(gsampler),
166 storage_(storage), initialized_(false) {
167 value_storage_.clear();
168 gradient_storage_.clear();
172 const Real order,
const Real threshold,
174 const bool storage =
true )
175 : ParametrizedObjective_(pObj), order_(order), threshold_(threshold),
176 ValueSampler_(sampler), GradientSampler_(sampler), HessianSampler_(sampler),
177 storage_(storage), initialized_(false) {
178 value_storage_.clear();
179 gradient_storage_.clear();
183 Teuchos::RCP<Vector<Real> > xvec; Real xvar = 0.0;
185 ParametrizedObjective_->update(*xvec,flag,iter);
186 ValueSampler_->update(*xvec);
188 value_storage_.clear();
191 GradientSampler_->update(*xvec);
192 HessianSampler_->update(*xvec);
194 gradient_storage_.clear();
200 Teuchos::RCP<Vector<Real> > xvec; Real xvar = 0.0;
203 std::vector<Real> point;
204 Real weight = 0.0, myval = 0.0, pval = 0.0, val = 0.0, bp = 0.0;
205 int start = ValueSampler_->start(), end = ValueSampler_->numMySamples();
206 for (
int i = start; i < end; i++ ) {
207 weight = ValueSampler_->getMyWeight(i);
208 point = ValueSampler_->getMyPoint(i);
214 myval += weight*((order_==1.0) ? bp
215 : std::pow(bp,order_));
219 ValueSampler_->sumAll(&myval,&val,1);
221 return ((order_==1.0) ? val : std::pow(val,1.0/order_));
225 Teuchos::RCP<Vector<Real> > xvec; Real xvar = 0.0;
229 g.
zero(); sumGrad0_->zero(); pointGrad_->zero();
230 std::vector<Real> point, val(2,0.0), myval(2,0.0);
231 Real weight = 0.0, pval = 0.0, pvalp0 = 0.0, pvalp1 = 0.0, bp = 0.0;
232 int start = GradientSampler_->start(), end = GradientSampler_->numMySamples();
233 for (
int i = start; i < end; i++ ) {
234 weight = GradientSampler_->getMyWeight(i);
235 point = GradientSampler_->getMyPoint(i);
241 pvalp0 = ((order_==1.0) ? bp
242 : std::pow(bp,order_));
243 pvalp1 = ((order_==1.0) ? 1.0
244 : ((order_==2.0) ? bp
245 : std::pow(bp,order_-1.0)));
247 myval[0] += weight*pvalp0;
252 sumGrad0_->axpy(weight*pvalp1,*pointGrad_);
256 GradientSampler_->sumAll(&myval[0],&val[0],2);
258 Real gvar = 0.0; gradient0_->zero();
259 if ( std::abs(val[0]) >= ROL_EPSILON<Real>()) {
260 GradientSampler_->sumAll(*sumGrad0_,*gradient0_);
261 Real norm = std::pow(val[0],(order_-1.0)/order_);
262 gradient0_->scale(xvar/norm);
272 Teuchos::RCP<Vector<Real> > xvec; Real xvar = 0.0;
274 Teuchos::RCP<Vector<Real> > vvec; Real vvar = 0.0;
278 hv.
zero(); sumHess_->zero(); hessvec_->zero();
279 sumGrad0_->zero(); sumGrad1_->zero(); sumGrad2_->zero();
280 gradient0_->zero(); gradient1_->zero(); gradient2_->zero();
281 std::vector<Real> point, val(5,0.0), myval(5,0.0);
282 Real pval = 0.0, pvalp0 = 0.0, pvalp1 = 0.0, pvalp2 = 0.0;
283 Real weight = 0.0, gv = 0.0, bp = 0.0;
284 int start = HessianSampler_->start(), end = HessianSampler_->numMySamples();
285 for (
int i = start; i < end; i++ ) {
287 weight = HessianSampler_->getMyWeight(i);
288 point = HessianSampler_->getMyPoint(i);
294 pvalp0 = ((order_==1.0) ? bp
295 : std::pow(bp,order_));
296 pvalp1 = ((order_==1.0) ? 1.0
297 : ((order_==2.0) ? bp
298 : std::pow(bp,order_-1.0)));
299 pvalp2 = ((order_==1.0) ? 0.0
300 : ((order_==2.0) ? 1.0
301 : ((order_==3.0) ? bp
302 : std::pow(bp,order_-2.0))));
304 myval[0] += weight*pvalp0;
306 myval[2] += weight*pvalp2*(pval-
threshold_)*(pval-threshold_);
309 gv = pointGrad_->dot(vvec->dual());
311 myval[3] += weight*pvalp1*gv;
312 myval[4] += weight*pvalp2*(pval-
threshold_)*gv;
313 sumGrad0_->axpy(weight*pvalp1,*pointGrad_);
314 sumGrad1_->axpy(weight*pvalp2*(pval-threshold_),*pointGrad_);
315 sumGrad2_->axpy(weight*pvalp2*gv,*pointGrad_);
317 getHessVec(*pointHess_,*vvec,*xvec,point,tol);
319 sumHess_->axpy(weight*pvalp1,*pointHess_);
323 HessianSampler_->sumAll(&myval[0],&val[0],5);
324 Real hvar = 0.0; hessvec_->zero();
325 if ( std::abs(val[0]) >= ROL_EPSILON<Real>() ) {
326 HessianSampler_->sumAll(*sumGrad0_,*gradient0_);
327 HessianSampler_->sumAll(*sumGrad1_,*gradient1_);
328 HessianSampler_->sumAll(*sumGrad2_,*gradient2_);
329 HessianSampler_->sumAll(*sumHess_,*hessvec_);
331 Real norm0 = ((order_==1.0) ? 1.0
332 : ((order_==2.0) ? std::sqrt(val[0])
333 : std::pow(val[0],(order_-1.0)/order_)));
334 Real norm1 = ((order_==1.0) ? val[0]
335 : std::pow(val[0],(2.0*order_-1.0)/order_));
336 hvar = (order_-1.0)*((val[2]/norm0 - val[1]*val[1]/norm1)*vvar
337 +xvar*(val[4]/norm0 - val[3]*val[1]/norm1))
339 hessvec_->scale(xvar/norm0);
340 Real coeff = -(order_-1.0)*xvar*(xvar*val[3]+vvar*val[1])/norm1+vvar/norm0;
341 hessvec_->axpy(coeff,*gradient0_);
342 hessvec_->axpy((order_-1.0)*vvar*xvar/norm0,*gradient1_);
343 hessvec_->axpy((order_-1.0)*xvar*xvar/norm0,*gradient2_);
Provides the interface to evaluate objective functions.
Teuchos::RCP< Vector< Real > > gradient1_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void unwrap_const_CVaR_vector(Teuchos::RCP< Vector< Real > > &xvec, Real &xvar, const Vector< Real > &x)
Teuchos::RCP< SampleGenerator< Real > > HessianSampler_
Teuchos::RCP< Vector< Real > > pointGrad_
Teuchos::RCP< Vector< Real > > sumGrad1_
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
void initialize(const Vector< Real > &x)
void getGradient(Vector< Real > &g, const Vector< Real > &x, const std::vector< Real > ¶m, Real &tol)
BPOEObjective(const Teuchos::RCP< Objective< Real > > &pObj, const Real order, const Real threshold, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< SampleGenerator< Real > > &hsampler, const bool storage=true)
Teuchos::RCP< Vector< Real > > sumGrad0_
virtual void precond(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply preconditioner to vector.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void getValue(Real &val, const Vector< Real > &x, const std::vector< Real > ¶m, Real &tol)
Teuchos::RCP< Vector< Real > > pointHess_
std::map< std::vector< Real >, Real > value_storage_
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
std::map< std::vector< Real >, Teuchos::RCP< Vector< Real > > > gradient_storage_
void setVector(const Vector< Real > &vec)
Teuchos::RCP< SampleGenerator< Real > > ValueSampler_
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
BPOEObjective(const Teuchos::RCP< Objective< Real > > &pObj, const Real order, const Real threshold, const Teuchos::RCP< SampleGenerator< Real > > &sampler, const bool storage=true)
void setStatistic(const Real stat)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Teuchos::RCP< Vector< Real > > gradient2_
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Teuchos::RCP< Vector< Real > > sumHess_
Teuchos::RCP< Vector< Real > > sumGrad2_
Teuchos::RCP< Objective< Real > > ParametrizedObjective_
Teuchos::RCP< Vector< Real > > gradient0_
BPOEObjective(const Teuchos::RCP< Objective< Real > > &pObj, const Real order, const Real threshold, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const bool storage=true)
virtual void set(const Vector &x)
Set where .
void getHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, const std::vector< Real > ¶m, Real &tol)
Teuchos::RCP< SampleGenerator< Real > > GradientSampler_
Teuchos::RCP< Vector< Real > > hessvec_