10 #ifndef ROL_CONVEXCOMBINATIONRISKMEASURE_HPP
11 #define ROL_CONVEXCOMBINATIONRISKMEASURE_HPP
39 std::vector<ROL::Ptr<RandVarFunctional<Real> > >
risk_;
52 values_ = makePtr<ScalarController<Real>>();
53 gradvecs_ = makePtr<ScalarController<Real>>();
54 gradients_ = makePtr<VectorController<Real>>();
55 hessvecs_ = makePtr<VectorController<Real>>();
61 risk_[i]->setHessVecStorage(gradvecs_,hessvecs_);
67 ROL_TEST_FOR_EXCEPTION((lSize!=rSize),std::invalid_argument,
68 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Convex combination parameter and risk measure arrays have different sizes!");
69 Real sum(0),
zero(0), one(1);
70 for (
uint i = 0; i < lSize; ++i) {
72 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Element of convex combination parameter array out of range!");
73 ROL_TEST_FOR_EXCEPTION(
risk_[i] == ROL::nullPtr, std::invalid_argument,
74 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Risk measure pointer is null!");
77 ROL_TEST_FOR_EXCEPTION((std::abs(sum-one) > std::sqrt(ROL_EPSILON<Real>())),std::invalid_argument,
78 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Coefficients do not sum to one!");
94 ROL::ParameterList &list
95 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Convex Combination Risk Measure");
97 lambda_ = ROL::getArrayFromStringParameter<Real>(list,
"Convex Combination Parameters");
102 risk_.clear();
risk_.resize(size_,ROL::nullPtr);
104 std::ostringstream convert;
106 std::string si = convert.str();
107 ROL::ParameterList &ilist = list.sublist(si);
108 std::string name = ilist.get<std::string>(
"Name");
109 ROL::ParameterList riskList;
110 riskList.sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",name);
111 riskList.sublist(
"SOL").sublist(
"Risk Measure").sublist(name) = ilist;
112 risk_[i] = RiskMeasureFactory<Real>(riskList);
115 std::vector<Real> lower, upper;
124 void setSample(
const std::vector<Real> &point,
const Real weight) {
127 risk_[i]->setSample(point,weight);
134 risk_[i]->resetStorage(flag);
140 risk_[i]->resetStorage(type);
148 risk_[i]->initialize(x);
154 const std::vector<Real> &xstat,
156 std::vector<Real> statx;
160 for (
int j = 0; j <
statVec_[i]; ++j) {
161 statx[j] = xstat[offset+j];
163 risk_[i]->updateValue(obj,x,statx,tol);
164 offset += statVec_[i];
169 const std::vector<Real> &xstat,
172 std::vector<Real> statx;
176 for (
int j = 0; j <
statVec_[i]; ++j) {
177 statx[j] = xstat[offset+j];
180 offset += statVec_[i];
187 const std::vector<Real> &xstat,
189 std::vector<Real> statx;
193 for (
int j = 0; j <
statVec_[i]; ++j) {
194 statx[j] = xstat[offset+j];
196 risk_[i]->updateGradient(obj,x,statx,tol);
197 offset += statVec_[i];
202 std::vector<Real> &gstat,
204 const std::vector<Real> &xstat,
206 std::vector<Real> statg, statx;
211 for (
int j = 0; j <
statVec_[i]; ++j) {
212 statg[j] =
static_cast<Real
>(0);
213 statx[j] = xstat[offset+j];
216 risk_[i]->getGradient(*
g_,statg,x,statx,sampler);
218 for (
int j = 0; j < statVec_[i]; ++j) {
219 gstat[offset+j] =
lambda_[i]*statg[j];
221 offset += statVec_[i];
227 const std::vector<Real> &vstat,
229 const std::vector<Real> &xstat,
231 std::vector<Real> statx, statv;
236 for (
int j = 0; j <
statVec_[i]; ++j) {
237 statx[j] = xstat[offset+j];
238 statv[j] = vstat[offset+j];
240 risk_[i]->updateHessVec(obj,v,statv,x,statx,tol);
241 offset += statVec_[i];
246 std::vector<Real> &hvstat,
248 const std::vector<Real> &vstat,
250 const std::vector<Real> &xstat,
252 std::vector<Real> stath, statx, statv;
258 for (
int j = 0; j <
statVec_[i]; ++j) {
259 stath[j] =
static_cast<Real
>(0);
260 statx[j] = xstat[offset+j];
261 statv[j] = vstat[offset+j];
264 risk_[i]->getHessVec(*
hv_,stath,v,statv,x,statx,sampler);
266 for (
int j = 0; j < statVec_[i]; ++j) {
267 hvstat[offset+j] =
lambda_[i]*stath[j];
269 offset += statVec_[i];
ConvexCombinationRiskMeasure(ROL::ParameterList &parlist)
Constructor.
Provides the interface to evaluate objective functions.
typename PV< Real >::size_type size_type
std::vector< ROL::Ptr< RandVarFunctional< Real > > > risk_
void RiskMeasureInfo(ROL::ParameterList &parlist, std::string &name, int &nStatistic, std::vector< Real > &lower, std::vector< Real > &upper, bool &isBoundActivated, const bool printToStream=false, std::ostream &outStream=std::cout)
virtual void setSample(const std::vector< Real > &point, const Real weight)
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Ptr< Vector< Real > > hv_
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
void initialize(const Vector< Real > &x)
Initialize temporary variables.
std::vector< Real > lambda_
virtual void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
Defines the linear algebra or vector space interface.
Ptr< ScalarController< Real > > gradvecs_
Ptr< VectorController< Real > > hessvecs_
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
virtual void resetStorage(bool flag=true)
Reset internal storage.
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
Ptr< ScalarController< Real > > values_
Ptr< VectorController< Real > > gradients_
std::vector< int > statVec_
void initializeCCRM(void)
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 resetStorage(bool flag=true)
Reset internal storage.
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
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.
void setSample(const std::vector< Real > &point, const Real weight)
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 setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
void resetStorage(UpdateType type)
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Provides an interface for a convex combination of risk measures.
std::vector< Real >::size_type uint