Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Em Algorithm Speedup #9

Open
paschermayr opened this issue Jul 11, 2019 · 3 comments
Open

Em Algorithm Speedup #9

paschermayr opened this issue Jul 11, 2019 · 3 comments

Comments

@paschermayr
Copy link

paschermayr commented Jul 11, 2019

Hi guys,

In your mle.jl file, on line 14 in the mle_step function, you have:

log_likelihoods = HMMBase.log_likelihoods(hmm, observations)

If you define the loglikelihoods function for both, univariate and multivariate, with a fixed type like:

function log_likelihoods(hmm::AbstractHMM{Univariate}, observations)::Array{Float64,2} 
    hcat(map(d -> logpdf.(d, observations), hmm.D)...)
end

you should archieve a drastic speed up. I had a similar problem and it did the trick. I am no expert, but I think the 'log_likelihoods' functions within the 'mle' function is not type stable.

Also, I have to say that your module is really well structured and intuitively written!

@maxmouchet
Copy link
Owner

Hi,

Thanks for the suggestion :-)

It does not seems to make a difference at a first glance (see the screenshot) but you're right that there is some Any types inside the function.

I'll look more into details.

Screenshot from 2019-07-18 11-56-01

@maxmouchet
Copy link
Owner

maxmouchet commented Jul 18, 2019

I don't know if we can do better in terms of time (2x17us ~= 35us), however we may be able to use slightly less memory (~40KiB instead of 79KiB):

@btime logpdf.(hmm.D[1], obs);
17.398 μs (5 allocations: 19.72 KiB)

@paschermayr
Copy link
Author

Thanks for your answer!

I used the log_likelihood function in another function and the compiler wasn't able to correctly guess the output - so I thought you might get some speed up when you are using your function in the MLE part of your module.

On a related note, I saw the graph where you guys benchmarked your package with hmmlearn - why this drastic time increase for the likelihood calculation? This should be already be a part in the forward pass.

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

No branches or pull requests

2 participants