108 const Real zero(0), one(1);
109 TEUCHOS_TEST_FOR_EXCEPTION((prob_ <= zero) || (prob_ >= one), std::invalid_argument,
110 ">>> ERROR (ROL::HMCR): Confidence level must be between 0 and 1!");
111 TEUCHOS_TEST_FOR_EXCEPTION((lambda_ < zero) || (lambda_ > one), std::invalid_argument,
112 ">>> ERROR (ROL::HMCR): Convex combination parameter must be positive!");
113 TEUCHOS_TEST_FOR_EXCEPTION((order_ < 2), std::invalid_argument,
114 ">>> ERROR (ROL::HMCR): Norm order is less than 2!");
115 TEUCHOS_TEST_FOR_EXCEPTION(plusFunction_ == Teuchos::null, std::invalid_argument,
116 ">>> ERROR (ROL::HMCR): PlusFunction pointer is null!");
129 HMCR(
const Real prob,
const Real lambda,
const unsigned order,
132 plusFunction_(pf), prob_(prob), lambda_(lambda), order_(order),
133 xvar_(0), vvar_(0), pnorm_(0), coeff0_(0), coeff1_(0), coeff2_(0),
134 HMCR_firstReset_(true) {
137 coeff_ = one/(one-
prob_);
151 HMCR( Teuchos::ParameterList &parlist )
153 xvar_(0), vvar_(0), pnorm_(0), coeff0_(0), coeff1_(0), coeff2_(0),
154 HMCR_firstReset_(true) {
155 Teuchos::ParameterList &list
156 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"HMCR");
158 prob_ = list.get<Real>(
"Confidence Level");
159 lambda_ = list.get<Real>(
"Convex Combination Parameter");
160 order_ = (unsigned)list.get<
int>(
"Order",2);
166 coeff_ = one/(one-
prob_);
173 if ( HMCR_firstReset_ ) {
174 mDualVector0_ = (x0->dual()).clone();
175 gDualVector0_ = (x0->dual()).clone();
176 mDualVector1_ = (x0->dual()).clone();
177 gDualVector1_ = (x0->dual()).clone();
178 HMCR_firstReset_ =
false;
182 mDualVector0_->zero(); gDualVector0_->zero();
183 pnorm_ = zero; coeff0_ = zero;
194 mDualVector1_->zero(); gDualVector1_->zero();
195 coeff1_ = zero; coeff2_ = zero;
198 void update(
const Real val,
const Real weight) {
199 const Real rorder =
static_cast<Real
>(
order_);
203 Real pf = plusFunction_->evaluate(val-xvar_,0);
204 pnorm_ += weight*std::pow(pf,rorder);
209 const Real power = one/
static_cast<Real
>(
order_);
210 std::vector<Real> val_in(2), val_out(2);
213 sampler.
sumAll(&val_in[0],&val_out[0],2);
214 return (one-lambda_)*val_out[0]
215 + lambda_*(xvar_ + coeff_*std::pow(val_out[1],power));
220 const Real rorder0 =
static_cast<Real
>(
order_);
221 const Real rorder1 = rorder0 - one;
225 Real pf0 = plusFunction_->evaluate(val-xvar_,0);
226 Real pf1 = plusFunction_->evaluate(val-xvar_,1);
228 Real pf0p0 = std::pow(pf0,rorder0);
229 Real pf0p1 = std::pow(pf0,rorder1);
231 pnorm_ += weight*pf0p0;
232 coeff0_ += weight*pf0p1*pf1;
234 mDualVector0_->axpy(weight*pf0p1*pf1,g);
238 const Real zero(0), one(1);
239 std::vector<Real> val_in(2), val_out(2);
242 sampler.
sumAll(&val_in[0],&val_out[0],2);
247 if ( val_in[0] > zero ) {
248 const Real rorder0 =
static_cast<Real
>(
order_);
249 const Real rorder1 = rorder0 - one;
250 Real denom = std::pow(val_out[0],rorder1/rorder0);
252 sampler.
sumAll(*mDualVector0_,*gDualVector0_);
255 var -= lambda_*coeff_*((denom > zero) ? val_out[1]/denom : zero);
265 const Real rorder0 =
static_cast<Real
>(
order_);
266 const Real rorder1 = rorder0-one;
267 const Real rorder2 = rorder1-one;
271 Real pf0 = plusFunction_->evaluate(val-xvar_,0);
272 Real pf1 = plusFunction_->evaluate(val-xvar_,1);
273 Real pf2 = plusFunction_->evaluate(val-xvar_,2);
275 Real pf0p0 = std::pow(pf0,rorder0);
276 Real pf0p1 = std::pow(pf0,rorder1);
277 Real pf0p2 = std::pow(pf0,rorder2);
279 Real scale0 = (rorder1*pf0p2*pf1*pf1 + pf0p1*pf2)*(gv-vvar_);
280 Real scale1 = pf0p1*pf1;
282 pnorm_ += weight*pf0p0;
283 coeff0_ += weight*scale0;
284 coeff1_ += weight*scale1;
285 coeff2_ += weight*rorder1*scale1*(vvar_-gv);
287 mDualVector0_->axpy(weight*scale0,g);
288 mDualVector0_->axpy(weight*scale1,hv);
289 mDualVector1_->axpy(weight*scale1,g);
293 const Real zero(0), one(1);
294 std::vector<Real> val_in(4), val_out(4);
298 sampler.
sumAll(&val_in[0],&val_out[0],4);
304 if ( val_out[0] > zero ) {
305 const Real rorder0 =
static_cast<Real
>(
order_);
306 const Real rorder1 = rorder0-one;
307 const Real rorder2 = rorder0 + rorder1;
308 const Real coeff = lambda_*
coeff_;
310 sampler.
sumAll(*mDualVector0_,*gDualVector0_);
311 sampler.
sumAll(*mDualVector1_,*gDualVector1_);
313 Real denom1 = std::pow(val_out[0],rorder1/rorder0);
314 Real denom2 = std::pow(val_out[0],rorder2/rorder0);
316 var = -coeff*(val_out[1]/denom1 + val_out[3]*val_out[2]/denom2);
Teuchos::RCP< PlusFunction< Real > > plusFunction_
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
Teuchos::RCP< Vector< Real > > gDualVector1_
void sumAll(Real *input, Real *output, int dim) const
HMCR(Teuchos::ParameterList &parlist)
Constructor.
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
Defines the linear algebra or vector space interface.
Teuchos::RCP< Vector< Real > > mDualVector1_
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x, Teuchos::RCP< Vector< Real > > &v0, const Vector< Real > &v)
Reset internal risk measure storage. Called for Hessian-times-a-vector computation.
void update(const Real val, const Real weight)
Update internal risk measure storage for value computation.
void update(const Real val, const Vector< Real > &g, const Real weight)
Update internal risk measure storage for gradient computation.
void update(const Real val, const Vector< Real > &g, const Real gv, const Vector< Real > &hv, const Real weight)
Update internal risk measure storage for Hessian-time-a-vector computation.
Real getValue(SampleGenerator< Real > &sampler)
Return risk measure value.
virtual void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
Provides an interface for a convex combination of the expected value and the higher moment coherent r...
HMCR(const Real prob, const Real lambda, const unsigned order, const Teuchos::RCP< PlusFunction< Real > > &pf)
Constructor.
Teuchos::RCP< Vector< Real > > mDualVector0_
void checkInputs(void) const
Provides the interface to implement risk measures.
Teuchos::RCP< Vector< Real > > gDualVector0_