54 virtual void SetParam(
double *pdParams) = 0;
69 #define lout_Solve wb::lout<<m_pAlgorithmName<<" " 98 m_pAlgorithmName =
"[Solve]";
112 virtual bool Run(
const double *pInitParams = NULL);
122 virtual void ComputeDir(
int k,
const double *pdParam,
const double *pdGradient,
double *pdDir);
131 virtual double LineSearch(
double *pdDir,
double dValue,
const double *pdParam,
const double *pdGradient);
133 virtual void Update(
double *pdParam,
const double *pdDir,
double dStep);
135 virtual bool StopDecision(
int k,
double dValue,
const double *pdGradient);
139 static double VecProduct(
const double *pdVec1,
const double *pdVec2,
int nSize);
141 static double VecNorm(
const double *pdVec,
int nSize);
143 static double VecDist(
const double *pdVec1,
const double *pdVec2,
int nSize);
172 m_pCirQueueBuf = NULL;
173 m_nCirQueueBufTail = 0;
177 m_pdPrevGradient = NULL;
178 m_pdPrevParam = NULL;
188 CirQueueBuf_Release();
191 virtual void IterInit();
193 virtual void ComputeDir(
int k,
const double *pdParam,
const double *pdGradient,
double *pdDir);
195 void CirQueueBuf_Init();
197 void CirQueueBuf_Release();
199 void CirQueueBuf_Prev(
int i,
double *&pd_s,
double *&pd_y);
201 void CirQueueBuf_In(
double *&pd_s,
double *&pd_y);
double * m_pdPrevParam
parameter on previous iteration
the base class of all the solve classes, and provide a gradient descent algorithm.
int m_nIterMin
minium iteration number
sy * m_pCirQueueBuf
the buffer of circular queue to store s_k = x_k - x_(k-1) and y_k = g_k - g_{k-1} ...
LBFGS(Func *pfunc=NULL, double dtol=1e-5)
constructor
virtual void SetParam(double *pdParams)=0
set the parameter.
virtual void IterInit()
initial the iteration, for derivation.
virtual void GetGradient(double *pdGradient)=0
calculate the gradient g(x)
a definition of a class Log, which can output to the cmd window and the log file simultaneously. In wb-log.cpp, there are a Log variable "lout", which can be directly used just like "cout". For example:
int m_nIterNum
current iteration number, iter form m_nIterMin to m_nIterMax
virtual double GetValue()=0
calculate the function value f(x)
Provide the toolkits for cmd window of window platform.
#define SAFE_DELETE_ARRAY(p)
int m_nIterMax
maximum iteration number
int m_nLimitiedNum
limited number, i.e. m
int GetParamNum() const
get the paremeter number
double * m_pdRoot
save the root of the function
double m_dGain
itera step. ==0 means using the line search .
Func * m_pfunc
pointer to the function
double m_dStop
stop threshold
double * m_pdAlpha
auxillary factor in ComputeDir
const char * m_pAlgorithmName
the algorithm name.
static const int cn_exvalue_max_num
virtual int GetExtraValues(int k, double *pdValues)
calculate extra values which will be print at each iteration
int m_nParamNum
the parameter number
Solve * m_pSolve
Save the solve pointor.
double * m_pd_y
current s_k = x_k - x_{k-1} and y_k
double * m_pdPrevGradient
gradient on previous iteration
void SetParamNum(int n)
setting the parameter number
int m_nCirQueueBufTail
queue tail
the objective function, used to derive
double VecNorm(T *pVec, int len)
[Vec-function] sqrt(v*v^T);
double m_dSpendMinute
record the iteration spend time��minute��
Solve(Func *pfunc=NULL, double dtol=1e-5)
define all the code written by Bin Wang.
Defination of simple dynamic array/stack/queue and so on.