Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Question on forward-backward algorithm in CRF++ #30

Open
hqzizania opened this issue Apr 19, 2016 · 10 comments
Open

A Question on forward-backward algorithm in CRF++ #30

hqzizania opened this issue Apr 19, 2016 · 10 comments

Comments

@hqzizania
Copy link

hqzizania commented Apr 19, 2016

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

@garfieldnate
Copy link

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?

@hqzizania
Copy link
Author

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()));
  }
}

@garfieldnate
Copy link

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.

@hqzizania
Copy link
Author

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

@dontloo
Copy link

dontloo commented Oct 17, 2016

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

@hqzizania
Copy link
Author

Now I see, Dontloo, thank you so much!

@dontloo
Copy link

dontloo commented Oct 17, 2016

You are welcome :)

@hqzizania
Copy link
Author

@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.

@chaoswork
Copy link

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

@chaoswork
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants