44 #ifndef ROL_RANDVARFUNCTIONAL_HPP 45 #define ROL_RANDVARFUNCTIONAL_HPP 48 #include "ROL_Ptr.hpp" 91 Ptr<Vector<Real> >
g_;
92 Ptr<Vector<Real> >
hv_;
103 bool isComputed =
false;
105 isComputed = value_storage_->get(val,point_);
107 if (!isComputed || !storage_) {
109 val = obj.
value(x,tol);
111 value_storage_->set(val,point_);
120 bool isComputed =
false;
122 isComputed = gradient_storage_->get(g,point_);
124 if (!isComputed || !storage_) {
128 gradient_storage_->set(g,point_);
139 bool isComputed =
false;
140 if (storage_hessvec_) {
141 isComputed = gradvec_storage_->get(gv,point_);
143 if (!isComputed || !storage_hessvec_) {
145 if (storage_hessvec_) {
146 gradvec_storage_->set(gv,point_);
156 bool isComputed =
false;
157 if (storage_hessvec_) {
158 isComputed = hessvec_storage_->get(hv,point_);
160 if (!isComputed || !storage_hessvec_) {
163 if (storage_hessvec_) {
164 hessvec_storage_->set(hv,point_);
173 value_storage_(nullPtr),
174 gradient_storage_(nullPtr),
175 gradvec_storage_(nullPtr),
176 hessvec_storage_(nullPtr),
177 val_(0), gv_(0), firstReset_(true),
183 if (value_storage_ == nullPtr) {
184 value_storage_ = makePtr<SampledScalar<Real>>();
186 if (gradient_storage_ == nullPtr) {
187 gradient_storage_ = makePtr<SampledVector<Real>>();
193 storage_hessvec_ = storage;
196 if (gradvec_storage_ == nullPtr) {
197 gradvec_storage_ = makePtr<SampledScalar<Real>>();
199 if (hessvec_storage_ == nullPtr) {
200 hessvec_storage_ = makePtr<SampledVector<Real>>();
207 value_storage_ = value_storage;
208 gradient_storage_ = gradient_storage;
214 gradvec_storage_ = gradvec_storage;
215 hessvec_storage_ = hessvec_storage;
225 value_storage_->update();
227 gradient_storage_->update();
228 if (storage_hessvec_) {
229 gradvec_storage_->update();
230 hessvec_storage_->update();
243 g_ = x.
dual().clone();
244 hv_ = x.
dual().clone();
245 dualVector_ = x.
dual().clone();
251 g_->zero(); hv_->zero(); dualVector_->zero();
252 if (storage_hessvec_) {
253 gradvec_storage_->update();
254 hessvec_storage_->update();
258 virtual void setSample(
const std::vector<Real> &point,
const Real weight) {
259 point_.assign(point.begin(),point.end());
270 if (xstat != nullPtr) {
285 const std::vector<Real> &xstat,
288 val_ += weight_ * val;
302 const std::vector<Real> &xstat,
305 g_->axpy(weight_,*dualVector_);
325 const std::vector<Real> &vstat,
327 const std::vector<Real> &xstat,
330 hv_->axpy(weight_,*dualVector_);
342 const std::vector<Real> &xstat,
345 sampler.
sumAll(&val_,&val,1);
361 std::vector<Real> &gstat,
363 const std::vector<Real> &xstat,
380 std::vector<Real> &hvstat,
382 const std::vector<Real> &vstat,
384 const std::vector<Real> &xstat,
virtual void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
Provides the interface to evaluate objective functions.
virtual void updateHessVec(Objective< Real > &obj, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for Hessian-time-a-vector computation.
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
virtual void setSample(const std::vector< Real > &point, const Real weight)
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void getHessVec(Vector< Real > &hv, std::vector< Real > &hvstat, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void sumAll(Real *input, Real *output, int dim) const
std::vector< Real > point_
Ptr< Vector< Real > > dualVector_
Defines the linear algebra or vector space interface.
virtual Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
virtual Real dot(const Vector &x) const =0
Compute where .
virtual void getGradient(Vector< Real > &g, std::vector< Real > &gstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
virtual void resetStorage(bool flag=true)
Reset internal storage.
Ptr< SampledVector< Real > > hessvec_storage_
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
virtual void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
virtual ~RandVarFunctional()
Ptr< SampledScalar< Real > > value_storage_
virtual void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
virtual Real computeStatistic(const Ptr< const std::vector< Real >> &xstat) const
Compute statistic.
void useStorage(bool storage)
Ptr< SampledVector< Real > > gradient_storage_
virtual void setParameter(const std::vector< Real > ¶m)
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< SampledScalar< Real > > gradvec_storage_
Real computeGradVec(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
void useHessVecStorage(bool storage)