ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ModuleBase::Opt_CG Class Reference

A class designed to deal with optimization problems with CG method. Three forms of CG methods have been implemented, including standard flow to solve the linear equation Ax = b, Polak-Ribire (PR) form and Hager-Zhang (HZ) form to solve general optimization problems min{f(x)}. We adopt following abbreviation x -> solution d -> direction g -> gradient. More...

#include <opt_CG.h>

Collaboration diagram for ModuleBase::Opt_CG:

Public Member Functions

 Opt_CG ()
 
 ~Opt_CG ()
 
void init_b (double *pinp_b)
 Initialize b before solving Ax = b.
 
void allocate (int nx)
 Allocate the space for pdirect_old and pgradient_old.
 
void set_para (double dV)
 
void refresh (int nx_new=0, double *pinp_b=nullptr)
 Refresh the class. If nx changes, reallocate space. If b is provided, initialize it.
 
void next_direct (double *pgradient, int label, double *rdirect)
 Get the next optimization direction.
 
double step_length (double *pAd, double *pdirect, int &ifPD)
 Get the step length, only work for standard CG.
 
double get_residual ()
 
int get_iter ()
 

Private Member Functions

void stantard_CGdirect (double *pAd, double *rdirect)
 Get the next optimization direction with standard CG workflow.
 
void PR_beta (double *pgradient)
 Get the beta in PR form. beta_k = max{0, <g_k, g_k-g_{k-1}>/<g_{k-1}, g_{k-1}>} <> means inner product.
 
void HZ_beta (double *pgradient)
 Get the beta in HZ form. See formula in Hager W W, Zhang H. SIAM Journal on optimization, 2005, 16(1): 170-192.
 
double inner_product (double *pa, double *pb, int length)
 

Private Attributes

double dV_ = 1.
 
int nx_ = 0
 
int iter_ = 0
 
double gg_ = 1000
 
double beta_ = 0.
 
double eta_ = 0.01
 
double * pdirect_old_ = nullptr
 
double * pgradient_old_ = nullptr
 
double alpha_ = 0.
 
double * pb_ = nullptr
 

Detailed Description

A class designed to deal with optimization problems with CG method. Three forms of CG methods have been implemented, including standard flow to solve the linear equation Ax = b, Polak-Ribire (PR) form and Hager-Zhang (HZ) form to solve general optimization problems min{f(x)}. We adopt following abbreviation x -> solution d -> direction g -> gradient.

Author
sunliang

Constructor & Destructor Documentation

◆ Opt_CG()

ModuleBase::Opt_CG::Opt_CG ( )

◆ ~Opt_CG()

ModuleBase::Opt_CG::~Opt_CG ( )

Member Function Documentation

◆ allocate()

void ModuleBase::Opt_CG::allocate ( int  nx)

Allocate the space for pdirect_old and pgradient_old.

Parameters
nxlength of the solution array x
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_iter()

int ModuleBase::Opt_CG::get_iter ( )
inline
Here is the caller graph for this function:

◆ get_residual()

double ModuleBase::Opt_CG::get_residual ( )
inline
Here is the caller graph for this function:

◆ HZ_beta()

void ModuleBase::Opt_CG::HZ_beta ( double *  pgradient)
private

Get the beta in HZ form. See formula in Hager W W, Zhang H. SIAM Journal on optimization, 2005, 16(1): 170-192.

Parameters
pgradientdf(x)/dx
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_b()

void ModuleBase::Opt_CG::init_b ( double *  pinp_b)

Initialize b before solving Ax = b.

Parameters
pinp_bb in the linear equation Ax = b
Here is the caller graph for this function:

◆ inner_product()

double ModuleBase::Opt_CG::inner_product ( double *  pa,
double *  pb,
int  length 
)
inlineprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ next_direct()

void ModuleBase::Opt_CG::next_direct ( double *  pgradient,
int  label,
double *  rdirect 
)

Get the next optimization direction.

Parameters
[in]pgradientAd for linear equaiont Ax=b, and gradient for general case
[in]label0 for solve Ax=b, 1 for PR form, 2 for HZ form.
[in,out]rdirectthe next optimization direction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PR_beta()

void ModuleBase::Opt_CG::PR_beta ( double *  pgradient)
private

Get the beta in PR form. beta_k = max{0, <g_k, g_k-g_{k-1}>/<g_{k-1}, g_{k-1}>} <> means inner product.

Parameters
pgradientdf(x)/dx
Here is the call graph for this function:
Here is the caller graph for this function:

◆ refresh()

void ModuleBase::Opt_CG::refresh ( int  nx_new = 0,
double *  pinp_b = nullptr 
)

Refresh the class. If nx changes, reallocate space. If b is provided, initialize it.

Parameters
nx_newlength of new x, default 0 means the length doesn't change
pinp_bnew b in Ax = b, default nullptr means we are dealing with general case
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_para()

void ModuleBase::Opt_CG::set_para ( double  dV)
Here is the caller graph for this function:

◆ stantard_CGdirect()

void ModuleBase::Opt_CG::stantard_CGdirect ( double *  pAd,
double *  rdirect 
)
private

Get the next optimization direction with standard CG workflow.

Parameters
[in]pAdAd for Ax=b
[out]rdirectthe next direction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ step_length()

double ModuleBase::Opt_CG::step_length ( double *  pAd,
double *  pdirect,
int &  ifPD 
)

Get the step length, only work for standard CG.

Parameters
pAdAd for Ax=b
pdirectdirection
ifPD0 if positive definite, -1, -2 when not
Returns
the step length alpha
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ alpha_

double ModuleBase::Opt_CG::alpha_ = 0.
private

◆ beta_

double ModuleBase::Opt_CG::beta_ = 0.
private

◆ dV_

double ModuleBase::Opt_CG::dV_ = 1.
private

◆ eta_

double ModuleBase::Opt_CG::eta_ = 0.01
private

◆ gg_

double ModuleBase::Opt_CG::gg_ = 1000
private

◆ iter_

int ModuleBase::Opt_CG::iter_ = 0
private

◆ nx_

int ModuleBase::Opt_CG::nx_ = 0
private

◆ pb_

double* ModuleBase::Opt_CG::pb_ = nullptr
private

◆ pdirect_old_

double* ModuleBase::Opt_CG::pdirect_old_ = nullptr
private

◆ pgradient_old_

double* ModuleBase::Opt_CG::pgradient_old_ = nullptr
private

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