44 #ifndef ROL_CONVEXCOMBINATIONRISKMEASURE_HPP
45 #define ROL_CONVEXCOMBINATIONRISKMEASURE_HPP
73 std::vector<ROL::Ptr<RandVarFunctional<Real> > >
risk_;
86 values_ = makePtr<SampledScalar<Real>>();
87 gradvecs_ = makePtr<SampledScalar<Real>>();
89 hessvecs_ = makePtr<SampledVector<Real>>();
95 risk_[i]->setHessVecStorage(gradvecs_,hessvecs_);
101 ROL_TEST_FOR_EXCEPTION((lSize!=rSize),std::invalid_argument,
102 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Convex combination parameter and risk measure arrays have different sizes!");
103 Real sum(0),
zero(0), one(1);
104 for (
uint i = 0; i < lSize; ++i) {
106 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Element of convex combination parameter array out of range!");
107 ROL_TEST_FOR_EXCEPTION(
risk_[i] == ROL::nullPtr, std::invalid_argument,
108 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Risk measure pointer is null!");
111 ROL_TEST_FOR_EXCEPTION((std::abs(sum-one) > std::sqrt(ROL_EPSILON<Real>())),std::invalid_argument,
112 ">>> ERROR (ROL::ConvexCombinationRiskMeasure): Coefficients do not sum to one!");
128 ROL::ParameterList &list
129 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Convex Combination Risk Measure");
131 lambda_ = ROL::getArrayFromStringParameter<Real>(list,
"Convex Combination Parameters");
136 risk_.clear();
risk_.resize(size_,ROL::nullPtr);
138 std::ostringstream convert;
140 std::string si = convert.str();
141 ROL::ParameterList &ilist = list.sublist(si);
142 std::string name = ilist.get<std::string>(
"Name");
143 ROL::ParameterList riskList;
144 riskList.sublist(
"SOL").sublist(
"Risk Measure").set(
"Name",name);
145 riskList.sublist(
"SOL").sublist(
"Risk Measure").sublist(name) = ilist;
146 risk_[i] = RiskMeasureFactory<Real>(riskList);
149 std::vector<Real> lower, upper;
158 void setSample(
const std::vector<Real> &point,
const Real weight) {
161 risk_[i]->setSample(point,weight);
168 risk_[i]->resetStorage(flag);
175 risk_[i]->initialize(x);
181 const std::vector<Real> &xstat,
183 std::vector<Real> statx;
187 for (
int j = 0; j <
statVec_[i]; ++j) {
188 statx[j] = xstat[offset+j];
190 risk_[i]->updateValue(obj,x,statx,tol);
191 offset += statVec_[i];
196 const std::vector<Real> &xstat,
199 std::vector<Real> statx;
203 for (
int j = 0; j <
statVec_[i]; ++j) {
204 statx[j] = xstat[offset+j];
207 offset += statVec_[i];
214 const std::vector<Real> &xstat,
216 std::vector<Real> statx;
220 for (
int j = 0; j <
statVec_[i]; ++j) {
221 statx[j] = xstat[offset+j];
223 risk_[i]->updateGradient(obj,x,statx,tol);
224 offset += statVec_[i];
229 std::vector<Real> &gstat,
231 const std::vector<Real> &xstat,
233 std::vector<Real> statg, statx;
238 for (
int j = 0; j <
statVec_[i]; ++j) {
239 statg[j] =
static_cast<Real
>(0);
240 statx[j] = xstat[offset+j];
243 risk_[i]->getGradient(*
g_,statg,x,statx,sampler);
245 for (
int j = 0; j < statVec_[i]; ++j) {
246 gstat[offset+j] =
lambda_[i]*statg[j];
248 offset += statVec_[i];
254 const std::vector<Real> &vstat,
256 const std::vector<Real> &xstat,
258 std::vector<Real> statx, statv;
263 for (
int j = 0; j <
statVec_[i]; ++j) {
264 statx[j] = xstat[offset+j];
265 statv[j] = vstat[offset+j];
267 risk_[i]->updateHessVec(obj,v,statv,x,statx,tol);
268 offset += statVec_[i];
273 std::vector<Real> &hvstat,
275 const std::vector<Real> &vstat,
277 const std::vector<Real> &xstat,
279 std::vector<Real> stath, statx, statv;
285 for (
int j = 0; j <
statVec_[i]; ++j) {
286 stath[j] =
static_cast<Real
>(0);
287 statx[j] = xstat[offset+j];
288 statv[j] = vstat[offset+j];
291 risk_[i]->getHessVec(*
hv_,stath,v,statv,x,statx,sampler);
293 for (
int j = 0; j < statVec_[i]; ++j) {
294 hvstat[offset+j] =
lambda_[i]*stath[j];
296 offset += statVec_[i];
virtual void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
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_
Defines the linear algebra or vector space interface.
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.
virtual void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
std::vector< int > statVec_
void initializeCCRM(void)
Ptr< SampledVector< Real > > hessvecs_
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.
Ptr< SampledScalar< Real > > gradvecs_
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
Ptr< SampledVector< Real > > gradients_
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.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
Ptr< SampledScalar< Real > > values_
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