Skip to content

Cython alternative to #1825 #1828

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

Closed
wants to merge 3 commits into from
Closed

Conversation

kmike
Copy link
Contributor

@kmike kmike commented Apr 2, 2013

Here .fit and .eval should be about 10-20% faster than #1825 on large HMMs and several times faster on tiny HMMs. _decode_viterbi should be on par with #1825.

_logsum is not moved to _extmath in this pull request.

For the record: I slightly prefer #1825 because of simplicity, but if there are use cases for HMMs with small number of parameters but slow training, this PR should be preferred.

@amueller
Copy link
Member

amueller commented Apr 2, 2013

Thanks for giving it a shot :) I didn't go through the code in any detail so I can't judge the overhead of maintaining the cython version. @larsmans any opinion?

@larsmans
Copy link
Member

larsmans commented Apr 2, 2013

LGTM! I didn't try a cython -a on this, any yellow lines remaining?.

@kmike
Copy link
Contributor Author

kmike commented Apr 2, 2013

Yes, there are yellow lines: https://gist.github.com/kmike/bf9b3ef041427068fcc4

Some of them are function starts & ends (because they are Python functions); _viterbi has a lot of Python calls (it is just a vectorized version from #1825); work_buffer allocations are also Python.

@larsmans
Copy link
Member

larsmans commented Apr 2, 2013

Fair enough, +1 for merge.

@kmike
Copy link
Contributor Author

kmike commented Apr 2, 2013

I ran more tests, and Cython extension provides a nice speed gain (> 1.5x compared to numpy+python) for 20-state HMM.fit(); I'm leaning towards this PR now.

@amueller
Copy link
Member

amueller commented Apr 2, 2013

great if you are happy with it :)
it is probably easier to optimize it further if needed. (will try to review soon if no-one else does).

@larsmans
Copy link
Member

Even the tests are significantly faster. Merged as 919951a.

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

Successfully merging this pull request may close these issues.

3 participants