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>
|
| 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 () |
|
|
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) |
|
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
◆ Opt_CG()
ModuleBase::Opt_CG::Opt_CG |
( |
| ) |
|
◆ ~Opt_CG()
ModuleBase::Opt_CG::~Opt_CG |
( |
| ) |
|
◆ allocate()
void ModuleBase::Opt_CG::allocate |
( |
int |
nx | ) |
|
Allocate the space for pdirect_old and pgradient_old.
- Parameters
-
nx | length of the solution array x |
◆ get_iter()
int ModuleBase::Opt_CG::get_iter |
( |
| ) |
|
|
inline |
◆ get_residual()
double ModuleBase::Opt_CG::get_residual |
( |
| ) |
|
|
inline |
◆ 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
-
◆ init_b()
void ModuleBase::Opt_CG::init_b |
( |
double * |
pinp_b | ) |
|
Initialize b before solving Ax = b.
- Parameters
-
pinp_b | b in the linear equation Ax = b |
◆ inner_product()
double ModuleBase::Opt_CG::inner_product |
( |
double * |
pa, |
|
|
double * |
pb, |
|
|
int |
length |
|
) |
| |
|
inlineprivate |
◆ next_direct()
void ModuleBase::Opt_CG::next_direct |
( |
double * |
pgradient, |
|
|
int |
label, |
|
|
double * |
rdirect |
|
) |
| |
Get the next optimization direction.
- Parameters
-
[in] | pgradient | Ad for linear equaiont Ax=b, and gradient for general case |
[in] | label | 0 for solve Ax=b, 1 for PR form, 2 for HZ form. |
[in,out] | rdirect | the next optimization direction |
◆ 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
-
◆ 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_new | length of new x, default 0 means the length doesn't change |
pinp_b | new b in Ax = b, default nullptr means we are dealing with general case |
◆ set_para()
void ModuleBase::Opt_CG::set_para |
( |
double |
dV | ) |
|
◆ stantard_CGdirect()
void ModuleBase::Opt_CG::stantard_CGdirect |
( |
double * |
pAd, |
|
|
double * |
rdirect |
|
) |
| |
|
private |
Get the next optimization direction with standard CG workflow.
- Parameters
-
[in] | pAd | Ad for Ax=b |
[out] | rdirect | the next direction |
◆ step_length()
double ModuleBase::Opt_CG::step_length |
( |
double * |
pAd, |
|
|
double * |
pdirect, |
|
|
int & |
ifPD |
|
) |
| |
Get the step length, only work for standard CG.
- Parameters
-
pAd | Ad for Ax=b |
pdirect | direction |
ifPD | 0 if positive definite, -1, -2 when not |
- Returns
- the step length alpha
◆ 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:
- /home/runner/work/abacus-develop/abacus-develop/source/source_base/opt_CG.h
- /home/runner/work/abacus-develop/abacus-develop/source/source_base/opt_CG.cpp