SOPT
Sparse OPTimisation
Classes | Public Types | Public Member Functions | List of all members
sopt::algorithm::PowerMethod< SCALAR > Class Template Reference

Eigenvalue and eigenvector for eigenvalue with largest magnitude. More...

#include <power_method.h>

Classes

struct  DiagnosticAndResult
 Holds result vector as well. More...
 

Public Types

using value_type = SCALAR
 Scalar type. More...
 
using Scalar = value_type
 Scalar type. More...
 
using Real = typename real_type< Scalar >::type
 Real type. More...
 
using t_Vector = Vector< Scalar >
 Type of then underlying vectors. More...
 
using t_LinearTransform = LinearTransform< t_Vector >
 Type of the Ψ and Ψ^H operations, as well as Φ and Φ^H. More...
 

Public Member Functions

 PowerMethod ()
 Setups ProximalADMM. More...
 
virtual ~PowerMethod ()
 
DiagnosticAndResult AtA (t_LinearTransform const &A, t_Vector const &input) const
 Maximum number of iterations. More...
 
template<typename DERIVED >
DiagnosticAndResult operator() (Eigen::DenseBase< DERIVED > const &A, t_Vector const &input) const
 Calls the power method for A, with A a matrix. More...
 
DiagnosticAndResult operator() (OperatorFunction< t_Vector > const &op, t_Vector const &input) const
 Calls the power method for a given matrix-vector multiplication function. More...
 

Detailed Description

template<typename SCALAR>
class sopt::algorithm::PowerMethod< SCALAR >

Eigenvalue and eigenvector for eigenvalue with largest magnitude.

Definition at line 137 of file power_method.h.

Member Typedef Documentation

◆ Real

template<typename SCALAR >
using sopt::algorithm::PowerMethod< SCALAR >::Real = typename real_type<Scalar>::type

Real type.

Definition at line 144 of file power_method.h.

◆ Scalar

template<typename SCALAR >
using sopt::algorithm::PowerMethod< SCALAR >::Scalar = value_type

Scalar type.

Definition at line 142 of file power_method.h.

◆ t_LinearTransform

template<typename SCALAR >
using sopt::algorithm::PowerMethod< SCALAR >::t_LinearTransform = LinearTransform<t_Vector>

Type of the Ψ and Ψ^H operations, as well as Φ and Φ^H.

Definition at line 148 of file power_method.h.

◆ t_Vector

template<typename SCALAR >
using sopt::algorithm::PowerMethod< SCALAR >::t_Vector = Vector<Scalar>

Type of then underlying vectors.

Definition at line 146 of file power_method.h.

◆ value_type

template<typename SCALAR >
using sopt::algorithm::PowerMethod< SCALAR >::value_type = SCALAR

Scalar type.

Definition at line 140 of file power_method.h.

Constructor & Destructor Documentation

◆ PowerMethod()

template<typename SCALAR >
sopt::algorithm::PowerMethod< SCALAR >::PowerMethod ( )
inline

Setups ProximalADMM.

Definition at line 163 of file power_method.h.

163 : itermax_(std::numeric_limits<t_uint>::max()), tolerance_(1e-8) {}

◆ ~PowerMethod()

template<typename SCALAR >
virtual sopt::algorithm::PowerMethod< SCALAR >::~PowerMethod ( )
inlinevirtual

Definition at line 164 of file power_method.h.

164 {}

Member Function Documentation

◆ AtA()

template<typename SCALAR >
PowerMethod< SCALAR >::DiagnosticAndResult sopt::algorithm::PowerMethod< SCALAR >::AtA ( t_LinearTransform const &  A,
t_Vector const &  input 
) const

Maximum number of iterations.

Convergence criteria

Calls the power method for A.adjoint() * A

Definition at line 199 of file power_method.h.

200  {
201  auto const op = [&A](t_Vector &out, t_Vector const &input) -> void {
202  out = A.adjoint() * static_cast<t_Vector>(A * input);
203  };
204  return operator()(op, input);
205 }
sopt::Vector< Scalar > t_Vector
DiagnosticAndResult operator()(Eigen::DenseBase< DERIVED > const &A, t_Vector const &input) const
Calls the power method for A, with A a matrix.
Definition: power_method.h:209

References sopt::LinearTransform< VECTOR >::adjoint().

Referenced by main().

◆ operator()() [1/2]

template<typename SCALAR >
template<typename DERIVED >
PowerMethod< SCALAR >::DiagnosticAndResult sopt::algorithm::PowerMethod< SCALAR >::operator() ( Eigen::DenseBase< DERIVED > const &  A,
t_Vector const &  input 
) const

Calls the power method for A, with A a matrix.

Definition at line 209 of file power_method.h.

210  {
211  Matrix<Scalar> const Ad = A.derived();
212  auto const op = [&Ad](t_Vector &out, t_Vector const &input) -> void { out = Ad * input; };
213  return operator()(op, input);
214 }
sopt::Matrix< Scalar > Matrix
Definition: inpainting.cc:29

◆ operator()() [2/2]

template<typename SCALAR >
PowerMethod< SCALAR >::DiagnosticAndResult sopt::algorithm::PowerMethod< SCALAR >::operator() ( OperatorFunction< t_Vector > const &  op,
t_Vector const &  input 
) const

Calls the power method for a given matrix-vector multiplication function.

Definition at line 217 of file power_method.h.

218  {
219  SOPT_INFO("Computing the upper bound of a given operator");
220  SOPT_INFO(" - input vector {}", input.transpose());
221  t_Vector eigenvector = input.normalized();
222  SOPT_INFO(" - eigenvector norm {}", eigenvector.stableNorm());
223  typename t_Vector::Scalar previous_magnitude = 1;
224  bool converged = false;
225  t_uint niters = 0;
226 
227  for (; niters < itermax() and converged == false; ++niters) {
228  op(eigenvector, eigenvector);
229  typename t_Vector::Scalar const magnitude =
230  eigenvector.stableNorm() / static_cast<Real>(eigenvector.size());
231  auto const rel_val = std::abs((magnitude - previous_magnitude) / previous_magnitude);
232  converged = rel_val < tolerance();
233  SOPT_INFO(" - [PM] iteration {}/{} -- norm: {}", niters, itermax(), magnitude);
234 
235  eigenvector /= magnitude;
236  previous_magnitude = magnitude;
237  }
238  // check function exists, otherwise, don't know if convergence is meaningful
239  if (not converged) {
240  SOPT_WARN(" - [PM] did not converge within {} iterations", itermax());
241  } else {
242  SOPT_INFO(" - [PM] converged in {} of {} iterations", niters, itermax());
243  }
244  return DiagnosticAndResult{itermax(), converged, previous_magnitude, eigenvector.normalized()};
245 }
sopt::t_real Scalar
typename real_type< Scalar >::type Real
Real type.
Definition: power_method.h:144
#define SOPT_WARN(...)
\macro Something might be going wrong
Definition: logging.h:213
#define SOPT_INFO(...)
\macro Verbose informational message about normal condition
Definition: logging.h:215
size_t t_uint
Root of the type hierarchy for unsigned integers.
Definition: types.h:15

References SOPT_INFO, and SOPT_WARN.


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