44 #ifndef ROL_RISKVECTOR_HPP
45 #define ROL_RISKVECTOR_HPP
49 #include "ROL_ParameterList.hpp"
61 std::vector<ROL::Ptr<std::vector<Real> > >
statCon_;
66 ROL::Ptr<Vector<Real> >
vec_;
70 mutable std::vector<ROL::Ptr<std::vector<Real> > >
dualCon_;
75 const Real stat = 1) {
77 if (parlist != ROL::nullPtr) {
79 std::vector<Real> lower, upper;
80 bool activated(
false);
81 RandVarFunctionalInfo<Real>(*parlist,name,
nStatObj_,lower,upper,activated);
96 const Real stat = 1) {
97 int size = parlist.size();
99 for (
int i = 0; i < size; ++i) {
100 if (parlist[i] != ROL::nullPtr) {
103 std::vector<Real> lower, upper;
104 bool activated(
false);
105 RandVarFunctionalInfo<Real>(*parlist[i],name,
nStatCon_[i],lower,upper,activated);
108 if (nStatCon_[i] > 0) {
109 statCon_[i] = ROL::makePtr<std::vector<Real>>(nStatCon_[i],stat);
129 const Real stat = 0 )
138 RiskVector( std::vector<ROL::Ptr<ROL::ParameterList> > &parlist,
140 const Real stat = 0 )
150 std::vector<ROL::Ptr<ROL::ParameterList> > &parlistCon,
152 const Real stat = 0 )
163 const ROL::Ptr<std::vector<Real> > &statObj,
164 const std::vector<ROL::Ptr<std::vector<Real> > > &statCon )
168 if (statObj != ROL::nullPtr) {
174 int size = statCon.size();
179 for (
int i = 0; i < size; ++i) {
180 if (statCon[i] != ROL::nullPtr) {
203 for (
int i = 0; i < size; ++i) {
219 for (
int i = 0; i < size; ++i) {
234 for (
int i = 0; i < size; ++i) {
250 for (
int i = 0; i < size; ++i) {
266 for (
int i = 0; i < size; ++i) {
276 return sqrt(
dot(*
this) );
279 ROL::Ptr<Vector<Real> >
clone(
void)
const {
280 ROL::Ptr<std::vector<Real> > e2 = ROL::nullPtr;
282 e2 = ROL::makePtr<std::vector<Real>>(
nStatObj_,
static_cast<Real
>(0));
285 std::vector<ROL::Ptr<std::vector<Real> > > e3(size, ROL::nullPtr);
286 for (
int j = 0; j < size; ++j) {
288 e3[j] = ROL::makePtr<std::vector<Real>>(
nStatCon_[j],
static_cast<Real
>(0));
291 return ROL::makePtr<RiskVector>(
vec_->clone(),e2,e3);
304 for (
int i = 0; i < size; ++i) {
320 for (
int i = 0; i < size; ++i) {
330 ROL::Ptr<Vector<Real> >
basis(
const int i )
const {
331 ROL::Ptr<Vector<Real> > e1;
332 ROL::Ptr<std::vector<Real> > e2 = ROL::nullPtr;
334 e2 = ROL::makePtr<std::vector<Real>>(
nStatObj_,
static_cast<Real
>(0));
337 std::vector<ROL::Ptr<std::vector<Real> > > e3(size);
338 for (
int j = 0; j < size; ++j) {
340 e3[j] = ROL::makePtr<std::vector<Real>>(
nStatCon_[j],
static_cast<Real
>(0));
343 int n1 =
vec_->dimension(), n2 = 0;
350 else if (i >= n1 && i < n1+n2) {
351 e1 =
vec_->clone(); e1->zero();
352 (*e2)[i-n1] =
static_cast<Real
>(1);
354 else if (i >= n1+n2) {
355 e1 =
vec_->clone(); e1->zero();
356 int sum = n1+n2, sum0 = sum;
357 for (
int j = 0; j < size; ++j) {
361 (*e3[j])[i-sum0] = static_cast<Real>(1);
371 return ROL::makePtr<RiskVector<Real>>(e1,e2,e3);
374 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
381 for (
int i = 0; i < size; ++i) {
397 for (
int i = 0; i < size; ++i) {
405 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
406 Real result = r.initialValue();
407 r.reduce(
vec_->reduce(r),result);
413 for (
int i = 0; i < size; ++i) {
429 for (
int i = 0; i < size; ++i) {
438 vec_->randomize(l,u);
444 for (
int i = 0; i < size; ++i) {
453 int dim =
vec_->dimension();
459 for (
int i = 0; i < size; ++i) {
471 ROL::Ptr<const StdVector<Real>>
476 else if (comp == 1) {
485 ROL::Ptr<StdVector<Real>>
490 else if (comp == 1) {
510 ROL::Ptr<std::vector<Real>>
517 else if (comp == 1) {
528 ROL::Ptr<const std::vector<Real>>
535 else if (comp == 1) {
546 void setStatistic(
const Real stat,
const int comp = 0,
const int index = 0) {
552 else if ( comp == 1 ) {
562 void setStatistic(
const std::vector<Real> &stat,
const int comp = 0,
const int index = 0) {
565 if (
nStatObj_ != static_cast<int>(stat.size()) ) {
568 statObj_->assign(stat.begin(),stat.end());
571 else if ( comp == 1) {
573 if (
nStatCon_[index] != static_cast<int>(stat.size()) ) {
576 statCon_[index]->assign(stat.begin(),stat.end());
ROL::Ptr< std::vector< Real > > dualObj_
ROL::Ptr< std::vector< Real > > getStatistic(const int comp=0, const int index=0)
RiskVector(ROL::Ptr< ROL::ParameterList > &parlist, const ROL::Ptr< Vector< Real > > &vec, const Real stat=0)
void set(const Vector< Real > &x)
Set where .
std::vector< int > nStatCon_
std::vector< ROL::Ptr< std::vector< Real > > > dualCon_
void scale(const Real alpha)
Compute where .
ROL::Ptr< const Vector< Real > > getVector(void) const
RiskVector(std::vector< ROL::Ptr< ROL::ParameterList > > &parlist, const ROL::Ptr< Vector< Real > > &vec, const Real stat=0)
void setStatistic(const std::vector< Real > &stat, const int comp=0, const int index=0)
ROL::Ptr< Vector< Real > > dual_vec1_
void setScalar(const Real C)
Set where .
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
ROL::Ptr< StdVector< Real > > getStatisticVector(const int comp, const int index=0)
RiskVector(ROL::Ptr< ROL::ParameterList > &parlistObj, std::vector< ROL::Ptr< ROL::ParameterList > > &parlistCon, const ROL::Ptr< Vector< Real > > &vec, const Real stat=0)
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
void setStatistic(const Real stat, const int comp=0, const int index=0)
Defines the linear algebra or vector space interface.
void setVector(const Vector< Real > &vec)
void plus(const Vector< Real > &x)
Compute , where .
ROL::Ptr< std::vector< Real > > statObj_
RiskVector(const ROL::Ptr< Vector< Real > > &vec, const ROL::Ptr< std::vector< Real > > &statObj, const std::vector< ROL::Ptr< std::vector< Real > > > &statCon)
void initializeCon(std::vector< ROL::Ptr< ROL::ParameterList > > &parlist, const Real stat=1)
std::vector< ROL::Ptr< StdVector< Real > > > statCon_vec_
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)
ROL::Ptr< Vector< Real > > getVector(void)
ROL::Ptr< RiskVector< Real > > dual_vec_
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
ROL::Ptr< const std::vector< Real > > getStatistic(const int comp=0, const int index=0) const
ROL::Ptr< const StdVector< Real > > getStatisticVector(const int comp, const int index=0) const
ROL::Ptr< Vector< Real > > basis(const int i) const
Return i-th basis vector.
Real norm(void) const
Returns where .
RiskVector(const ROL::Ptr< Vector< Real > > &vec)
ROL::Ptr< StdVector< Real > > statObj_vec_
Real reduce(const Elementwise::ReductionOp< Real > &r) const
Real dot(const Vector< Real > &x) const
Compute where .
void initializeObj(ROL::Ptr< ROL::ParameterList > &parlist, const Real stat=1)
ROL::Ptr< Vector< Real > > vec_
std::vector< ROL::Ptr< std::vector< Real > > > statCon_