10 #ifndef ROL_RISKVECTOR_HPP
11 #define ROL_RISKVECTOR_HPP
15 #include "ROL_ParameterList.hpp"
27 std::vector<Ptr<std::vector<Real> > >
statCon_;
36 mutable std::vector<Ptr<std::vector<Real> > >
dualCon_;
41 const Real stat = 1) {
43 if (parlist != nullPtr) {
45 std::vector<Real> lower, upper;
46 bool activated(
false);
47 RandVarFunctionalInfo<Real>(*parlist,name,
nStatObj_,lower,upper,activated);
62 const Real stat = 1) {
63 int size = parlist.size();
65 for (
int i = 0; i < size; ++i) {
66 if (parlist[i] != nullPtr) {
69 std::vector<Real> lower, upper;
70 bool activated(
false);
71 RandVarFunctionalInfo<Real>(*parlist[i],name,
nStatCon_[i],lower,upper,activated);
74 if (nStatCon_[i] > 0) {
75 statCon_[i] = makePtr<std::vector<Real>>(nStatCon_[i],stat);
106 const Real stat = 0 )
116 std::vector<Ptr<ParameterList> > &parlistCon,
118 const Real stat = 0 )
129 const Ptr<std::vector<Real> > &statObj,
130 const std::vector<Ptr<std::vector<Real> > > &statCon )
134 if (statObj != nullPtr) {
140 int size = statCon.size();
145 for (
int i = 0; i < size; ++i) {
146 if (statCon[i] != nullPtr) {
169 for (
int i = 0; i < size; ++i) {
185 for (
int i = 0; i < size; ++i) {
200 for (
int i = 0; i < size; ++i) {
216 for (
int i = 0; i < size; ++i) {
232 for (
int i = 0; i < size; ++i) {
242 return sqrt(
dot(*
this) );
245 Ptr<Vector<Real> >
clone(
void)
const {
246 Ptr<std::vector<Real> > e2 = nullPtr;
248 e2 = makePtr<std::vector<Real>>(
nStatObj_,
static_cast<Real
>(0));
251 std::vector<Ptr<std::vector<Real> > > e3(size, nullPtr);
252 for (
int j = 0; j < size; ++j) {
254 e3[j] = makePtr<std::vector<Real>>(
nStatCon_[j],
static_cast<Real
>(0));
257 return makePtr<RiskVector>(
vec_->clone(),e2,e3);
270 for (
int i = 0; i < size; ++i) {
286 for (
int i = 0; i < size; ++i) {
296 Ptr<Vector<Real> >
basis(
const int i )
const {
297 Ptr<Vector<Real> > e1;
298 Ptr<std::vector<Real> > e2 = nullPtr;
300 e2 = makePtr<std::vector<Real>>(
nStatObj_,
static_cast<Real
>(0));
303 std::vector<Ptr<std::vector<Real> > > e3(size);
304 for (
int j = 0; j < size; ++j) {
306 e3[j] = makePtr<std::vector<Real>>(
nStatCon_[j],
static_cast<Real
>(0));
309 int n1 =
vec_->dimension(), n2 = 0;
316 else if (i >= n1 && i < n1+n2) {
317 e1 =
vec_->clone(); e1->zero();
318 (*e2)[i-n1] =
static_cast<Real
>(1);
320 else if (i >= n1+n2) {
321 e1 =
vec_->clone(); e1->zero();
322 int sum = n1+n2, sum0 = sum;
323 for (
int j = 0; j < size; ++j) {
327 (*e3[j])[i-sum0] = static_cast<Real>(1);
337 return makePtr<RiskVector<Real>>(e1,e2,e3);
340 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
347 for (
int i = 0; i < size; ++i) {
363 for (
int i = 0; i < size; ++i) {
371 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
372 Real result = r.initialValue();
373 r.reduce(
vec_->reduce(r),result);
379 for (
int i = 0; i < size; ++i) {
395 for (
int i = 0; i < size; ++i) {
404 vec_->randomize(l,u);
410 for (
int i = 0; i < size; ++i) {
425 for (
int i = 0; i < size; ++i) {
437 Ptr<const StdVector<Real>>
442 else if (comp == 1) {
455 else if (comp == 1) {
474 Ptr<std::vector<Real>>
481 else if (comp == 1) {
492 Ptr<const std::vector<Real>>
499 else if (comp == 1) {
510 void setStatistic(
const Real stat,
const int comp = 0,
const int index = 0) {
516 else if ( comp == 1 ) {
526 void setStatistic(
const std::vector<Real> &stat,
const int comp = 0,
const int index = 0) {
529 if (
nStatObj_ != static_cast<int>(stat.size()) ) {
532 statObj_->assign(stat.begin(),stat.end());
535 else if ( comp == 1) {
537 if (
nStatCon_[index] != static_cast<int>(stat.size()) ) {
540 statCon_[index]->assign(stat.begin(),stat.end());
void set(const Vector< Real > &x)
Set where .
std::vector< int > nStatCon_
void scale(const Real alpha)
Compute where .
Ptr< Vector< Real > > vec_
void setStatistic(const std::vector< Real > &stat, const int comp=0, const int index=0)
void setScalar(const Real C)
Set where .
Ptr< Vector< Real > > getVector(void)
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
void setStatistic(const Real stat, const int comp=0, const int index=0)
Defines the linear algebra or vector space interface.
Ptr< Vector< Real > > dual_vec1_
void setVector(const Vector< Real > &vec)
void plus(const Vector< Real > &x)
Compute , where .
std::vector< Ptr< std::vector< Real > > > dualCon_
Ptr< const StdVector< Real > > getStatisticVector(const int comp, const int index=0) const
int dimension(void) const
Return dimension of the vector space.
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
Ptr< std::vector< Real > > getStatistic(const int comp=0, const int index=0)
RiskVector(const Ptr< Vector< Real > > &vec, const Ptr< std::vector< Real > > &statObj, const std::vector< Ptr< std::vector< Real > > > &statCon)
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
RiskVector(Ptr< ParameterList > &parlist, const Ptr< Vector< Real > > &vec, const Real stat=0)
Ptr< StdVector< Real > > getStatisticVector(const int comp, const int index=0)
RiskVector(const Ptr< Vector< Real > > &vec)
RiskVector(Ptr< ParameterList > &parlistObj, std::vector< Ptr< ParameterList > > &parlistCon, const Ptr< Vector< Real > > &vec, const Real stat=0)
Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
void initializeCon(std::vector< Ptr< ParameterList > > &parlist, const Real stat=1)
Ptr< StdVector< Real > > statObj_vec_
Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
std::vector< Ptr< StdVector< Real > > > statCon_vec_
Real norm(void) const
Returns where .
RiskVector(std::vector< Ptr< ParameterList > > &parlist, const Ptr< Vector< Real > > &vec, const Real stat=0)
Ptr< RiskVector< Real > > dual_vec_
Ptr< const Vector< Real > > getVector(void) const
Real reduce(const Elementwise::ReductionOp< Real > &r) const
Real dot(const Vector< Real > &x) const
Compute where .
Ptr< std::vector< Real > > statObj_
std::vector< Ptr< std::vector< Real > > > statCon_
void initializeObj(Ptr< ParameterList > &parlist, const Real stat=1)
Ptr< std::vector< Real > > dualObj_
Ptr< const std::vector< Real > > getStatistic(const int comp=0, const int index=0) const