44 #ifndef ROL_MEANDEVIATION_HPP
45 #define ROL_MEANDEVIATION_HPP
70 order_.push_back((order < 2.0) ? 2.0 : order);
72 coeff_.push_back((coeff < 0.0) ? 1.0 : coeff);
78 if ( order.size() != coeff.size() ) {
79 coeff.resize(order.size(),1.0);
81 for (
unsigned i = 0; i < order.size(); i++ ) {
82 order_.push_back((order[i] < 2.0) ? 2.0 : order[i]);
83 coeff_.push_back((coeff[i] < 0.0) ? 1.0 : coeff[i]);
111 x0 = Teuchos::rcp(&
const_cast<Vector<Real> &
>(x),
false);
112 v0 = Teuchos::rcp(&
const_cast<Vector<Real> &
>(v),
false);
115 void update(
const Real val,
const Real weight) {
126 typename std::vector<Teuchos::RCP<Vector<Real> > >::iterator it = (this->
gradient_storage_).end();
140 typename std::vector<Teuchos::RCP<Vector<Real> > >::iterator it = (this->
gradient_storage_).end();
155 sampler.
sumAll(&val,&ev,1);
157 Real diff = 0.0, pf0 = 0.0, dev = 0.0;
158 std::vector<Real> devp(this->
order_.size(),0.0);
159 std::vector<Real> devs(this->
order_.size(),0.0);
160 for (
unsigned i = 0; i < this->
weights_.size(); i++ ) {
163 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
167 sampler.
sumAll(&devp[0],&devs[0],devp.size());
168 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
169 dev += (this->
coeff_[p])*std::pow(devs[p],1.0/this->
order_[p]);
180 sampler.
sumAll(&val,&ev,1);
182 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, c = 0.0;
183 std::vector<Real> dev0(this->
order_.size(),0.0);
184 std::vector<Real> des0(this->
order_.size(),0.0);
185 std::vector<Real> dev1(this->
order_.size(),0.0);
186 std::vector<Real> des1(this->
order_.size(),0.0);
187 for (
unsigned i = 0; i < this->
weights_.size(); i++ ) {
191 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
193 dev1[p] += (this->
weights_[i]) * std::pow(pf0,this->
order_[p]-1.0) * pf1;
196 sampler.
sumAll(&dev0[0],&des0[0],dev0.size());
197 sampler.
sumAll(&dev1[0],&des1[0],dev1.size());
198 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
199 dev0[p] = std::pow(des0[p],1.0-1.0/this->
order_[p]);
202 Teuchos::RCP<Vector<Real> > gtmp = g.
clone();
204 for (
unsigned i = 0; i < this->
weights_.size(); i++ ) {
209 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
210 if ( dev0[p] > 0.0 ) {
211 c += (this->
coeff_[p])/dev0[p] * (std::pow(pf0,this->
order_[p]-1.0)*pf1 - des1[p]);
225 sampler.
sumAll(&val,&ev,1);
228 sampler.
sumAll(&gv,&egv,1);
230 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, pf2 = 0.0;
231 Real cg = 0.0, ch = 0.0, diff1 = 0.0, diff2 = 0.0, diff3 = 0.0;
232 std::vector<Real> dev0(this->
order_.size(),0.0);
233 std::vector<Real> dev1(this->
order_.size(),0.0);
234 std::vector<Real> dev2(this->
order_.size(),0.0);
235 std::vector<Real> dev3(this->
order_.size(),0.0);
236 std::vector<Real> des0(this->
order_.size(),0.0);
237 std::vector<Real> des1(this->
order_.size(),0.0);
238 std::vector<Real> des2(this->
order_.size(),0.0);
239 std::vector<Real> des3(this->
order_.size(),0.0);
240 std::vector<Real> devp(this->
order_.size(),0.0);
241 std::vector<Real> gvp1(this->
order_.size(),0.0);
242 std::vector<Real> gvp2(this->
order_.size(),0.0);
243 std::vector<Real> gvp3(this->
order_.size(),0.0);
244 std::vector<Real> gvs1(this->
order_.size(),0.0);
245 std::vector<Real> gvs2(this->
order_.size(),0.0);
246 std::vector<Real> gvs3(this->
order_.size(),0.0);
247 for (
unsigned i = 0; i < this->
weights_.size(); i++ ) {
252 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
254 dev1[p] += (this->
weights_[i]) * std::pow(pf0,this->
order_[p]-1.0) * pf1;
255 dev2[p] += (this->
weights_[i]) * std::pow(pf0,this->
order_[p]-2.0) * pf1 * pf1;
256 dev3[p] += (this->
weights_[i]) * std::pow(pf0,this->
order_[p]-1.0) * pf2;
259 sampler.
sumAll(&dev0[0],&des0[0],dev0.size());
260 sampler.
sumAll(&dev1[0],&des1[0],dev1.size());
261 sampler.
sumAll(&dev2[0],&des2[0],dev2.size());
262 sampler.
sumAll(&dev3[0],&des3[0],dev3.size());
263 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
264 devp[p] = std::pow(des0[p],2.0-1.0/this->
order_[p]);
265 dev0[p] = std::pow(des0[p],1.0-1.0/this->
order_[p]);
272 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
273 gvp1[p] += (this->
weights_[i]) * (std::pow(pf0,this->
order_[p]-1.0)*pf1-des1[p]) *
275 gvp2[p] += (this->
weights_[i]) * (std::pow(pf0,this->
order_[p]-2.0)*pf1*pf1-des2[p]) *
277 gvp3[p] += (this->
weights_[i]) * (std::pow(pf0,this->
order_[p]-1.0)*pf2-des3[p]) *
281 sampler.
sumAll(&gvp1[0],&gvs1[0],gvp1.size());
282 sampler.
sumAll(&gvp2[0],&gvs2[0],gvp2.size());
283 sampler.
sumAll(&gvp3[0],&gvs3[0],gvp3.size());
285 Teuchos::RCP<Vector<Real> > htmp = hv.
clone();
287 for (
unsigned i = 0; i < this->
weights_.size(); i++ ) {
294 for (
unsigned p = 0; p < this->
order_.size(); p++ ) {
295 if ( dev0[p] > 0.0 ) {
296 diff1 = std::pow(pf0,this->
order_[p]-1.0)*pf1-des1[p];
299 cg += this->
coeff_[p]*diff1/dev0[p];
300 ch += this->
coeff_[p]*(((this->
order_[p]-1.0)*diff2+diff3)/dev0[p] -
301 (this->
order_[p]-1.0)*gvs1[p]*diff1/devp[p]);
Real getValue(SampleGenerator< Real > &sampler)
MeanDeviation(Real order, Real coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
void sumAll(Real *input, Real *output, int dim) const
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
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< Real > value_storage_
std::vector< Teuchos::RCP< Vector< Real > > > gradient_storage_
std::vector< Real > gradvec_storage_
void update(const Real val, const Real weight)
void update(const Real val, const Vector< Real > &g, const Real gv, const Vector< Real > &hv, const Real weight)
void update(const Real val, const Vector< Real > &g, const Real weight)
MeanDeviation(std::vector< Real > &order, std::vector< Real > &coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
Teuchos::RCP< PositiveFunction< Real > > positiveFunction_
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
std::vector< Real > weights_
std::vector< Real > coeff_
std::vector< Teuchos::RCP< Vector< Real > > > hessvec_storage_
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)