44 #ifndef ROL_PROBABILITYVECTOR_H
45 #define ROL_PROBABILITYVECTOR_H
72 int numMySamples =
static_cast<int>(yval.size());
73 ROL_TEST_FOR_EXCEPTION((i < 0 || i >= numMySamples), std::invalid_argument,
74 ">>> ERROR (ROL::ProbabilityVector): index out of bounds in getProbability!");
80 int numMySamples =
static_cast<int>(yval.size());
81 ROL_TEST_FOR_EXCEPTION((i < 0 || i >= numMySamples), std::invalid_argument,
82 ">>> ERROR (ROL::ProbabilityVector): index out of bounds in setProbability!");
93 class PrimalProbabilityVector :
public ProbabilityVector<Real> {
97 mutable ROL::Ptr<DualProbabilityVector<Real> >
dual_vec_;
103 const ROL::Ptr<std::vector<Real> > &
scale)
110 uint numMySamples =
static_cast<uint>(yval.size());
111 ROL_TEST_FOR_EXCEPTION( xval.size() != numMySamples, std::invalid_argument,
112 "Error: Vectors must have the same dimension." );
113 Real val(0), sum_val(0);
114 for (
uint i = 0; i < numMySamples; i++) {
115 val += xval[i] * (*scale_)[i] * yval[i];
122 ROL::Ptr<Vector<Real> >
clone(
void)
const {
124 return ROL::makePtr<PrimalProbabilityVector>(
125 ROL::makePtr<std::vector<Real>>(numMySamples),
132 dual_vec_ = ROL::makePtr<DualProbabilityVector<Real>>(
133 ROL::makePtr<std::vector<Real>>(numMySamples),
137 for (
uint i = 0; i < numMySamples; ++i) {
146 class DualProbabilityVector :
public ProbabilityVector<Real> {
156 const ROL::Ptr<std::vector<Real> > &
scale)
163 uint numMySamples =
static_cast<uint>(yval.size());
164 ROL_TEST_FOR_EXCEPTION( xval.size() != numMySamples, std::invalid_argument,
165 "Error: Vectors must have the same dimension." );
166 Real val(0), sum_val(0);
167 for (
uint i = 0; i < numMySamples; i++) {
168 val += xval[i] * yval[i] / (*scale_)[i];
175 ROL::Ptr<Vector<Real> >
clone(
void)
const {
177 return ROL::makePtr<DualProbabilityVector>(
178 ROL::makePtr<std::vector<Real>>(numMySamples),
185 primal_vec_ = ROL::makePtr<PrimalProbabilityVector<Real>>(
186 ROL::makePtr<std::vector<Real>>(numMySamples),
190 for (
uint i = 0; i < numMySamples; i++) {
std::vector< Real >::size_type uint
typename PV< Real >::size_type size_type
void scale(const Real alpha)
Compute where .
PrimalProbabilityVector(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BatchManager< Real > > &bman, const ROL::Ptr< std::vector< Real > > &scale)
const Real getProbability(const int i) const
ROL::Ptr< DualProbabilityVector< Real > > dual_vec_
const ROL::Ptr< BatchManager< Real > > getBatchManager(void) const
Provides the std::vector implementation of the ROL::Vector interface.
Ptr< const std::vector< Element > > getVector() const
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Defines the linear algebra or vector space interface.
ProbabilityVector(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BatchManager< Real > > &bman)
Real dot(const Vector< Real > &x) const
Compute where .
ROL::Ptr< std::vector< Real > > scale_
std::vector< Real >::size_type uint
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
DualProbabilityVector(const ROL::Ptr< std::vector< Real > > &vec, const ROL::Ptr< BatchManager< Real > > &bman, const ROL::Ptr< std::vector< Real > > &scale)
void setProbability(const int i, const Real wt)
ROL::Ptr< PrimalProbabilityVector< Real > > primal_vec_
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
Provides the std::vector implementation of the ROL::Vector interface.
std::vector< Real >::size_type uint
std::vector< Real >::size_type uint
Real dot(const Vector< Real > &x) const
Compute where .
ROL::Ptr< std::vector< Real > > scale_
int getNumMyAtoms(void) const