ROL
ROL_l1Objective.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_L1OBJECTIVE_H
11 #define ROL_L1OBJECTIVE_H
12 
13 #include "ROL_Objective.hpp"
14 
23 namespace ROL {
24 
25 template<typename Real>
26 class l1Objective : public Objective<Real> {
27 private:
28  const Ptr<Vector<Real>> weights_, shift_;
29  Ptr<Vector<Real>> tmp_;
30 
31  struct ProjSymBnd : public Elementwise::BinaryFunction<Real> {
32  Real apply(const Real &xc, const Real &yc) const { return std::min(yc, std::max(-yc, xc)); }
33  } psb_;
34 
35 public:
36 
38  : weights_(weights), shift_(weights->dual().clone()) {
39  shift_->zero();
40  tmp_ = shift_->clone();
41  }
42 
43  l1Objective(const Ptr<Vector<Real>> &weights, const Ptr<Vector<Real>> &shift)
44  : weights_(weights), shift_(shift) {
45  tmp_ = shift_->clone();
46  }
47 
48  Real value( const Vector<Real> &x, Real &tol ) {
49  tmp_->set(x);
50  tmp_->axpy(static_cast<Real>(-1),*shift_);
51  tmp_->applyUnary(Elementwise::AbsoluteValue<Real>());
52  return weights_->apply(*tmp_);
53  }
54 
55  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
56  g.set(x);
57  g.axpy(static_cast<Real>(-1),*shift_);
58  g.applyUnary(Elementwise::Sign<Real>());
59  g.applyBinary(Elementwise::Multiply<Real>(), *weights_);
60  }
61 
62  Real dirDeriv( const Vector<Real> &x, const Vector<Real> &d, Real &tol ) {
63  gradient(*tmp_, x, tol);
64  return tmp_->apply(d);
65  }
66 
67  void prox( Vector<Real> &Pv, const Vector<Real> &v, Real t, Real &tol){
68  Pv.set(*shift_);
69  Pv.axpy(static_cast<Real>(-1), v);
70  Pv.scale(static_cast<Real>(1) / t);
72  Pv.scale(t);
73  Pv.plus(v);
74  }
75 //TODO: input prox jacobian
76 }; // class l1Objective
77 
78 } // namespace ROL
79 
80 #endif
Provides the interface to evaluate objective functions.
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
const double weights[4][5]
Definition: ROL_Types.hpp:838
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
Definition: ROL_Vector.hpp:214
void prox(Vector< Real > &Pv, const Vector< Real > &v, Real t, Real &tol)
Compute the proximity operator.
l1Objective(const Ptr< Vector< Real >> &weights)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Real value(const Vector< Real > &x, Real &tol)
Compute value.
ROL::l1Objective::ProjSymBnd psb_
Real dirDeriv(const Vector< Real > &x, const Vector< Real > &d, Real &tol)
Compute directional derivative.
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &f)
Definition: ROL_Vector.hpp:208
const Ptr< Vector< Real > > weights_
Ptr< Vector< Real > > tmp_
Provides the interface to evaluate the weighted/shifted l1 objective function.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
l1Objective(const Ptr< Vector< Real >> &weights, const Ptr< Vector< Real >> &shift)
const Ptr< Vector< Real > > shift_
Real apply(const Real &xc, const Real &yc) const