50 Seq() : m_nLen(0),m_hnode(0),m_hlayer(0) {};
51 Seq(
int len,
int hlayer,
int hnode) : m_nLen(0), m_hnode(0), m_hlayer(0) {
Reset(len, hlayer, hnode); }
53 void SetLen(
int len) { m_nLen = len; }
60 void Reset(
int len,
int hlayer,
int hnode);
81 virtual LogP ClusterSum(
int *pSeq,
int nLen,
int nPos,
int nOrder);
84 #define HHMap(h1, h2) (int)((h1) * 2 + (h2)) 86 #define HRF_VALUE_SET(p, m) \ 87 memcpy(m.GetBuf(), p, sizeof(PValue)*m.GetSize()); \ 89 #define HRF_VALUE_GET(p, m) \ 90 memcpy(p, m.GetBuf(), sizeof(PValue)*m.GetSize()); \ 113 m_nSampleHAccTimes(0), m_nSampleHTotalTimes(0),
114 m_nLenJumpAccTimes(0), m_nLenJumpTotalTime(0)
116 Model(Vocab *pv,
int hlayer,
int hnode,
int maxlen) :
trf::
Model(pv, maxlen),
117 m_hlayer(hlayer), m_hnode(hnode), m_nodeCal(this),
118 m_nSampleHAccTimes(0), m_nSampleHTotalTimes(0),
119 m_nLenJumpAccTimes(0), m_nLenJumpTotalTime(0)
121 Reset(pv, hlayer, hnode, maxlen);
124 void Reset(Vocab *pv,
int hlayer,
int hnode,
int maxlen);
132 virtual void SetParam(PValue *pParam);
134 void GetParam(PValue *pParam);
136 LogP GetLogProb(
Seq &seq,
bool bNorm =
true);
139 void ReadT(
const char *pfilename);
141 void WriteT(
const char *pfilename);
148 LogP ClusterSum(
Seq &seq,
int nPos,
int nOrder);
150 LogP HiddenClusterSum(
Seq &seq,
int nPos,
int nOrder);
152 LogP FeatClusterSum(
trf::Seq &x,
int nPos,
int nOrder);
154 LogP LayerClusterSum(
Seq &seq,
int nlayer,
int nPos,
int nOrder);
156 double ExactNormalize(
int nLen);
158 void ExactNormalize();
160 LogP GetMarginalLogProb(
int nLen,
int nPos,
Seq &sub,
bool bNorm =
true);
162 void GetNodeExp(
double *pExp, Prob *pLenProb = NULL);
164 void GetNodeExp(
int nLen,
double *pExp);
172 void GetLayerExp(
AlgLayer &fb,
int nLayer,
181 void Sample(
Seq &seq);
184 void LocalJump(
Seq &seq);
186 void MarkovMove(
Seq &seq);
188 LogP ProposeLength(
int nOld,
int &nNew,
bool bSample);
192 LogP ProposeC0(VocabID &ci,
Seq &seq,
int nPos,
bool bSample);
201 void ProposeHProbs(
VecShell<LogP> &logps,
Seq &seq,
int nPos,
bool bConsiderXandC =
false);
205 LogP GetReducedModelForH(
Seq &seq,
int nPos);
207 LogP GetReducedModelForC(
Seq &seq,
int nPos);
209 LogP GetReducedModelForW(
Seq &seq,
int nPos);
213 LogP GetMarginalProbOfC(
Seq &seq,
int nPos);
215 void SampleC(
Seq &seq,
int nPos);
218 LogP SampleW(
Seq &seq,
int nPos,
bool bSample =
true);
220 void RandSeq(
Seq &seq,
int nLen = -1);
222 void RandHidden(
Seq &seq);
239 int GetEncodeNodeLimit()
const;
247 int GetEncodeHiddenLimit()
const;
251 int GetEncodeLayerLimit()
const;
255 template <
typename T>
261 VH.
Reset(p, m_m3dVH.GetXDim(), m_m3dVH.GetYDim(), m_m3dVH.GetZDim());
263 CH.
Reset(p, m_m3dCH.GetXDim(), m_m3dCH.GetYDim(), m_m3dCH.GetZDim());
265 HH.
Reset(p, m_m3dHH.GetXDim(), m_m3dHH.GetYDim(), m_m3dHH.GetZDim());
275 void HiddenFeatCount(
Seq &seq,
290 void PerformSAMS(
int nMinibatch,
int tmax,
int t0,
int beta,
double zgap = 10);
292 LogP GetLogProb_AIS(
VecShell<VocabID> &x,
int nChain = 10,
int nIntermediate = 10000);
310 virtual LogP ClusterSum(
int *pSeq,
int nLen,
int nPos,
int nOrder);
int m_nSampleHAccTimes
sample H the acceptance times
int GetParamNum() const
Get the total parameter number.
int GetHnode() const
get hidden node dimension
int GetParamNum() const
Get parameter number.
m WriteT(cfg_pathModelWrite)
int m_hnode
the number of hidden nodes
Seq GetSubSeq(int nPos, int nOrder)
Return the sub-sequence.
void Reset(int len, int hlayer, int hnode)
bool operator==(Seq &s)
If the two sequence is equal.
VecShell< VocabID > GetWordSeq()
Mat3d< PValue > m_m3dHH
the weight between adjacent Hidden(H)
int m_nLen
mutiple hidden matrix [position * (layer * hnode)]
hidden-random-field model
AlgNode m_nodeCal
the forward-backward calculation for node (x and h)
void BufMap(T *p, VecShell< T > &feat, Mat3dShell< T > &VH, Mat3dShell< T > &CH, Mat3dShell< T > &HH, MatShell< T > &Bias)
Map a paremeter vector to each kinds of parameters.
void Reset(T *p, int size)
define a sequence including the word sequence and class sequence
Mat3d< PValue > m_m3dCH
the weight between Class(C) and Hidden(H)
int GetHiddenOrder() const
Get HH mat order.
Seq(int len, int hlayer, int hnode)
VocabID * GetClassSeq()
get class sequence
int m_hlayer
the number of hidden layer
VocabID * GetWordSeq()
get word sequence
int m_nLenJumpAccTimes
lenght jump the acceptance times
int m_nSampleHTotalTimes
sample H the total times
Mat< PValue > m_matBias
the bias for each value of Hidden(H)
void Reset(T *p, int xdim, int ydim, int zdim)
void Reset(T *pbuf, int row, int col)
Mat3d< PValue > m_m3dVH
the weight between Word(V) and Hidden(H)
Model(Vocab *pv, int hlayer, int hnode, int maxlen)