{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "推移確率行列を定義する." ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.3" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p_mat[3,1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 状態遷移図\n", "\n", "参照: https://mathtrain.jp/markovchain" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3×3 Array{Float64,2}:\n", " 0.7 0.3 0.0\n", " 0.4 0.4 0.2\n", " 0.3 0.3 0.4" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 一般的な(行,列)によるしていにするためにreshape -> transposeを行う.\n", "p_mat = transpose(reshape(Float64[[0.7 0.3 0] [0.4 0.4 0.2] [0.3 0.3 0.4]],3,3))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "状態空間の定義" ] }, { "cell_type": "code", "execution_count": 176, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 176, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s =[\"晴れ\",\"曇り\",\"雨\"]\n", "initial_state = 1\n", "state = 1" ] }, { "cell_type": "code", "execution_count": 96, "metadata": {}, "outputs": [], "source": [ "using Match" ] }, { "cell_type": "code", "execution_count": 174, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "marcov_chain (generic function with 2 methods)" ] }, "execution_count": 174, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function markovchain_rule(p_mat)\n", " p = rand(0.1:0.1:1.0)\n", " if p >= 0.7\n", " initial_state\n", " end\n", "end\n", " \n", "function sunny()\n", " if p >= p_mat[1,1]\n", " state = s[1]\n", " elseif p >= 0.0 && p <= p_mat[1,2]\n", " state[2]\n", " end \n", "end\n", "\n", "function cloudy()\n", " if p >= \n", "end\n", " " ] }, { "cell_type": "code", "execution_count": 177, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "markovchain2 (generic function with 1 method)" ] }, "execution_count": 177, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function markovchain2(p_mat)\n", " @match initial_state begin\n", " 1 => println(s[1]) # 晴れ\n", " 2 => println(s[2]) # 曇り\n", " 3 => println(s[3]) # 雨\n", " end\n", "end" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.4" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p_mat[4]" ] }, { "cell_type": "code", "execution_count": 94, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mCloning cache of Match from https://github.com/kmsquire/Match.jl.git\n", "\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mInstalling Match v0.4.0\n", "\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPackage database updated\n", "\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mMETADATA is out-of-date — you may not have the latest version of Match\n", "\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mUse `Pkg.update()` to get the latest versions of your packages\n", "\u001b[39m" ] } ], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.6.3", "language": "julia", "name": "julia-0.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }