44 #ifndef ROL_MEANDEVIATIONFROMTARGET_HPP
45 #define ROL_MEANDEVIATIONFROMTARGET_HPP
60 std::vector<Teuchos::RCP<Vector<Real> > >
pg0_;
61 std::vector<Teuchos::RCP<Vector<Real> > >
pg_;
62 std::vector<Teuchos::RCP<Vector<Real> > >
phv_;
71 order_.push_back((order < 2.0) ? 2.0 : order);
73 coeff_.push_back((coeff < 0.0) ? 1.0 : coeff);
80 if ( order.size() != target.size() ) {
81 target.resize(order.size(),0.0);
83 if ( order.size() != coeff.size() ) {
84 coeff.resize(order.size(),1.0);
86 for (
unsigned i = 0; i < order.size(); i++ ) {
88 order_.push_back((order[i] < 2.0) ? 2.0 : order[i]);
89 coeff_.push_back((coeff[i] < 0.0) ? 1.0 : coeff[i]);
102 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
109 x0 = Teuchos::rcp(&
const_cast<Vector<Real> &
>(x),
false);
122 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
129 x0 = Teuchos::rcp(&
const_cast<Vector<Real> &
>(x),
false);
130 v0 = Teuchos::rcp(&
const_cast<Vector<Real> &
>(v),
false);
133 void update(
const Real val,
const Real weight) {
134 Real diff = 0.0, pf0 = 0.0;
136 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
139 this->
pval_[p] += weight * std::pow(pf0,this->
order_[p]);
144 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, c = 0.0;
145 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
149 c = std::pow(pf0,this->
order_[p]-1.0) * pf1;
150 (this->
pg_[p])->axpy(weight * c,g);
151 this->
pval_[p] += weight * std::pow(pf0,this->
order_[p]);
158 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, pf2 = 0.0, p0 = 0.0, p1 = 0.0, p2 = 0.0, c = 0.0;
159 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
164 p0 = std::pow(pf0,this->
order_[p]);
165 p1 = std::pow(pf0,this->
order_[p]-1.0);
166 p2 = std::pow(pf0,this->
order_[p]-2.0);
167 c = -(this->
order_[p]-1.0)*p1*pf1;
168 this->
pg0_[p]->axpy(weight*c,g);
169 c = gv*((this->
order_[p]-1.0)*p2*pf1*pf1 + p1*pf2);
170 this->
pg_[p]->axpy(weight*c,g);
172 this->
phv_[p]->axpy(weight*c,hv);
173 this->
pval_[p] += weight*p0;
174 this->
pgv_[p] += weight*p1*pf1*gv;
182 sampler.
sumAll(&val,&dev,1);
183 std::vector<Real> pval_sum(this->
pval_.size());
185 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
186 dev += this->
coeff_[p] * std::pow(pval_sum[p],1.0/this->
order_[p]);
193 std::vector<Real> pval_sum(this->
pval_.size());
195 Teuchos::RCP<Vector<Real> > pg;
196 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
197 if ( pval_sum[p] > 0.0 ) {
198 pg = (this->
pg_[p])->clone();
206 std::vector<Real> pval_sum(this->
pval_.size());
208 std::vector<Real> pgv_sum(this->
pgv_.size());
211 Teuchos::RCP<Vector<Real> > pg, pg0, phv;
212 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
213 if ( pval_sum[p] > 0.0 ) {
214 pg = (this->
pg_[p])->clone();
216 pg0 = (this->
pg0_[p])->clone();
218 phv = (this->
phv_[p])->clone();
220 c = this->
coeff_[p]*(pgv_sum[p]/std::pow(pval_sum[p],2.0-1.0/this->
order_[p]));
222 c = this->
coeff_[p]/std::pow(pval_sum[p],1.0-1.0/this->
order_[p]);
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
MeanDeviationFromTarget(std::vector< Real > &target, std::vector< Real > &order, std::vector< Real > &coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
std::vector< Real > target_
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void update(const Real val, const Vector< Real > &g, const Real gv, const Vector< Real > &hv, const Real weight)
Defines the linear algebra or vector space interface.
void sumAll(Real *input, Real *output, int dim) const
std::vector< Real > coeff_
MeanDeviationFromTarget(Real target, Real order, Real coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
std::vector< Real > pval_
Real getValue(SampleGenerator< Real > &sampler)
std::vector< Teuchos::RCP< Vector< Real > > > phv_
void update(const Real val, const Real weight)
Teuchos::RCP< PositiveFunction< Real > > positiveFunction_
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x, Teuchos::RCP< Vector< Real > > &v0, const Vector< Real > &v)
std::vector< Real > order_
std::vector< Teuchos::RCP< Vector< Real > > > pg_
std::vector< Teuchos::RCP< Vector< Real > > > pg0_
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)
void update(const Real val, const Vector< Real > &g, const Real weight)