推移確率行列を定義する.
p_mat[3,1]
0.3
# 一般的な(行,列)によるしていにするためにreshape -> transposeを行う.
p_mat = transpose(reshape(Float64[[0.7 0.3 0] [0.4 0.4 0.2] [0.3 0.3 0.4]],3,3))
3×3 Array{Float64,2}: 0.7 0.3 0.0 0.4 0.4 0.2 0.3 0.3 0.4
状態空間の定義
s =["晴れ","曇り","雨"]
initial_state = 1
state = 1
1
using Match
function markovchain_rule(p_mat)
p = rand(0.1:0.1:1.0)
if p >= 0.7
initial_state
end
end
function sunny()
if p >= p_mat[1,1]
state = s[1]
elseif p >= 0.0 && p <= p_mat[1,2]
state[2]
end
end
function cloudy()
if p >=
end
marcov_chain (generic function with 2 methods)
function markovchain2(p_mat)
@match initial_state begin
1 => println(s[1]) # 晴れ
2 => println(s[2]) # 曇り
3 => println(s[3]) # 雨
end
end
markovchain2 (generic function with 1 method)
p_mat[4]
0.4
INFO: Cloning cache of Match from https://github.com/kmsquire/Match.jl.git INFO: Installing Match v0.4.0 INFO: Package database updated INFO: METADATA is out-of-date — you may not have the latest version of Match INFO: Use `Pkg.update()` to get the latest versions of your packages