hiroishida / arhmm.jl Goto Github PK
View Code? Open in Web Editor NEWTraining auto-regressive HMM by EM-algorithm with forward-backward algorithm
Training auto-regressive HMM by EM-algorithm with forward-backward algorithm
if set det(A) > 1, hmm training fails with a lot of NANs ...
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];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.