10 #ifndef ROL_STOCHASTICOBJECTIVE_HPP
11 #define ROL_STOCHASTICOBJECTIVE_HPP
26 Ptr<RandVarFunctional<Real>>
rvf_;
49 if (xstat == nullPtr) {
50 xstat = makePtr<const std::vector<Real>>(0);
58 if (xstat == nullPtr) {
59 xstat = makePtr<std::vector<Real>>(0);
72 const bool storage =
true,
73 const int comp = 0,
const int index = 0 )
77 rvf->useStorage(storage);
84 const bool storage =
true,
85 const int comp = 0,
const int index = 0 )
91 const bool storage =
true,
92 const int comp = 0,
const int index = 0 )
96 ParameterList &parlist,
100 const int comp = 0,
const int index = 0 )
104 std::string name, type = parlist.sublist(
"SOL").get(
"Type",
"Risk Averse");
105 if (type ==
"Risk Averse")
106 name = parlist.sublist(
"SOL").sublist(
"Risk Measure").get(
"Name",
"CVaR");
108 if (type ==
"Risk Averse" && name ==
"Convex Combination Risk Measure")
109 rvf_ = makePtr<ConvexCombinationRiskMeasure<Real>>(parlist);
111 rvf_ = RandVarFunctionalFactory<Real>(parlist);
113 bool storage = parlist.sublist(
"SOL").get(
"Store Sampled Value and Gradient",
true);
114 rvf_->useStorage(storage);
118 ROL::ParameterList &parlist,
121 const int comp = 0,
const int index = 0 )
125 ROL::ParameterList &parlist,
127 const int comp = 0,
const int index = 0 )
132 return rvf_->computeStatistic(xstat);
142 rvf_->resetStorage(type);
144 obj_->update(*x0,type,iter);
156 rvf_->resetStorage(flag);
158 obj_->update(*x0,flag,iter);
170 rvf_->initialize(*x0);
172 for (
int i = 0; i <
vsampler_->numMySamples(); i++ ) {
174 rvf_->updateValue(*
obj_,*x0,*xstat,tol);
185 Ptr<std::vector<Real>> gstat =
getStat(g);
186 rvf_->initialize(*x0);
187 for (
int i = 0; i <
gsampler_->numMySamples(); i++ ) {
189 rvf_->updateGradient(*
obj_,*x0,*xstat,tol);
202 Ptr<std::vector<Real>> hvstat =
getStat(hv);
203 rvf_->initialize(*x0);
204 for (
int i = 0; i <
hsampler_->numMySamples(); i++ ) {
206 rvf_->updateHessVec(*
obj_,*v0,*vstat,*x0,*xstat,tol);
208 rvf_->getHessVec(*hv0,*hvstat,*v0,*vstat,*x0,*xstat,*
hsampler_);
Provides the interface to evaluate objective functions.
Real computeStatistic(const Vector< Real > &x) const
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
StochasticObjective(const Ptr< Objective< Real >> &obj, const Ptr< RandVarFunctional< Real >> &rvf, const Ptr< SampleGenerator< Real >> &vsampler, const Ptr< SampleGenerator< Real >> &gsampler, const bool storage=true, const int comp=0, const int index=0)
Ptr< Objective< Real > > obj_
virtual void zero()
Set to zero vector.
virtual ~StochasticObjective()
Defines the linear algebra or vector space interface.
virtual void precond(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply preconditioner to vector.
Ptr< std::vector< Real > > getStat(Vector< Real > &x) const
Ptr< const Vector< Real > > getConstVector(const Vector< Real > &x) const
StochasticObjective(const Ptr< Objective< Real >> &obj, ROL::ParameterList &parlist, const Ptr< SampleGenerator< Real >> &sampler, const int comp=0, const int index=0)
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
StochasticObjective(const Ptr< Objective< Real >> &obj, const Ptr< RandVarFunctional< Real >> &rvf, const Ptr< SampleGenerator< Real >> &sampler, const bool storage=true, const int comp=0, const int index=0)
Ptr< std::vector< Real > > getStatistic(const int comp=0, const int index=0)
Ptr< SampleGenerator< Real > > hsampler_
Ptr< SampleGenerator< Real > > vsampler_
Ptr< RandVarFunctional< Real > > rvf_
StochasticObjective(const Ptr< Objective< Real >> &obj, const Ptr< RandVarFunctional< Real >> &rvf, const Ptr< SampleGenerator< Real >> &vsampler, const Ptr< SampleGenerator< Real >> &gsampler, const Ptr< SampleGenerator< Real >> &hsampler, const bool storage=true, const int comp=0, const int index=0)
Ptr< const std::vector< Real > > getConstStat(const Vector< Real > &x) const
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Ptr< const Vector< Real > > getVector(void) const
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
Ptr< Vector< Real > > getVector(Vector< Real > &x) const
virtual void set(const Vector &x)
Set where .
StochasticObjective(const Ptr< Objective< Real >> &obj, ROL::ParameterList &parlist, const Ptr< SampleGenerator< Real >> &vsampler, const Ptr< SampleGenerator< Real >> &gsampler, const int comp=0, const int index=0)
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
StochasticObjective(const Ptr< Objective< Real >> &obj, ParameterList &parlist, const Ptr< SampleGenerator< Real >> &vsampler, const Ptr< SampleGenerator< Real >> &gsampler, const Ptr< SampleGenerator< Real >> &hsampler, const int comp=0, const int index=0)
Ptr< SampleGenerator< Real > > gsampler_
Real value(const Vector< Real > &x, Real &tol)
Compute value.