24 for (
int i = 0; i <
m_aAlpha.GetNum(); i++)
26 for (
int i = 0; i <
m_aBeta.GetNum(); i++)
37 for (
int i = 0; i <
m_aAlpha.GetNum(); i++)
39 for (
int i = 0; i <
m_aBeta.GetNum(); i++)
42 int nClusterNum = nLen - nOrder + 1;
49 for (
int i = 0; i < nClusterNum; i++) {
56 Prepare(nLen, nOrder, nValueLimit);
57 int nClusterNum = nLen - nOrder + 1;
66 for (
int i = 1; i < nClusterNum; i++) {
71 for (nodeSeq[i - 1] = 0; nodeSeq[i - 1] <
m_nValueLimit; nodeSeq[i - 1]++) {
74 dLogSum =
Log_Sum(dLogSum, temp);
82 m_aBeta[nClusterNum - 1]->Fill(0);
83 for (
int i = nClusterNum - 2; i >= 0; i--) {
90 +
m_aBeta[i + 1]->Get(nodeSeq.
GetBuf() + i + 2, m_nOrder - 1);
91 dLogSum =
Log_Sum(dLogSum, temp);
94 m_aBeta[i]->Get(nodeSeq.
GetBuf() + i + 1, m_nOrder - 1) = dLogSum;
103 if (nPos + nSubLen >
m_nLen) {
104 lout_error(
"[Model] GetMarginalLogProb: nPos(" << nPos <<
")+nOrder(" << nSubLen <<
") > seq.len(" <<
m_nLen <<
")!!");
115 while (iter.Next()) {
132 while (iter.Next()) {
142 while (iter.Next()) {
147 +
m_aBeta[nCluster]->Get(nseq.
GetBuf() + nCluster + 1, m_nOrder - 1));
164 while (iter.Next()) {
175 logSum =
Log_Sum(logSum, temp);
190 int totalsize = pow(m_size, m_dim);
191 m_pbuf =
new float[totalsize];
201 int totalsize = pow(m_size, m_dim);
202 for (
int i = 0; i < totalsize; i++) {
212 m_pbuf =
new float[GetBufSize()];
215 memcpy(m_pbuf, m.m_pbuf,
sizeof(m_pbuf[0]) * GetBufSize());
221 int nIndex = pIdx[0];
222 for (
int i = 0; i < nDim - 1; i++)
224 nIndex = nIndex * m_size + pIdx[i + 1];
226 return m_pbuf[nIndex];
244 for (
int i = 0; i < m_nDim; i++)
251 for (
int i = 0; i < m_nDim - 1; i++) {
252 if (m_pBuf[i] > m_nMax) {
261 return m_pBuf[m_nDim - 1] <= m_nMax;
#define SAFE_DELETE(p)
memory release
int m_nLen
the sequence length.
Msg(int nMsgDim, int nSize)
LogP Log_Sum(LogP x, LogP y)
VecShell< T > GetSub(int nPos, int nLen)
void Prepare(int nLen, int nOrder, int nValueLimit)
prepare
int m_nValueLimit
the max-value at each position
int m_nOrder
the order, i.e. the node number at each cluster {x_1,x_2,...,x_n}
virtual LogP ClusterSum(int *pSeq, int nLen, int nPos, int nOrder)=0
This function need be derived. Calcualte the log probability of each cluster.
Array< Msg * > m_aAlpha
the forward message
#define SAFE_DELETE_ARRAY(p)
LogP GetLogSummation()
Get the summation over the sequence, corresponding to the log normalization constants 'logZ'...
float & Get(int *pIdx, int nDim)
void ForwardBackward(int nLen, int nOrder, int nValueLimit)
forward-backward calculation
VecIter(int *p, int nDim, int nMin, int nMax)
LogP GetMarginalLogProb(int nPos, int *pSubSeq, int nSubLen, double logz=0)
Get the marginal probability. 'logz' is the input of the log normalization constants.
Array< Msg * > m_aBeta
the backward message