14 for (
int i = 0; i < vParams.GetSize(); i++)
15 vParams[i] = 1.0 * rand() / RAND_MAX - 0.5;
20 lout <<
"[ModelExam] Test Normalization (nlen=" << nLen <<
")" << endl;
27 while (nodeIter.Next()) {
36 lout <<
"[ModelExam] Test Expectation (nlen=" << nLen <<
")" << endl;
49 while (nodeIter.Next()) {
56 if (fabs(exp1[i] - exp2[i]) > 1e-4) {
57 lout <<
"[Warning] i="<<i<<
" "<< exp1[i] <<
" " << exp2[i] <<
" " << exp1[i] - exp2[i] << endl;
64 lout <<
"[ModelExam] Test Hidden Exp (nlen=" << nLen <<
")" << endl;
76 LogP mglogp1, mglogp2, mplogpAIS;
102 if (fabs(exp1[i] - exp2[i]) > 1e-4) {
103 lout <<
"[Warning] i=" << i <<
" " << exp1[i] <<
" " << exp2[i] <<
" " << exp1[i] - exp2[i] << endl;
110 lout <<
"[ModelExam] Test Sample (nlen=" << nLen <<
")" << endl;
133 File fdbg(
"test_sample_exp.dbg",
"wt");
134 fdbg.
PrintArray(
"%f ", exp1.GetBuf(), exp1.GetSize());
135 int nSampleNum = 1000;
136 int nSampleTime = 100;
139 for (
int t = 1; t <= nSampleTime; t++) {
140 for (
int i = 0; i < nSampleNum; i++) {
151 exp2 /= t * nSampleNum;
152 exp3 /= t* nSampleNum;
153 fdbg.
PrintArray(
"%f ", exp2.GetBuf(), exp2.GetSize());
154 fdbg.
PrintArray(
"%f ", exp3.GetBuf(), exp3.GetSize());
155 double diff2 =
VecDiff(exp1.GetBuf(), exp2.GetBuf(), exp2.GetSize());
156 double diff3 =
VecDiff(exp1.GetBuf(), exp3.GetBuf(), exp3.GetSize());
157 lout <<
"t=" << t <<
" diff2-1=" << diff2 <<
" diff3-1=" << diff3 << endl;
158 exp2 *= t * nSampleNum;
159 exp3 *= t * nSampleNum;
162 exp2 /= nSampleTime * nSampleNum;
163 len2 /= nSampleTime * nSampleNum;
165 lout << i <<
"\t" << len1[i] <<
"\t" << len2[i] << endl;
173 m.pm->ExactNormalize();
int GetParamNum() const
Get the total parameter number.
void SetValueAll(PValue v)
set parameter values
int GetEncodeNodeLimit() const
The encoded integer size.
int m_hnode
the number of hidden nodes
void TestSample(int nLen=-1)
test sample
void SetPi(Prob *pPi)
Set the pi.
LogP Log_Sum(LogP x, LogP y)
void GetNodeExp(double *pExp, Prob *pLenProb=NULL)
[exact] sum_l { n_l/n * E_{p_l}[f] }: Exactly calculate the expectation over x and h ...
virtual void SetParam(PValue *pParam)
Set the parameters.
void TestHiddenExp(int nLen)
test hidden expectation
double ExactNormalize(int nLen)
[exact] Exact Normalization, return the logz of given length
void SetValueRand()
set parameter values randomly
void FeatCount(Seq &seq, VecShell< double > featcount, Mat3dShell< double > VHcount, Mat3dShell< double > CHcount, Mat3dShell< double > HHcount, MatShell< double > Bcount, double dadd=1)
Count the feature number in current sequence, and add to the result.
int GetEncodeHiddenLimit() const
The encoded integer size.
void TestGradient()
test the sa gradient
void Set(Array< int > &aInt, Vocab *pv)
transform the word sequence (form file) to Seq
void DecodeNode(int n, VocabID &xi, VocabID &ci, VecShell< HValue > &hi)
decode a integer to the x_i and h_i
Vocab * GetVocab() const
Get Vocab.
double VecDiff(T *pVec1, T *pVec2, int len)
[Vec-function] |v1-v2|
void DecodeHidden(int n, VecShell< HValue > hi)
decode a integer to a hidden vector
int m_hlayer
the number of hidden layer
void MarkovMove(Seq &seq)
[sample] Markov Move - perform the gibbs sampling
Log lout
the defination is in wb-log.cpp
void PrintArray(const char *pformat, TYPE *pbuf, int num)
print a array into file
LogP GetLogProb_AIS(VecShell< VocabID > &x, int nChain=10, int nIntermediate=10000)
perform AIS to esitmate the mariginal probabilities
void RandSeq(Seq &seq, int nLen=-1)
Random init sequence, if nLen==-1, random the length also.
int GetMaxLen() const
Get max-len.
void GetHiddenExp(VecShell< int > x, double *pExp)
[exact] E_{p_l(h|x)}[f]: don't clean the pExp and directly add the new exp to pExp.
LogP GetLogProb(Seq &seq, bool bNorm=true)
calculate the probability
void Sample(Seq &seq)
[sample] Perform one train-dimensional mixture sampling
void TestNormalization(int nLen)
test the exact normalization
void TestExpectation(int nLen)
test feat expectation