44 #ifndef ROL_RISKVECTOR_HPP 45 #define ROL_RISKVECTOR_HPP 49 #include "Teuchos_ParameterList.hpp" 56 Teuchos::RCP<std::vector<Real> >
stat_;
58 Teuchos::RCP<Vector<Real> >
vec_;
71 : stat_(Teuchos::null), stat_vec_(Teuchos::null), vec_(vec),
72 augmented_(false), nStat_(0), isDualInitialized_(false) {
75 std::vector<Real> lower, upper;
76 bool activated(
false);
78 RiskMeasureInfo<Real>(parlist,name,nStat,lower,upper,activated);
79 augmented_ = (nStat > 0) ?
true :
false;
83 stat_ = Teuchos::rcp(
new std::vector<Real>(nStat_,stat));
89 const bool augmented =
false )
90 : stat_(Teuchos::null), stat_vec_(Teuchos::null), vec_(vec),
91 augmented_(augmented), nStat_((augmented ? 1 : 0)), isDualInitialized_(false) {
93 stat_ = Teuchos::rcp(
new std::vector<Real>(nStat_,0));
99 const std::vector<Real> &stat,
100 const bool augmented =
true )
101 : stat_(Teuchos::null), stat_vec_(Teuchos::null), vec_(vec),
102 augmented_(augmented), nStat_(stat.size()), isDualInitialized_(false) {
104 stat_ = Teuchos::rcp(
new std::vector<Real>(stat));
128 stat_vec_->scale(alpha);
150 return sqrt(
dot(*
this) );
153 Teuchos::RCP<Vector<Real> >
clone(
void)
const {
154 std::vector<Real> stat(nStat_,static_cast<Real>(0));
160 if ( !isDualInitialized_ ) {
161 dual_vec1_ = vec_->dual().clone();
162 std::vector<Real> stat(nStat_,static_cast<Real>(0));
164 isDualInitialized_ =
true;
167 dual_vec1_->set(vec_->dual());
176 Teuchos::RCP<Vector<Real> >
basis(
const int i )
const {
177 Teuchos::RCP<Vector<Real> > e1;
178 std::vector<Real> e2(nStat_,static_cast<Real>(0));
179 int n1 = vec_->dimension(), n2 = stat_vec_->dimension();
183 else if (i >= n1 && i < n1+n2) {
184 e1 = vec_->clone(); e1->zero();
185 e2[i-n1] =
static_cast<Real
>(1);
188 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
189 ">>> ERROR (ROL::RiskVector::Basis): index is out of bounds.");
194 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
197 stat_vec_->applyUnary(f);
209 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
210 Real result = r.initialValue();
211 r.reduce(vec_->reduce(r),result);
213 r.reduce(stat_vec_->reduce(r),result);
219 int dim = vec_->dimension();
221 dim += stat_vec_->dimension();
237 Teuchos::RCP<const Vector<Real> >
getVector(
void)
const {
249 TEUCHOS_TEST_FOR_EXCEPTION((i < 0 || i > (
int)nStat_-1),std::invalid_argument,
250 ">>> ERROR (ROL::RiskVector::getStatistic): index out-of-bounds.");
251 TEUCHOS_TEST_FOR_EXCEPTION(!augmented_,std::invalid_argument,
252 ">>> ERROR (ROL::RiskVector::getStatistic): vector is not augmented.");
259 stat.assign(stat_->begin(),stat_->end());
265 stat_->assign(nStat_,stat);
271 stat_->assign(stat.begin(),stat.end());
Real norm(void) const
Returns where .
void set(const Vector< Real > &x)
Set where .
void scale(const Real alpha)
Compute where .
int dimension(void) const
Return dimension of the vector space.
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
Defines the linear algebra or vector space interface.
void setStatistic(const std::vector< Real > &stat)
const Real getStatistic(const int i) const
Teuchos::RCP< const Vector< Real > > getVector(void) const
Teuchos::RCP< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
void setVector(const Vector< Real > &vec)
void plus(const Vector< Real > &x)
Compute , where .
Teuchos::RCP< Vector< Real > > getVector(void)
Teuchos::RCP< RiskVector< Real > > dual_vec_
RiskVector(const Teuchos::RCP< Vector< Real > > &vec, const std::vector< Real > &stat, const bool augmented=true)
void setStatistic(const Real stat)
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector< Real > &x)
Real dot(const Vector< Real > &x) const
Compute where .
Real reduce(const Elementwise::ReductionOp< Real > &r) const
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
RiskVector(Teuchos::ParameterList &parlist, const Teuchos::RCP< Vector< Real > > &vec, const Real stat=1)
Teuchos::RCP< Vector< Real > > dual_vec1_
Teuchos::RCP< std::vector< Real > > stat_
Teuchos::RCP< StdVector< Real > > stat_vec_
Teuchos::RCP< const StdVector< Real > > getStatistic(void) const
Teuchos::RCP< Vector< Real > > vec_
void getStatistic(std::vector< Real > &stat) const
RiskVector(const Teuchos::RCP< Vector< Real > > &vec, const bool augmented=false)
Teuchos::RCP< Vector< Real > > basis(const int i) const
Return i-th basis vector.
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Teuchos::RCP< StdVector< Real > > getStatistic(void)