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
23namespace ROL {
24
25template<typename Real>
26class l1Objective : public Objective<Real> {
27private:
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)); }
34
35public:
36
37 l1Objective(const Ptr<Vector<Real>> &weights)
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.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual void applyUnary(const Elementwise::UnaryFunction< Real > &f)
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Provides the interface to evaluate the weighted/shifted l1 objective function.
l1Objective(const Ptr< Vector< Real > > &weights, const Ptr< Vector< Real > > &shift)
const Ptr< Vector< Real > > shift_
void prox(Vector< Real > &Pv, const Vector< Real > &v, Real t, Real &tol)
Compute the proximity operator.
const Ptr< Vector< Real > > weights_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Ptr< Vector< Real > > tmp_
Real dirDeriv(const Vector< Real > &x, const Vector< Real > &d, Real &tol)
Compute directional derivative.
ROL::l1Objective::ProjSymBnd psb_
l1Objective(const Ptr< Vector< Real > > &weights)
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Real apply(const Real &xc, const Real &yc) const