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

2 state and 3 observation HMM #12

Closed
GuilhermePFM opened this issue Dec 5, 2019 · 3 comments
Closed

2 state and 3 observation HMM #12

GuilhermePFM opened this issue Dec 5, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@GuilhermePFM
Copy link

GuilhermePFM commented Dec 5, 2019

Hello,

Thank you for this very nice package. I am just learning HMM and I would like to know if is it possible to estimate a HMM with 2 hidden states for 3 observations like this:

hmm = HMM([0.9 0.1; 0.1 0.9], [MvNormal(ones(3)), MvNormal(ones(3))])
nstates, obs_dim = size(hmm)
y = rand(hmm, 1000) 

I tried it but it gives an error of dimension mismatch:

ERROR: DimensionMismatch("tried to assign 3-element array to 1×2 destination")

Am I doing something wrong here?

@GuilhermePFM
Copy link
Author

GuilhermePFM commented Dec 5, 2019

I think it just needs to change this function:

function rand(rng::AbstractRNG, hmm::AbstractHMM{Multivariate}, z::AbstractVector{<:Integer})
    y = Matrix{Float64}(undef, length(z), size(hmm, 1))
    for t in eachindex(
        y[t,:] = rand(rng, hmm.B[z[t]])
    end
    y
end

to y = Matrix{Float64}(undef, length(z), size(hmm, 2))

I tested here and it seems to be working. If that is ok with you I can open a PR with the fix and also add a new test for that.

@maxmouchet
Copy link
Owner

Hi Guilherme,

You're right, thanks for reporting this bug!
Feel free to make a PR if you have the time :)

You can add a test in unit.jl: https://github.com/maxmouchet/HMMBase.jl/blob/master/test/unit.jl#L48-L76
Maybe you can add a third hmm (hmm3) which has a different number of states and observations, with a comment that links to this issue.

@maxmouchet maxmouchet added the bug Something isn't working label Dec 5, 2019
@GuilhermePFM
Copy link
Author

Ok! Will do this right now, thank you

GuilhermePFM pushed a commit to GuilhermePFM/HMMBase.jl that referenced this issue Dec 6, 2019
@GuilhermePFM GuilhermePFM mentioned this issue Dec 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants