| 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 |
#pragma once |
| 11 |
#ifndef L1_PENALTY_OBJECTIVE_HPP |
| 12 |
#define L1_PENALTY_OBJECTIVE_HPP |
| 13 |
|
| 14 |
#include "ROL_Objective.hpp" |
| 15 |
#include "l1_utilities.hpp" |
| 16 |
|
| 17 |
/* Reformulates the unconstrained sparse penalization problem |
| 18 |
|
| 19 |
min_x f(x) + gamma ||g(x)||_1 |
| 20 |
|
| 21 |
to the general constrained problem |
| 22 |
|
| 23 |
min_{x,r,s} f(x) + gamma * sum(r + s) |
| 24 |
subject to c(x,r,s) = g(x) - (r - s) = 0 |
| 25 |
r,s >= 0 |
| 26 |
Teuchos::GlobalMPISession::GlobalMPISession |
| 27 |
*/ |
| 28 |
|
| 29 |
namespace ROL { |
| 30 |
|
| 31 |
template<typename Real> |
| 32 |
class L1PenaltyObjective : public Objective<Real> { |
| 33 |
public: |
| 34 |
L1PenaltyObjective( const Ptr<Objective<Real>>& obj, |
| 35 |
const Vector<Real>& emul, |
| 36 |
Real gamma ) |
| 37 |
: obj_(obj), e_(emul.clone()), gamma_(gamma) { |
| 38 |
e_->setScalar(1.0); |
| 39 |
} |
| 40 |
|
| 41 |
void update( const Vector<Real>& x, UpdateType type, int iter = -1 ) override { |
| 42 |
auto [xp] = pv_cast(x); |
| 43 |
obj_->update(xp[X],type,iter); |
| 44 |
} |
| 45 |
|
| 46 |
Real value( const Vector<Real>& x, Real& tol ) override { |
| 47 |
auto [xp] = pv_cast(x); |
| 48 |
auto fval = obj_->value(xp[X],tol); |
| 49 |
return fval + gamma_*(e_->dot(xp[R])+e_->dot(xp[S])); |
| 50 |
} |
| 51 |
|
| 52 |
void gradient( Vector<Real>& g, |
| 53 |
const Vector<Real>& x, |
| 54 |
Real& tol ) override { |
| 55 |
auto [gp,xp] = pv_cast(g,x); |
| 56 |
obj_->gradient(gp[X],xp[X],tol); |
| 57 |
gp[R].setScalar(gamma_); |
| 58 |
gp[S].setScalar(gamma_); |
| 59 |
} |
| 60 |
|
| 61 |
void hessVec( Vector<Real>& hv, |
| 62 |
const Vector<Real>& v, |
| 63 |
const Vector<Real>& x, |
| 64 |
Real& tol ) override { |
| 65 |
auto [hvp,vp,xp] = pv_cast(hv,v,x); |
| 66 |
obj_->hessVec(hvp[X],vp[X],xp[X],tol); |
| 67 |
hvp[R].zero(); |
| 68 |
hvp[S].zero(); |
| 69 |
} |
| 70 |
|
| 71 |
// PartitionedVector block indices |
| 72 |
static constexpr int X{0}, R{1}, S{2}; |
| 73 |
|
| 74 |
|
| 75 |
private: |
| 76 |
Ptr<Objective<Real>> obj_; |
| 77 |
Ptr<Vector<Real>> e_; |
| 78 |
Real gamma_; |
| 79 |
}; |
| 80 |
|
| 81 |
|
| 82 |
} // namespace ROL |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
#endif //L1_PENALTY_OBJECTIVE_HPP |
| 87 |
|