SOPT
Sparse OPTimisation
Public Types | Public Member Functions | List of all members
sopt::proximal::WeightedL2Ball< T > Class Template Reference

#include <proximal.h>

+ Inheritance diagram for sopt::proximal::WeightedL2Ball< T >:
+ Collaboration diagram for sopt::proximal::WeightedL2Ball< T >:

Public Types

using Real = typename L2Ball< T >::Real
 
using t_Vector = Vector< Real >
 
- Public Types inherited from sopt::proximal::L2Ball< T >
using Real = typename real_type< T >::type
 

Public Member Functions

template<typename T0 >
 WeightedL2Ball (Real epsilon, Eigen::DenseBase< T0 > const &w)
 Constructs an L2 ball proximal of size epsilon with given weights. More...
 
 WeightedL2Ball (Real epsilon)
 Constructs an L2 ball proximal of size epsilon. More...
 
void operator() (Vector< T > &out, typename real_type< T >::type, Vector< T > const &x) const
 Calls proximal function. More...
 
void operator() (Vector< T > &out, Vector< T > const &x) const
 Calls proximal function. More...
 
template<typename T0 >
EnveloppeExpression< WeightedL2Ball, T0 > operator() (Real const &, Eigen::MatrixBase< T0 > const &x) const
 Lazy version. More...
 
template<typename T0 >
EnveloppeExpression< WeightedL2Ball, T0 > operator() (Eigen::MatrixBase< T0 > const &x) const
 Lazy version. More...
 
t_Vector const & weights () const
 Weights associated with each dimension. More...
 
template<typename T0 >
WeightedL2Ball< T > & weights (Eigen::MatrixBase< T0 > const &w)
 Weights associated with each dimension. More...
 
Real epsilon () const
 Size of the ball. More...
 
WeightedL2Ball< T > & epsilon (Real const &eps)
 Size of the ball. More...
 
- Public Member Functions inherited from sopt::proximal::L2Ball< T >
 L2Ball (Real epsilon)
 Constructs an L2 ball proximal of size epsilon. More...
 
void operator() (Vector< T > &out, typename real_type< T >::type, Vector< T > const &x) const
 Calls proximal function. More...
 
void operator() (Vector< T > &out, Vector< T > const &x) const
 Calls proximal function. More...
 
template<typename T0 >
EnveloppeExpression< L2Ball, T0 > operator() (Real const &, Eigen::MatrixBase< T0 > const &x) const
 Lazy version. More...
 
template<typename T0 >
EnveloppeExpression< L2Ball, T0 > operator() (Eigen::MatrixBase< T0 > const &x) const
 Lazy version. More...
 
Real epsilon () const
 Size of the ball. More...
 
L2Ball< T > & epsilon (Real eps)
 Size of the ball. More...
 

Detailed Description

template<typename T>
class sopt::proximal::WeightedL2Ball< T >

Definition at line 246 of file proximal.h.

Member Typedef Documentation

◆ Real

template<typename T >
using sopt::proximal::WeightedL2Ball< T >::Real = typename L2Ball<T>::Real

Definition at line 248 of file proximal.h.

◆ t_Vector

template<typename T >
using sopt::proximal::WeightedL2Ball< T >::t_Vector = Vector<Real>

Definition at line 249 of file proximal.h.

Constructor & Destructor Documentation

◆ WeightedL2Ball() [1/2]

template<typename T >
template<typename T0 >
sopt::proximal::WeightedL2Ball< T >::WeightedL2Ball ( Real  epsilon,
Eigen::DenseBase< T0 > const &  w 
)
inline

Constructs an L2 ball proximal of size epsilon with given weights.

Definition at line 267 of file proximal.h.

267 : L2Ball<T>(epsilon), weights_(w) {}
Real epsilon() const
Size of the ball.
Definition: proximal.h:312

◆ WeightedL2Ball() [2/2]

template<typename T >
sopt::proximal::WeightedL2Ball< T >::WeightedL2Ball ( Real  epsilon)
inline

Constructs an L2 ball proximal of size epsilon.

Definition at line 269 of file proximal.h.

269 : WeightedL2Ball(epsilon, t_Vector::Ones(1)) {}
WeightedL2Ball(Real epsilon, Eigen::DenseBase< T0 > const &w)
Constructs an L2 ball proximal of size epsilon with given weights.
Definition: proximal.h:267

Member Function Documentation

◆ epsilon() [1/2]

template<typename T >
Real sopt::proximal::WeightedL2Ball< T >::epsilon ( ) const
inline

Size of the ball.

Definition at line 312 of file proximal.h.

312 { return L2Ball<T>::epsilon(); }
Real epsilon() const
Size of the ball.
Definition: proximal.h:222

References sopt::proximal::L2Ball< T >::epsilon().

Referenced by sopt::proximal::WeightedL2Ball< T >::operator()(), and TEST_CASE().

◆ epsilon() [2/2]

template<typename T >
WeightedL2Ball<T>& sopt::proximal::WeightedL2Ball< T >::epsilon ( Real const &  eps)
inline

Size of the ball.

Definition at line 314 of file proximal.h.

314  {
315  L2Ball<T>::epsilon(eps);
316  return *this;
317  }

References sopt::proximal::L2Ball< T >::epsilon().

◆ operator()() [1/4]

template<typename T >
template<typename T0 >
EnveloppeExpression<WeightedL2Ball, T0> sopt::proximal::WeightedL2Ball< T >::operator() ( Eigen::MatrixBase< T0 > const &  x) const
inline

Lazy version.

Definition at line 297 of file proximal.h.

297  {
298  return {*this, x};
299  }

◆ operator()() [2/4]

template<typename T >
template<typename T0 >
EnveloppeExpression<WeightedL2Ball, T0> sopt::proximal::WeightedL2Ball< T >::operator() ( Real const &  ,
Eigen::MatrixBase< T0 > const &  x 
) const
inline

Lazy version.

Definition at line 291 of file proximal.h.

292  {
293  return {*this, x};
294  }

◆ operator()() [3/4]

template<typename T >
void sopt::proximal::WeightedL2Ball< T >::operator() ( Vector< T > &  out,
typename real_type< T >::type  ,
Vector< T > const &  x 
) const
inline

Calls proximal function.

Definition at line 273 of file proximal.h.

273  {
274  return operator()(out, x);
275  }
void operator()(Vector< T > &out, typename real_type< T >::type, Vector< T > const &x) const
Calls proximal function.
Definition: proximal.h:273

◆ operator()() [4/4]

template<typename T >
void sopt::proximal::WeightedL2Ball< T >::operator() ( Vector< T > &  out,
Vector< T > const &  x 
) const
inline

Calls proximal function.

Definition at line 277 of file proximal.h.

277  {
278 #ifdef SOPT_MPI
279  auto const norm = mpi::l2_norm(x.array(), weights().array(), communicator());
280 #else
281  auto const norm = weights().size() == 1 ? x.stableNorm() * std::abs(weights()(0))
282  : (x.array() * weights().array()).matrix().stableNorm();
283 #endif
284  if (norm > epsilon())
285  out = x * (epsilon() / norm);
286  else
287  out = x;
288  }
t_Vector const & weights() const
Weights associated with each dimension.
Definition: proximal.h:302
void l2_norm(Eigen::DenseBase< T0 > &out, Eigen::DenseBase< T2 > const &gamma, Eigen::DenseBase< T1 > const &x)
Definition: proximal.h:90

References sopt::proximal::WeightedL2Ball< T >::epsilon(), sopt::proximal::l2_norm(), and sopt::proximal::WeightedL2Ball< T >::weights().

◆ weights() [1/2]

template<typename T >
t_Vector const& sopt::proximal::WeightedL2Ball< T >::weights ( ) const
inline

Weights associated with each dimension.

Definition at line 302 of file proximal.h.

302 { return weights_; }

Referenced by sopt::proximal::WeightedL2Ball< T >::operator()().

◆ weights() [2/2]

template<typename T >
template<typename T0 >
WeightedL2Ball<T>& sopt::proximal::WeightedL2Ball< T >::weights ( Eigen::MatrixBase< T0 > const &  w)
inline

Weights associated with each dimension.

Definition at line 305 of file proximal.h.

305  {
306  if ((w.array() < 0e0).any()) SOPT_THROW("Weights cannot be negative");
307  if (w.stableNorm() < 1e-12) SOPT_THROW("Weights cannot be null");
308  weights_ = w;
309  return *this;
310  }
#define SOPT_THROW(MSG)
Definition: exception.h:46

References SOPT_THROW.


The documentation for this class was generated from the following file: