crfpp icon indicating copy to clipboard operation
crfpp copied to clipboard

A Question on forward-backward algorithm in CRF++

Open hqzizania opened this issue 9 years ago • 10 comments
trafficstars

I’m a beginner of CRF++. A question have plagued me for many days. I’m exhausted~

In void Node::calcBeta() {

Why the code is so like calcAlpha()

You know they two are very different in original forward-backward algorithm of HMM.

@garfieldnate

hqzizania avatar Apr 19 '16 02:04 hqzizania

Sorry, I'm not a core contributor and I don't have any special knowledge of the code or its algorithms. The only difference I see between those two methods is the use of rpath/rnode vs. lpath/lnode. I assume lpath goes backward and rpath goes forward, giving you your forward-backward algorithm. Can you give any details from the paper about what's different here?

garfieldnate avatar Apr 19 '16 06:04 garfieldnate

Thanks for your reply. alpha beta

The calcAlpha is consistent with the formula but the calcbeta() code should be:

void Node::calcBeta() {
  beta = 0.0;
  for (const_Path_iterator it = rpath.begin(); it != rpath.end(); ++it) {
    beta = logsumexp(beta,
                     (*it)->cost +(*it)->rnode->beta + (*it)->rnode->cost,
                     (it == rpath.begin()));
  }
}

hqzizania avatar Apr 19 '16 07:04 hqzizania

I have no idea. I haven't read the paper. My two suggestions would be to 1) try changing the code and seeing if it still works, and 2) ask this question on stats.stackexchange.com/ and attach the [conditional-random-field] tag.

garfieldnate avatar Apr 22 '16 07:04 garfieldnate

I changed the code as my understanding but its results are wrong. So I think its implementation is right definitely. I just wonder why it is different from the paper, or if there is another paper for the details.

Anyway, Thanks so much~ I will try to ask it on stats.stackexchange.com

hqzizania avatar Apr 22 '16 07:04 hqzizania

Hi I've posted an answer to your question here http://stats.stackexchange.com/a/240610/95569 , hope it's not too late :)

dontloo avatar Oct 17 '16 03:10 dontloo

Now I see, Dontloo, thank you so much!

hqzizania avatar Oct 17 '16 04:10 hqzizania

You are welcome :)

dontloo avatar Oct 17 '16 06:10 dontloo

@Dontloo Since the beta is actually beta', and it should subtract the cost in calcExpectation. But one more question I have is why it does not subtract the cost in calcExpectation as the beta is also beta' in that place.

hqzizania avatar Oct 17 '16 06:10 hqzizania

Z is also using Beta', so Z is larger than the really Z_ ??

chaoswork avatar Mar 14 '17 12:03 chaoswork

@hqzizania that's because c = std::exp(lnode->alpha + path.cost + rnode->cost + rnode->beta -rnode->cost - Z) path->cost means the transfer possibility. rnode->cost means the states possibility.

chaoswork avatar Mar 14 '17 13:03 chaoswork