TRF Language Model
hrf::Model Class Reference

hidden-random-field model More...

#include <hrf-model.h>

Inheritance diagram for hrf::Model:
trf::Model

Public Member Functions

 Model (Vocab *pv)
 
 Model (Vocab *pv, int hlayer, int hnode, int maxlen)
 
void Reset (Vocab *pv, int hlayer, int hnode, int maxlen)
 reset, the maxlen is the length excluding the beg/end symbols. More...
 
int GetHnode () const
 get hidden node dimension More...
 
int GetHiddenOrder () const
 Get HH mat order. More...
 
int GetParamNum () const
 Get the total parameter number. More...
 
virtual void SetParam (PValue *pParam)
 Set the parameters. More...
 
void GetParam (PValue *pParam)
 Get the paremetre vector. More...
 
LogP GetLogProb (Seq &seq, bool bNorm=true)
 calculate the probability More...
 
void ReadT (const char *pfilename)
 Read Model. More...
 
void WriteT (const char *pfilename)
 Write Model. More...
 
LogP GetLogProb (VecShell< VocabID > &x, bool bNorm=true)
 [exact] calculate the probability of x More...
 
LogP ClusterSum (Seq &seq, int nPos, int nOrder)
 [exact] Calculate the logP in each cluster. Only used for forward-backword algorithms ( class AlgNode) More...
 
LogP HiddenClusterSum (Seq &seq, int nPos, int nOrder)
 [exact] Calculate the logp in each cluster. Only consinder the VH,CH,HH values, used in class AlgHidden More...
 
LogP FeatClusterSum (trf::Seq &x, int nPos, int nOrder)
 [exact] Calculate the logp in each cluster. Only consinder the feature values More...
 
LogP LayerClusterSum (Seq &seq, int nlayer, int nPos, int nOrder)
 [exact] Calculate the logp in each cluster. Only consinder the VH,CH,HH values on such layer More...
 
double ExactNormalize (int nLen)
 [exact] Exact Normalization, return the logz of given length More...
 
void ExactNormalize ()
 [exact] Exact Normalization all the length More...
 
LogP GetMarginalLogProb (int nLen, int nPos, Seq &sub, bool bNorm=true)
 [exact] Exactly calculate the marginal probability at position 'nPos' and with order 'nOrder' More...
 
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 More...
 
void GetNodeExp (int nLen, double *pExp)
 [exact] E_{p_l}[f]: Exactly calculate the expectation over x and h for length nLen More...
 
void GetNodeExp (int nLen, VecShell< double > featexp, Mat3dShell< double > VHexp, Mat3dShell< double > CHexp, Mat3dShell< double > HHexp, MatShell< double > Bexp)
 [exact] E_{p_l}[f]: Exactly calculate the expectation over x and h for length nLen More...
 
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. More...
 
void GetLayerExp (AlgLayer &fb, int nLayer, Mat3dShell< double > &VHexp, Mat3dShell< double > &CHexp, Mat3dShell< double > &HHexp, MatShell< double > &Bexp, LogP logz=0)
 [exact] called in GetHiddenExp. More...
 
void Sample (Seq &seq)
 [sample] Perform one train-dimensional mixture sampling More...
 
void LocalJump (Seq &seq)
 [sample] Local Jump - sample a new length More...
 
void MarkovMove (Seq &seq)
 [sample] Markov Move - perform the gibbs sampling More...
 
LogP ProposeLength (int nOld, int &nNew, bool bSample)
 [sample] Propose the length, using the variable m_matLenJump More...
 
LogP ProposeH0 (VecShell< HValue > &hi, Seq &seq, int nPos, bool bSample)
 [sample] Propose the h_{i} at position i. Then return the propose probability Q(h_i|h_{other}) More...
 
LogP ProposeC0 (VocabID &ci, Seq &seq, int nPos, bool bSample)
 [sample] Propose the c_{i} at position i. Then return the propose probability R(c_i|h_i,c_{other}) More...
 
void ProposeHProbs (VecShell< LogP > &logps, Seq &seq, int nPos, bool bConsiderXandC=false)
 [sample] A reduced model only consinder HHmat(W) and VHmat(M) and CHmat(U). More...
 
void ProposeCProbs (VecShell< LogP > &logps, Seq &seq, int nPos)
 [sample] Return the distribution of c_i at position nPos More...
 
LogP GetReducedModelForH (Seq &seq, int nPos)
 [sample] A unnormalized reduced model. It only consindering the HH matrix (W) More...
 
LogP GetReducedModelForC (Seq &seq, int nPos)
 [sample] A unnormalized reduced model to sample class c_i, consindering CH matrix(U) and class-ngram (lambda_c) More...
 
LogP GetReducedModelForW (Seq &seq, int nPos)
 [sample] A unnormalized reduced model to sample word w_i, consindering VH matrix(M) and word-ngram (lambda_w) More...
 
LogP GetConditionalProbForH (VecShell< HValue > &hi, VecShell< Prob > &probs)
 [sample] using the logprobs returned by ProposeHProb to calculate the logprob of hi. More...
 
LogP GetMarginalProbOfC (Seq &seq, int nPos)
 [sample] Fixed h, given c_i, summate the probabilities of x_i, i.e. P(c_i) More...
 
void SampleC (Seq &seq, int nPos)
 [sample] Sample the c_i at position nPos given h_i without x_i. More...
 
LogP SampleW (Seq &seq, int nPos, bool bSample=true)
 [sample] Sample the w_i at position nPos More...
 
void RandSeq (Seq &seq, int nLen=-1)
 Random init sequence, if nLen==-1, random the length also. More...
 
void RandHidden (Seq &seq)
 Random init the hidden variables. More...
 
virtual LogP SampleHAndCGivenX (Seq &seq, MatShell< HValue > *tagH=NULL)
 [sample] sample h given x using gibbs sampling. More...
 
int EncodeNode (VocabID xi, VocabID ci, VecShell< HValue > &hi)
 encode the x_i and h_i at position i to a integer More...
 
void EncodeNode (VecShell< int > &vn, Seq &seq, int nPos=0, int nDim=-1)
 encode the x and h to a integer sequence More...
 
void DecodeNode (int n, VocabID &xi, VocabID &ci, VecShell< HValue > &hi)
 decode a integer to the x_i and h_i More...
 
void DecodeNode (VecShell< int > &vn, Seq &seq, int nPos=0, int nDim=-1)
 decode several integer to a sequence More...
 
int GetEncodeNodeLimit () const
 The encoded integer size. More...
 
int EncodeHidden (VecShell< HValue > hi)
 encode the hidden vector h_i to a integer More...
 
void DecodeHidden (int n, VecShell< HValue > hi)
 decode a integer to a hidden vector More...
 
void DecodeHidden (VecShell< int > &vn, Mat< HValue > &h, int nPos=0, int nDim=-1)
 decoder several integer to a sequence More...
 
int GetEncodeHiddenLimit () const
 The encoded integer size. More...
 
void DecodeLayer (VecShell< int > &vn, Mat< HValue > &h, int layer, int nPos=0, int nDim=-1)
 decoder several integer to a sequence More...
 
int GetEncodeLayerLimit () const
 The encoded integer size of one layer. More...
 
template<typename T >
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. More...
 
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. More...
 
void HiddenFeatCount (Seq &seq, Mat3dShell< double > VHcount, Mat3dShell< double > CHcount, Mat3dShell< double > HHcount, MatShell< double > Bcount, double dadd=1)
 Count the hidden features. More...
 
void FeatCount (Seq &seq, VecShell< double > count, double dadd=1)
 Count the feature number in current sequence. More...
 
PValue SumVHWeight (MatShell< PValue > m, VecShell< HValue > h)
 
PValue SumHHWeight (Mat3dShell< PValue > m, VecShell< HValue > h1, VecShell< HValue > h2)
 
PValue SumVHWeight (MatShell< PValue > m, VecShell< HValue > h, int layer)
 
PValue SumHHWeight (Mat3dShell< PValue > m, VecShell< HValue > h1, VecShell< HValue > h2, int layer)
 
void PerformSAMS (int nMinibatch, int tmax, int t0, int beta, double zgap=10)
 perform the SAMS to estimate the normalization constants zeta More...
 
LogP GetLogProb_AIS (VecShell< VocabID > &x, int nChain=10, int nIntermediate=10000)
 perform AIS to esitmate the mariginal probabilities More...
 
LogP GetLogProb_Gibbs (VecShell< VocabID > &x, int num=100)
 sample the best hidden and calculate the joint probability. More...
 
- Public Member Functions inherited from trf::Model
 Model (Vocab *pv)
 constructor More...
 
 Model (Vocab *pv, int maxlen)
 constructor More...
 
 ~Model ()
 destructor More...
 
int GetMaxLen () const
 Get max-len. More...
 
VocabGetVocab () const
 Get Vocab. More...
 
int GetMaxOrder () const
 Get maximum order. More...
 
int GetParamNum () const
 Get parameter number. More...
 
void Reset (Vocab *pv, int maxlen)
 reset, the maxlen is the length excluding the beg/end symbols. More...
 
void GetParam (PValue *pValue)
 Get the paremetre vector. More...
 
void SetPi (Prob *pPi)
 Set the pi. More...
 
template<typename T >
void SetZeta (T *pzeta)
 Set updated zeta. More...
 
template<typename T >
void GetZeta (T *pzeta)
 
LogP GetLogProb (Seq &seq, bool bNorm=true)
 calculate the probability More...
 
void LoadFromCorpus (const char *pcorpus, const char *pfeatstyle, int nOrder)
 load ngram features from corpus More...
 
void FeatCount (Seq &seq, double *pCount, double dadd=1.0)
 Count the feature number in a sequence. More...
 
void ReadT (const char *pfilename)
 Read Model. More...
 
void WriteT (const char *pfilename)
 Write Model. More...
 
LogP ClusterSum (Seq &seq, int nPos, int nOrder)
 Read Binary. More...
 
void GetNodeExp (int nLen, double *pExp)
 [exact] E_{p_l}[f]: Exactly calculate the expectation over x and h for length nLen More...
 
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 More...
 
void Sample (Seq &seq)
 [sample] Perform one train-dimensional mixture sampling More...
 
void LocalJump (Seq &seq)
 [sample] Local Jump - sample a new length More...
 
virtual void MarkovMove (Seq &seq)
 [sample] Markov Move - perform the gibbs sampling More...
 
LogP ProposeLength (int nOld, int &nNew, bool bSample)
 [sample] Propose the length, using the variable m_matLenJump More...
 
LogP ProposeC0 (VocabID &ci, Seq &seq, int nPos, bool bSample)
 [sample] Propose the c_{i} at position i. Then return the propose probability R(c_i|h_i,c_{other}) More...
 
void ProposeCProbs (VecShell< LogP > &logps, Seq &seq, int nPos)
 [sample] Return the propose distribution of c_i at position nPos More...
 
LogP GetReducedModelForC (Seq &seq, int nPos)
 [sample] A unnormalized reduced model to sample class c_i. More...
 
LogP GetReducedModelForW (Seq &seq, int nPos)
 [sample] A unnormalized reduced model to sample word w_i. More...
 
LogP GetReducedModel (Seq &seq, int nPos)
 [sample] A unnormalized reduced depending on nPos. More...
 
LogP GetMarginalProbOfC (Seq &seq, int nPos)
 [sample] given c_i, summate the probabilities of x_i, i.e. P(c_i) More...
 
void SampleC (Seq &seq, int nPos)
 [sample] Sample the c_i at position nPos without x_i. More...
 
LogP SampleX (Seq &seq, int nPos, bool bSample=true)
 [sample] Sample the x_i at position nPos More...
 
LogP AISNormalize (int nLen, int nChain, int nInter)
 perform AIS to calculate the normalization constants, return the logz of given length More...
 
void AISNormalize (int nLenMin, int nLenMax, int nChain, int nInter)
 

Public Attributes

int m_hlayer
 the number of hidden layer More...
 
int m_hnode
 the number of hidden nodes More...
 
Mat3d< PValuem_m3dVH
 the weight between Word(V) and Hidden(H) More...
 
Mat3d< PValuem_m3dCH
 the weight between Class(C) and Hidden(H) More...
 
Mat3d< PValuem_m3dHH
 the weight between adjacent Hidden(H) More...
 
Mat< PValuem_matBias
 the bias for each value of Hidden(H) More...
 
int m_nSampleHAccTimes
 sample H the acceptance times More...
 
int m_nSampleHTotalTimes
 sample H the total times More...
 
int m_nLenJumpAccTimes
 lenght jump the acceptance times More...
 
int m_nLenJumpTotalTime
 
- Public Attributes inherited from trf::Model
Featm_pFeat
 hash all the features More...
 
Vec< PValuem_value
 the value for each features More...
 
int m_maxlen
 the maximum length of model, excluding <s> and </s>. The min-len = 1 More...
 
Vec< Probm_pi
 the prior length distribution More...
 
Vec< LogPm_logz
 the normalization constants log Z_l More...
 
Vec< LogPm_zeta
 the estimated normalization constants (fix = 0) More...
 
Vocabm_pVocab
 
Mat< Probm_matLenJump
 [sample] used to propose a new length More...
 
int m_maxSampleLen
 [sample] the maximum sample length, default = m_maxlen + 2 More...
 
int m_nLenJumpAccTimes
 lenght jump the acceptance times More...
 
int m_nLenJumpTotalTime
 total times of length jump More...
 
int m_nSampleHAccTimes
 sample H the acceptance times More...
 
int m_nSampleHTotalTimes
 

Protected Attributes

AlgNode m_nodeCal
 the forward-backward calculation for node (x and h) More...
 
- Protected Attributes inherited from trf::Model
AlgNode m_AlgNode
 the forward-backward calculation each node More...
 

Detailed Description

hidden-random-field model

Definition at line 98 of file hrf-model.h.

Constructor & Destructor Documentation

§ Model() [1/2]

hrf::Model::Model ( Vocab pv)
inline

Definition at line 112 of file hrf-model.h.

§ Model() [2/2]

hrf::Model::Model ( Vocab pv,
int  hlayer,
int  hnode,
int  maxlen 
)
inline

Definition at line 116 of file hrf-model.h.

Member Function Documentation

§ BufMap()

template<typename T >
void hrf::Model::BufMap ( T *  p,
VecShell< T > &  feat,
Mat3dShell< T > &  VH,
Mat3dShell< T > &  CH,
Mat3dShell< T > &  HH,
MatShell< T > &  Bias 
)
inline

Map a paremeter vector to each kinds of parameters.

Definition at line 256 of file hrf-model.h.

§ ClusterSum()

LogP hrf::Model::ClusterSum ( Seq seq,
int  nPos,
int  nOrder 
)

[exact] Calculate the logP in each cluster. Only used for forward-backword algorithms ( class AlgNode)

Definition at line 298 of file hrf-model.cpp.

§ DecodeHidden() [1/2]

void hrf::Model::DecodeHidden ( int  n,
VecShell< HValue hi 
)

decode a integer to a hidden vector

Definition at line 1152 of file hrf-model.cpp.

§ DecodeHidden() [2/2]

void hrf::Model::DecodeHidden ( VecShell< int > &  vn,
Mat< HValue > &  h,
int  nPos = 0,
int  nDim = -1 
)

decoder several integer to a sequence

Definition at line 1159 of file hrf-model.cpp.

§ DecodeLayer()

void hrf::Model::DecodeLayer ( VecShell< int > &  vn,
Mat< HValue > &  h,
int  layer,
int  nPos = 0,
int  nDim = -1 
)

decoder several integer to a sequence

Definition at line 1174 of file hrf-model.cpp.

§ DecodeNode() [1/2]

void hrf::Model::DecodeNode ( int  n,
VocabID xi,
VocabID ci,
VecShell< HValue > &  hi 
)

decode a integer to the x_i and h_i

Definition at line 1124 of file hrf-model.cpp.

§ DecodeNode() [2/2]

void hrf::Model::DecodeNode ( VecShell< int > &  vn,
Seq seq,
int  nPos = 0,
int  nDim = -1 
)

decode several integer to a sequence

Definition at line 1132 of file hrf-model.cpp.

§ EncodeHidden()

int hrf::Model::EncodeHidden ( VecShell< HValue hi)

encode the hidden vector h_i to a integer

Definition at line 1143 of file hrf-model.cpp.

§ EncodeNode() [1/2]

int hrf::Model::EncodeNode ( VocabID  xi,
VocabID  ci,
VecShell< HValue > &  hi 
)

encode the x_i and h_i at position i to a integer

Definition at line 1111 of file hrf-model.cpp.

§ EncodeNode() [2/2]

void hrf::Model::EncodeNode ( VecShell< int > &  vn,
Seq seq,
int  nPos = 0,
int  nDim = -1 
)

encode the x and h to a integer sequence

Definition at line 1117 of file hrf-model.cpp.

§ ExactNormalize() [1/2]

double hrf::Model::ExactNormalize ( int  nLen)
virtual

[exact] Exact Normalization, return the logz of given length

< max-order

Reimplemented from trf::Model.

Definition at line 403 of file hrf-model.cpp.

§ ExactNormalize() [2/2]

void hrf::Model::ExactNormalize ( )
virtual

[exact] Exact Normalization all the length

Reimplemented from trf::Model.

Definition at line 445 of file hrf-model.cpp.

§ FeatClusterSum()

LogP hrf::Model::FeatClusterSum ( trf::Seq x,
int  nPos,
int  nOrder 
)

[exact] Calculate the logp in each cluster. Only consinder the feature values

Definition at line 302 of file hrf-model.cpp.

§ FeatCount() [1/2]

void hrf::Model::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.

Definition at line 1186 of file hrf-model.cpp.

§ FeatCount() [2/2]

void hrf::Model::FeatCount ( Seq seq,
VecShell< double >  count,
double  dadd = 1 
)

Count the feature number in current sequence.

Definition at line 1234 of file hrf-model.cpp.

§ GetConditionalProbForH()

LogP hrf::Model::GetConditionalProbForH ( VecShell< HValue > &  hi,
VecShell< Prob > &  probs 
)

[sample] using the logprobs returned by ProposeHProb to calculate the logprob of hi.

Definition at line 951 of file hrf-model.cpp.

§ GetEncodeHiddenLimit()

int hrf::Model::GetEncodeHiddenLimit ( ) const

The encoded integer size.

Definition at line 1166 of file hrf-model.cpp.

§ GetEncodeLayerLimit()

int hrf::Model::GetEncodeLayerLimit ( ) const

The encoded integer size of one layer.

Definition at line 1181 of file hrf-model.cpp.

§ GetEncodeNodeLimit()

int hrf::Model::GetEncodeNodeLimit ( ) const

The encoded integer size.

Definition at line 1139 of file hrf-model.cpp.

§ GetHiddenExp()

void hrf::Model::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.

< length

< max-order

Definition at line 622 of file hrf-model.cpp.

§ GetHiddenOrder()

int hrf::Model::GetHiddenOrder ( ) const
inline

Get HH mat order.

Definition at line 128 of file hrf-model.h.

§ GetHnode()

int hrf::Model::GetHnode ( ) const
inline

get hidden node dimension

Definition at line 126 of file hrf-model.h.

§ GetLayerExp()

void hrf::Model::GetLayerExp ( AlgLayer fb,
int  nLayer,
Mat3dShell< double > &  VHexp,
Mat3dShell< double > &  CHexp,
Mat3dShell< double > &  HHexp,
MatShell< double > &  Bexp,
LogP  logz = 0 
)

[exact] called in GetHiddenExp.

Definition at line 650 of file hrf-model.cpp.

§ GetLogProb() [1/2]

LogP hrf::Model::GetLogProb ( Seq seq,
bool  bNorm = true 
)

calculate the probability

Definition at line 112 of file hrf-model.cpp.

§ GetLogProb() [2/2]

LogP hrf::Model::GetLogProb ( VecShell< VocabID > &  x,
bool  bNorm = true 
)

[exact] calculate the probability of x

Add all the ngram features

Definition at line 277 of file hrf-model.cpp.

§ GetLogProb_AIS()

LogP hrf::Model::GetLogProb_AIS ( VecShell< VocabID > &  x,
int  nChain = 10,
int  nIntermediate = 10000 
)

perform AIS to esitmate the mariginal probabilities

Definition at line 1342 of file hrf-model.cpp.

§ GetLogProb_Gibbs()

LogP hrf::Model::GetLogProb_Gibbs ( VecShell< VocabID > &  x,
int  num = 100 
)

sample the best hidden and calculate the joint probability.

Definition at line 1470 of file hrf-model.cpp.

§ GetMarginalLogProb()

LogP hrf::Model::GetMarginalLogProb ( int  nLen,
int  nPos,
Seq sub,
bool  bNorm = true 
)

[exact] Exactly calculate the marginal probability at position 'nPos' and with order 'nOrder'

Definition at line 453 of file hrf-model.cpp.

§ GetMarginalProbOfC()

LogP hrf::Model::GetMarginalProbOfC ( Seq seq,
int  nPos 
)

[sample] Fixed h, given c_i, summate the probabilities of x_i, i.e. P(c_i)

Definition at line 961 of file hrf-model.cpp.

§ GetNodeExp() [1/3]

void hrf::Model::GetNodeExp ( double *  pExp,
Prob pLenProb = NULL 
)

[exact] sum_l { n_l/n * E_{p_l}[f] }: Exactly calculate the expectation over x and h

< max-order

Definition at line 470 of file hrf-model.cpp.

§ GetNodeExp() [2/3]

void hrf::Model::GetNodeExp ( int  nLen,
double *  pExp 
)

[exact] E_{p_l}[f]: Exactly calculate the expectation over x and h for length nLen

Definition at line 499 of file hrf-model.cpp.

§ GetNodeExp() [3/3]

void hrf::Model::GetNodeExp ( int  nLen,
VecShell< double >  featexp,
Mat3dShell< double >  VHexp,
Mat3dShell< double >  CHexp,
Mat3dShell< double >  HHexp,
MatShell< double >  Bexp 
)

[exact] E_{p_l}[f]: Exactly calculate the expectation over x and h for length nLen

decoder to x and h

Definition at line 507 of file hrf-model.cpp.

§ GetParam()

void hrf::Model::GetParam ( PValue pParam)

Get the paremetre vector.

Definition at line 95 of file hrf-model.cpp.

§ GetParamNum()

int hrf::Model::GetParamNum ( ) const
inline

Get the total parameter number.

Definition at line 130 of file hrf-model.h.

§ GetReducedModelForC()

LogP hrf::Model::GetReducedModelForC ( Seq seq,
int  nPos 
)

[sample] A unnormalized reduced model to sample class c_i, consindering CH matrix(U) and class-ngram (lambda_c)

Definition at line 927 of file hrf-model.cpp.

§ GetReducedModelForH()

LogP hrf::Model::GetReducedModelForH ( Seq seq,
int  nPos 
)

[sample] A unnormalized reduced model. It only consindering the HH matrix (W)

Definition at line 913 of file hrf-model.cpp.

§ GetReducedModelForW()

LogP hrf::Model::GetReducedModelForW ( Seq seq,
int  nPos 
)

[sample] A unnormalized reduced model to sample word w_i, consindering VH matrix(M) and word-ngram (lambda_w)

Definition at line 941 of file hrf-model.cpp.

§ HiddenClusterSum()

LogP hrf::Model::HiddenClusterSum ( Seq seq,
int  nPos,
int  nOrder 
)

[exact] Calculate the logp in each cluster. Only consinder the VH,CH,HH values, used in class AlgHidden

Definition at line 306 of file hrf-model.cpp.

§ HiddenFeatCount()

void hrf::Model::HiddenFeatCount ( Seq seq,
Mat3dShell< double >  VHcount,
Mat3dShell< double >  CHcount,
Mat3dShell< double >  HHcount,
MatShell< double >  Bcount,
double  dadd = 1 
)

Count the hidden features.

Definition at line 1194 of file hrf-model.cpp.

§ LayerClusterSum()

LogP hrf::Model::LayerClusterSum ( Seq seq,
int  nlayer,
int  nPos,
int  nOrder 
)

[exact] Calculate the logp in each cluster. Only consinder the VH,CH,HH values on such layer

Definition at line 355 of file hrf-model.cpp.

§ LocalJump()

void hrf::Model::LocalJump ( Seq seq)

[sample] Local Jump - sample a new length

Definition at line 730 of file hrf-model.cpp.

§ MarkovMove()

void hrf::Model::MarkovMove ( Seq seq)

[sample] Markov Move - perform the gibbs sampling

Definition at line 777 of file hrf-model.cpp.

§ PerformSAMS()

void hrf::Model::PerformSAMS ( int  nMinibatch,
int  tmax,
int  t0,
int  beta,
double  zgap = 10 
)

perform the SAMS to estimate the normalization constants zeta

< the length count of sample of each thread

Definition at line 1288 of file hrf-model.cpp.

§ ProposeC0()

LogP hrf::Model::ProposeC0 ( VocabID ci,
Seq seq,
int  nPos,
bool  bSample 
)

[sample] Propose the c_{i} at position i. Then return the propose probability R(c_i|h_i,c_{other})

Definition at line 824 of file hrf-model.cpp.

§ ProposeCProbs()

void hrf::Model::ProposeCProbs ( VecShell< LogP > &  logps,
Seq seq,
int  nPos 
)

[sample] Return the distribution of c_i at position nPos

Definition at line 903 of file hrf-model.cpp.

§ ProposeH0()

LogP hrf::Model::ProposeH0 ( VecShell< HValue > &  hi,
Seq seq,
int  nPos,
bool  bSample 
)

[sample] Propose the h_{i} at position i. Then return the propose probability Q(h_i|h_{other})

Definition at line 796 of file hrf-model.cpp.

§ ProposeHProbs()

void hrf::Model::ProposeHProbs ( VecShell< LogP > &  logps,
Seq seq,
int  nPos,
bool  bConsiderXandC = false 
)

[sample] A reduced model only consinder HHmat(W) and VHmat(M) and CHmat(U).

save the logp of 0 or 1 for each hidden vairables

Definition at line 841 of file hrf-model.cpp.

§ ProposeLength()

LogP hrf::Model::ProposeLength ( int  nOld,
int &  nNew,
bool  bSample 
)

[sample] Propose the length, using the variable m_matLenJump

Definition at line 788 of file hrf-model.cpp.

§ RandHidden()

void hrf::Model::RandHidden ( Seq seq)

Random init the hidden variables.

Definition at line 1101 of file hrf-model.cpp.

§ RandSeq()

void hrf::Model::RandSeq ( Seq seq,
int  nLen = -1 
)

Random init sequence, if nLen==-1, random the length also.

Definition at line 1083 of file hrf-model.cpp.

§ ReadT()

void hrf::Model::ReadT ( const char *  pfilename)

Read Model.

Definition at line 149 of file hrf-model.cpp.

§ Reset()

void hrf::Model::Reset ( Vocab pv,
int  hlayer,
int  hnode,
int  maxlen 
)

reset, the maxlen is the length excluding the beg/end symbols.

Definition at line 65 of file hrf-model.cpp.

§ Sample()

void hrf::Model::Sample ( Seq seq)

[sample] Perform one train-dimensional mixture sampling

Definition at line 725 of file hrf-model.cpp.

§ SampleC()

void hrf::Model::SampleC ( Seq seq,
int  nPos 
)

[sample] Sample the c_i at position nPos given h_i without x_i.

Definition at line 979 of file hrf-model.cpp.

§ SampleHAndCGivenX()

LogP hrf::Model::SampleHAndCGivenX ( Seq seq,
MatShell< HValue > *  tagH = NULL 
)
virtual

[sample] sample h given x using gibbs sampling.

Definition at line 1053 of file hrf-model.cpp.

§ SampleW()

LogP hrf::Model::SampleW ( Seq seq,
int  nPos,
bool  bSample = true 
)

[sample] Sample the w_i at position nPos

Definition at line 1012 of file hrf-model.cpp.

§ SetParam()

void hrf::Model::SetParam ( PValue pParam)
virtual

Set the parameters.

Reimplemented from trf::Model.

Definition at line 78 of file hrf-model.cpp.

§ SumHHWeight() [1/2]

PValue hrf::Model::SumHHWeight ( Mat3dShell< PValue m,
VecShell< HValue h1,
VecShell< HValue h2 
)

Definition at line 1251 of file hrf-model.cpp.

§ SumHHWeight() [2/2]

PValue hrf::Model::SumHHWeight ( Mat3dShell< PValue m,
VecShell< HValue h1,
VecShell< HValue h2,
int  layer 
)

Definition at line 1273 of file hrf-model.cpp.

§ SumVHWeight() [1/2]

PValue hrf::Model::SumVHWeight ( MatShell< PValue m,
VecShell< HValue h 
)

Definition at line 1243 of file hrf-model.cpp.

§ SumVHWeight() [2/2]

PValue hrf::Model::SumVHWeight ( MatShell< PValue m,
VecShell< HValue h,
int  layer 
)

Definition at line 1265 of file hrf-model.cpp.

§ WriteT()

void hrf::Model::WriteT ( const char *  pfilename)

Write Model.

Definition at line 233 of file hrf-model.cpp.

Member Data Documentation

§ m_hlayer

int hrf::Model::m_hlayer

the number of hidden layer

Definition at line 101 of file hrf-model.h.

§ m_hnode

int hrf::Model::m_hnode

the number of hidden nodes

Definition at line 102 of file hrf-model.h.

§ m_m3dCH

Mat3d<PValue> hrf::Model::m_m3dCH

the weight between Class(C) and Hidden(H)

Definition at line 104 of file hrf-model.h.

§ m_m3dHH

Mat3d<PValue> hrf::Model::m_m3dHH

the weight between adjacent Hidden(H)

Definition at line 105 of file hrf-model.h.

§ m_m3dVH

Mat3d<PValue> hrf::Model::m_m3dVH

the weight between Word(V) and Hidden(H)

Definition at line 103 of file hrf-model.h.

§ m_matBias

Mat<PValue> hrf::Model::m_matBias

the bias for each value of Hidden(H)

Definition at line 106 of file hrf-model.h.

§ m_nLenJumpAccTimes

int hrf::Model::m_nLenJumpAccTimes

lenght jump the acceptance times

Definition at line 179 of file hrf-model.h.

§ m_nLenJumpTotalTime

int hrf::Model::m_nLenJumpTotalTime

total times of length jump

Definition at line 180 of file hrf-model.h.

§ m_nodeCal

AlgNode hrf::Model::m_nodeCal
protected

the forward-backward calculation for node (x and h)

Definition at line 109 of file hrf-model.h.

§ m_nSampleHAccTimes

int hrf::Model::m_nSampleHAccTimes

sample H the acceptance times

Definition at line 177 of file hrf-model.h.

§ m_nSampleHTotalTimes

int hrf::Model::m_nSampleHTotalTimes

sample H the total times

Definition at line 178 of file hrf-model.h.


The documentation for this class was generated from the following files: