Code Monkey home page Code Monkey logo

arhmm.jl's People

Contributors

hiroishida avatar kanazawanaoaki avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kanazawanaoaki

arhmm.jl's Issues

Update of stochastic matrix is strange

even though index is not reversed...

julia> mp.A
2×2 MMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
 1.0  0.00100141
 0.0  0.998999

Setting :

using Revise
using Random
using LinearAlgebra
using ARHMM

using StaticArrays
using Distributions

function data_generation(n, A, prop_list)
    x = SVector{1, Float64}([0.0])
    z = 1
    xs = [x]
    zs = [z]
    for i in 1:n
        cat = Categorical(A[:, z])
        z_next = rand(cat)
        x_next = prop_list[z](x)
        x, z = x_next, z_next
        push!(xs, SVector{1, Float64}(x))
        push!(zs, z)
    end
    return xs, zs
end

Random.seed!(0)
prop1 = LinearPropagator(Diagonal([1.0]), Diagonal([0.1^2]), [0.4])
prop2 = LinearPropagator(Diagonal([1.0]), Diagonal([0.1^2]), [-0.4])
prop_list = [prop1, prop2]
A = [0.6 0.0;
     0.4 1.0]

xs, zs = data_generation(1000, A, prop_list)
A_pred_init = [0.9 0.0;
               0.1 1.0]
prop1_init = LinearPropagator(Diagonal([1.0]), Diagonal([0.5^2]), [0.2])
prop2_init = LinearPropagator(Diagonal([1.0]), Diagonal([0.3^2]), [-0.5])
prop_list_init = [prop1_init, prop2_init]
mp = ModelParameters(1, A_pred_init, prop_list_init)

z_ests = nothing
for _ in 1:1 # if more than 2, usually likelihood will be static
    global z_ests
    z_ests, zz_ests, log_likeli = compute_hidden_states(mp, xs)
    update_model_parameters!(mp, z_ests, zz_ests, xs)
end
z_preds = [argmax(z) for z in z_ests];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.