3 #include "hrf-corpus.h" 18 AISConfig(
int p_nChain = 16,
int p_nInter = 1000) :nChain(p_nChain), nInter(p_nInter){}
21 char *p = strtok(tempStr.
GetBuffer(),
":,");
23 p = strtok(NULL,
":,");
35 void Create(
int maxlen,
Model *pModel);
112 SAfunc() :m_nMiniBatchSample(100), m_nMiniBatchTraining(100) {
116 m_bPrintTrain =
true;
117 m_bPrintValie =
true;
120 m_bSAMSSample =
false;
124 Reset(pModel, pTrain, pValid, pTest, nMinibatch);
128 m_bPrintTrain =
true;
129 m_bPrintValie =
true;
132 m_bSAMSSample =
false;
138 for (
int i = 0; i < m_aSeqs.
GetNum(); i++)
140 for (
int i = 0; i < m_threadData.
GetNum(); i++) {
167 void RandSeq(
Seq &seq,
int nLen = -1);
169 void GetParam(
double *pdParams);
192 double GetSampleLL(
CorpusBase *pCorpus,
int nCalNum = -1,
int method = 0);
194 void IterEnd(
double *pFinalParams);
196 void WriteModel(
int nEpoch);
198 virtual void SetParam(
double *pdParams);
199 virtual void GetGradient(
double *pdGradient);
201 virtual int GetExtraValues(
int t,
double *pdValues);
216 void Reset(
const char *pstr,
int p_t0);
261 m_pAlgorithmName =
"[SA]";
263 m_pAlgorithmName =
"[CD]";
271 m_bUpdate_lambda =
true;
272 m_bUpdate_zeta =
true;
287 virtual bool Run(
const double *pInitParams = NULL);
289 void UpdateGamma(
int nIterNum);
291 void UpdateDir(
double *pDir,
double *pGradient,
const double *pParam);
293 virtual void Update(
double *pdParam,
const double *pdDir,
double dStep);
297 int CutValue(
double *p,
int num,
double gap);
#define SAFE_DELETE(p)
memory release
trf::CorpusRandSelect m_TrainSelect
random select the sequence from corpus
the base class of all the solve classes, and provide a gradient descent algorithm.
wb::Array< int > m_aWriteAtIter
output temp model at some iteration
bool m_bPrintTrain
output the LL on training set
bool m_bSAMSSample
if using the sams sampling method
bool m_bPrintValie
output the LL on valid set
File m_fdbg
output the sample pi/zete information
virtual double GetValue()
calculate the function value f(x)
Vec< Prob > m_samplePi
the length distribution used for sample
int m_nMiniBatchTraining
mini-batch for training set
hidden-random-field model
SAtrain(SAfunc *pfunc=NULL)
int nInter
intermediate distribution number
AISConfig m_AISConfigForZ
the AIS configuration for normalization
int m_nAvgBeg
if >0, then calculate the average
LearningRate m_gain_lambda
int GetWeightNum() const
get the bias mat number
void Parse(const char *str)
File m_fgrad
output the gradient of each iteration
int GetZetaNum() const
get the zeta parameter number
int m_nTrainHiddenSampleTimes
the sample times for training sequence
File m_fexp
output the expectation of each iteartion
bool m_bPrintTest
output the LL on test set
int m_nCDSampleTimes
the CD-n: the sample number.
SAfunc(Model *pModel, CorpusBase *pTrain, CorpusBase *pValid=NULL, CorpusBase *pTest=NULL, int nMinibatch=100)
int GetVHmatSize() const
get the VH mat number
File m_fvar
output the variance at each iteration
AISConfig m_AISConfigForP
the AIS configuration for calculating the LL.
File m_feat_mean
output the empirical mean
int GetCHmatSize() const
get the CH mat number
float m_fMomentum
the momentum
int m_nSampleHiddenSampleTimes
the sample times for the hidden of samples
int GetHHmatSize() const
get the HH mat number
File m_feat_var
output the empirical variance
File m_fsamp
output all the samples
int m_nPrintPerIter
output the LL per iteration, if ==-1, the disable
int GetNum() const
Get Array number.
LearningRate m_gain_hidden
File m_fparm
output the parameters of each iteration
double m_fEpochNum
the current epoch number
char * GetBuffer() const
get buffer
CorpusCache m_TrainCache
cache all the h of training sequences.
int m_nMiniBatchSample
mini-batch for samples
File m_ftrain
output all the training sequences
int m_nSASampleTimes
the SA sample times
int GetNgramFeatNum() const
get the ngram feature number
AISConfig(int p_nChain=16, int p_nInter=1000)