/usr/include/trilinos/ROL_RiskMeasure.hpp is in libtrilinos-rol-dev 12.12.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | // @HEADER
// ************************************************************************
//
// Rapid Optimization Library (ROL) Package
// Copyright (2014) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact lead developers:
// Drew Kouri (dpkouri@sandia.gov) and
// Denis Ridzal (dridzal@sandia.gov)
//
// ************************************************************************
// @HEADER
#ifndef ROL_RISKMEASURE_HPP
#define ROL_RISKMEASURE_HPP
#include "ROL_RiskVector.hpp"
/** @ingroup stochastic_group
\class ROL::RiskMeasure
\brief Provides the interface to implement risk measures.
Let \f$(\Omega,\mathcal{F},\mathbb{P})\f$ be a complete space.
Here, \f$\Omega\f$ is the set of outcomes,
\f$\mathcal{F}\subseteq 2^\Omega\f$ is a \f$\sigma\f$-algebra of events and
\f$\mathbb{P}:\mathcal{F}\to[0,1]\f$ is a probability measure. Moreover,
let \f$\mathcal{X}\f$ be a class of random variables.
A risk measure is an extended real-valued functional that associates
numerical values to random variables, i.e.,
\f$\mathcal{R}:\mathcal{X}\to\mathbb{R}\cup\{+\infty\}\f$. In most cases,
\f$\mathcal{X} = L^p(\Omega,\mathcal{F},\mathbb{P})\f$ for some
\f$1\le p\le \infty\f$.
There are a number of classifications for risk measures. One important
class are the coherent risk measures. \f$\mathcal{R}\f$ is coherent
if it satisfies the following four axioms:
\li Convexity: \f$\mathcal{R}(\lambda X + (1-\lambda)X')
\le \lambda \mathcal{R}(X)
+ (1-\lambda)\mathcal{R}(X')\f$
for all \f$0 \le \lambda \le 1\f$;
\li Translation Equivariance: \f$\mathcal{R}(X+C)
= \mathcal{R}(X) + C\f$
for all constants \f$C\f$;
\li Monotonicity: If \f$X \le X'\f$ \f$\mathbb{P}\f$ almost everywhere
then \f$\mathcal{R}(X) \le \mathcal{R}(X')\f$;
\li Positive Homogeneity: \f$\mathcal{R}(tX) = t \mathcal{R}(X)\f$
for all \f$t \ge 0\f$.
Another useful characterization is law invariance. \f$\mathcal{R}\f$ is
law invariant if \f$\mathcal{R}(X) = \mathcal{R}(X')\f$ whenever
\f$\mathbb{P}(X\le t) = \mathbb{P}(X'\le t)\f$ for all \f$t\in\mathbb{R}\f$.
Law invariant risk measures are only functions of the distribution of the
input random variable.
ROL's risk measure base class is written in a way to exploit parallel
sampling. General risk measures may depend on global information such as
the expected value of a random variable, \f$\mathbb{E}[X]\f$. Thus,
ROL::RiskMeasure contains functions to update intermediate information
and to compute desired quantities such as risk values, gradients and
Hessians applied to vectors.
*/
namespace ROL {
template<class Real>
class RiskMeasure {
protected:
Real val_;
Real gv_;
Teuchos::RCP<Vector<Real> > g_;
Teuchos::RCP<Vector<Real> > hv_;
Teuchos::RCP<Vector<Real> > dualVector_;
bool firstReset_;
public:
virtual ~RiskMeasure() {}
RiskMeasure(void) : val_(0), gv_(0), firstReset_(true) {}
/** \brief Reset internal risk measure storage.
Called for value and gradient computation.
@param[out] x0 is a user-provided optimization vector
@param[in] x is a (potentially) augmented risk vector
On input, \f$x\f$ carries \f$x_0\f$ and any statistics (scalars)
associated with the risk measure.
*/
virtual void reset(Teuchos::RCP<Vector<Real> > &x0, const Vector<Real> &x) {
x0 = Teuchos::rcp_const_cast<Vector<Real> >(
Teuchos::dyn_cast<const RiskVector<Real> >(x).getVector());
// Create memory for class members
if ( firstReset_ ) {
g_ = (x0->dual()).clone();
hv_ = (x0->dual()).clone();
dualVector_ = (x0->dual()).clone();
firstReset_ = false;
}
// Zero member variables
const Real zero(0);
val_ = zero; gv_ = zero;
g_->zero(); hv_->zero(); dualVector_->zero();
}
/** \brief Reset internal risk measure storage.
Called for Hessian-times-a-vector computation.
@param[out] x0 is a user-provided optimization vector
@param[in] x is a (potentially) augmented risk vector
@param[out] v0 is a user-provided direction vector
@param[in] v is a (potentially) augmented risk vector
On input, \f$x\f$ carries \f$x_0\f$ and any statistics (scalars)
associated with the risk measure. Similarly, \f$v\f$ carries
\f$v_0\f$ and any statistics (scalars) associated with the risk
measure.
*/
virtual void reset(Teuchos::RCP<Vector<Real> > &x0, const Vector<Real> &x,
Teuchos::RCP<Vector<Real> > &v0, const Vector<Real> &v) {
reset(x0,x);
// Get vector component of v. This is important for CVaR.
v0 = Teuchos::rcp_const_cast<Vector<Real> >(
Teuchos::dyn_cast<const RiskVector<Real> >(v).getVector());
}
/** \brief Update internal risk measure storage for value computation.
@param[in] val is the value of the random variable objective
function at the current sample point
@param[in] weight is the weight associated with the current
sample point
*/
virtual void update(const Real val, const Real weight) {
val_ += weight * val;
}
/** \brief Update internal risk measure storage for gradient computation.
@param[in] val is the value of the random variable objective
function at the current sample point
@param[in] g is the gradient of the random variable objective
function at the current sample point
@param[in] weight is the weight associated with the current
sample point
*/
virtual void update(const Real val, const Vector<Real> &g, const Real weight) {
g_->axpy(weight,g);
}
/** \brief Update internal risk measure storage for Hessian-time-a-vector computation.
@param[in] val is the value of the random variable objective
function at the current sample point
@param[in] g is the gradient of the random variable objective
function at the current sample point
@param[in] gv is the gradient of the random variable objective
function at the current sample point applied to
the vector v0
@param[in] hv is the Hessian of the random variable objective
function at the current sample point applied to
the vector v0
@param[in] weight is the weight associated with the current
sample point
*/
virtual void update(const Real val, const Vector<Real> &g, const Real gv, const Vector<Real> &hv,
const Real weight) {
hv_->axpy(weight,hv);
}
/** \brief Return risk measure value.
@param[in] sampler is the ROL::SampleGenerator used to sample
the objective function
Upon return, getValue returns \f$\mathcal{R}(f(x_0))\f$ where \f$f(x_0)\f$
denotes the random variable objective function evaluated at \f$x_0\f$.
*/
virtual Real getValue(SampleGenerator<Real> &sampler) {
Real val(0);
sampler.sumAll(&val_,&val,1);
return val;
}
/** \brief Return risk measure (sub)gradient.
@param[out] g is the (sub)gradient of the risk measure
@param[in] sampler is the ROL::SampleGenerator used to sample
the objective function
Upon return, getGradient returns \f$\theta\in\partial\mathcal{R}(f(x_0))\f$
where \f$f(x_0)\f$ denotes the random variable objective function evaluated
at \f$x_0\f$ and \f$\partial\mathcal{R}(X)\f$ denotes the subdifferential
of \f$\mathcal{R}\f$ at \f$X\f$.
*/
virtual void getGradient(Vector<Real> &g, SampleGenerator<Real> &sampler) {
sampler.sumAll(*g_,*dualVector_);
(Teuchos::dyn_cast<RiskVector<Real> >(g)).setVector(*dualVector_);
}
/** \brief Return risk measure Hessian-times-a-vector.
@param[out] hv is the Hessian-times-a-vector of the risk measure
@param[in] sampler is the ROL::SampleGenerator used to sample
the objective function
Upon return, getHessVec returns \f$\nabla^2 \mathcal{R}(f(x_0))v_0\f$
(if available)
where \f$f(x_0)\f$ denotes the random variable objective function evaluated
at \f$x_0\f$.
*/
virtual void getHessVec(Vector<Real> &hv, SampleGenerator<Real> &sampler) {
sampler.sumAll(*hv_,*dualVector_);
(Teuchos::dyn_cast<RiskVector<Real> >(hv)).setVector(*dualVector_);
}
};
}
#endif
|