DiSMEC++
dismec::solvers::CGMinimizer Class Reference

Approximately solve a linear equation Ax + b = 0. More...

#include <cg.h>

Inheritance diagram for dismec::solvers::CGMinimizer:
dismec::HyperParameterBase

Public Types

using MatrixVectorProductFn = std::function< void(const DenseRealVector &, Eigen::Ref< DenseRealVector >)>
 
- Public Types inherited from dismec::HyperParameterBase
using hyper_param_t = std::variant< long, double >
 

Public Member Functions

 CGMinimizer (long num_vars)
 
long minimize (const MatrixVectorProductFn &A, const DenseRealVector &b, const DenseRealVector &M)
 Solves Ax+b=0. returns the number of iterations. More...
 
const DenseRealVectorget_solution () const
 returns the solution vector found by the last minimize call More...
 
double get_epsilon () const
 Gets the value of the tolerance hyperparameter. More...
 
void set_epsilon (double v)
 Sets the value of the tolerance hyperparameter. More...
 
- Public Member Functions inherited from dismec::HyperParameterBase
 HyperParameterBase ()=default
 
virtual ~HyperParameterBase ()=default
 
 HyperParameterBase (const HyperParameterBase &)=default
 
 HyperParameterBase (HyperParameterBase &&)=default
 
HyperParameterBaseoperator= (HyperParameterBase &&)=default
 
HyperParameterBaseoperator= (const HyperParameterBase &)=default
 
void set_hyper_parameter (const std::string &name, long value)
 
void set_hyper_parameter (const std::string &name, double value)
 
hyper_param_t get_hyper_parameter (const std::string &name) const
 
std::vector< std::string > get_hyper_parameter_names () const
 Returns a vector that lists all hyper parameter names. More...
 

Private Member Functions

long do_minimize (const MatrixVectorProductFn &A, const DenseRealVector &b, const DenseRealVector &M)
 

Private Attributes

long m_Size
 
real_t m_Epsilon = CG_DEFAULT_EPSILON
 
DenseRealVector m_A_times_d
 
DenseRealVector m_S
 s from the CG algorithm More...
 
DenseRealVector m_Residual
 r_k from the CG algorithm More...
 
DenseRealVector m_Conjugate
 p_k from the CG algorithm More...
 

Additional Inherited Members

- Protected Member Functions inherited from dismec::HyperParameterBase
template<class U , class S >
void declare_hyper_parameter (std::string name, U S::*pointer)
 
template<class U , class S >
void declare_hyper_parameter (std::string name, U(S::*getter)() const, void(S::*setter)(U))
 Declares an constrained hyper-parameter with explicit getter and setter function. More...
 
template<class T , class S >
void declare_sub_object (const std::string &name, T S::*object)
 Declares a sub-object that also contains hyper-parameters. More...
 

Detailed Description

Approximately solve a linear equation Ax + b = 0.

This class uses a CG algorithm to approximately solve Ax + b = 0. It does not require the entire matrix A but only a function that allows to calculate Ad for an arbitrary vector d. This class has a size of approximately 5n sizeof(double) for n being the number of variables.

Definition at line 23 of file cg.h.

Member Typedef Documentation

◆ MatrixVectorProductFn

using dismec::solvers::CGMinimizer::MatrixVectorProductFn = std::function<void(const DenseRealVector &, Eigen::Ref<DenseRealVector>)>

Type of function that calculates hessian-vector product. The first argument is the vector, the second argument is an (potentially uninitialized) output argument in which to place the product.

Definition at line 27 of file cg.h.

Constructor & Destructor Documentation

◆ CGMinimizer()

CGMinimizer::CGMinimizer ( long  num_vars)
explicit

Member Function Documentation

◆ do_minimize()

long CGMinimizer::do_minimize ( const MatrixVectorProductFn A,
const DenseRealVector b,
const DenseRealVector M 
)
private

Definition at line 26 of file cg.cpp.

References dismec::CG_MIN_ITER_BOUND, m_A_times_d, m_Conjugate, m_Epsilon, m_Residual, m_S, and m_Size.

Referenced by minimize().

◆ get_epsilon()

double dismec::solvers::CGMinimizer::get_epsilon ( ) const
inline

Gets the value of the tolerance hyperparameter.

Definition at line 38 of file cg.h.

References m_Epsilon.

Referenced by CGMinimizer().

◆ get_solution()

const DenseRealVector& dismec::solvers::CGMinimizer::get_solution ( ) const
inline

returns the solution vector found by the last minimize call

Definition at line 35 of file cg.h.

References m_S.

Referenced by dismec::solvers::NewtonWithLineSearch::run().

◆ minimize()

long CGMinimizer::minimize ( const MatrixVectorProductFn A,
const DenseRealVector b,
const DenseRealVector M 
)

Solves Ax+b=0. returns the number of iterations.

Definition at line 21 of file cg.cpp.

References do_minimize().

Referenced by dismec::solvers::NewtonWithLineSearch::run().

◆ set_epsilon()

void dismec::solvers::CGMinimizer::set_epsilon ( double  v)
inline

Sets the value of the tolerance hyperparameter.

Definition at line 41 of file cg.h.

References m_Epsilon.

Referenced by CGMinimizer().

Member Data Documentation

◆ m_A_times_d

DenseRealVector dismec::solvers::CGMinimizer::m_A_times_d
private

Definition at line 50 of file cg.h.

Referenced by CGMinimizer(), and do_minimize().

◆ m_Conjugate

DenseRealVector dismec::solvers::CGMinimizer::m_Conjugate
private

p_k from the CG algorithm

Definition at line 53 of file cg.h.

Referenced by CGMinimizer(), and do_minimize().

◆ m_Epsilon

real_t dismec::solvers::CGMinimizer::m_Epsilon = CG_DEFAULT_EPSILON
private

Definition at line 47 of file cg.h.

Referenced by do_minimize(), get_epsilon(), and set_epsilon().

◆ m_Residual

DenseRealVector dismec::solvers::CGMinimizer::m_Residual
private

r_k from the CG algorithm

Definition at line 52 of file cg.h.

Referenced by CGMinimizer(), and do_minimize().

◆ m_S

DenseRealVector dismec::solvers::CGMinimizer::m_S
private

s from the CG algorithm

Definition at line 51 of file cg.h.

Referenced by CGMinimizer(), do_minimize(), and get_solution().

◆ m_Size

long dismec::solvers::CGMinimizer::m_Size
private

Definition at line 46 of file cg.h.

Referenced by do_minimize().


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