2020-12-11 21:33:20 +00:00
{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2021-01-05 11:10:29 +00:00
"version": "3.8.6-final"
2020-12-11 21:33:20 +00:00
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"cell_type": "code",
2021-01-05 11:10:29 +00:00
"execution_count": 1,
2020-12-11 21:33:20 +00:00
"metadata": {},
"outputs": [],
"source": [
2020-12-31 19:30:39 +00:00
"#IMPORTS AND COMMON VARIABLES\n",
2021-01-01 18:53:11 +00:00
"import matplotlib\n",
"import matplotlib.cm as cm\n",
2020-12-11 21:33:20 +00:00
"import matplotlib.pyplot as plt\n",
2021-01-01 18:53:11 +00:00
"from matplotlib.pyplot import savefig\n",
2020-12-11 21:33:20 +00:00
"import numpy as np\n",
2020-12-31 19:30:39 +00:00
"from math import sqrt\n",
2020-12-11 21:33:20 +00:00
"\n",
"from constants import *\n",
"from maths import gaussian\n",
2020-12-31 19:30:39 +00:00
"from markov import MarkovModel\n",
"from markovlog import LogMarkovModel\n",
"\n",
2021-01-01 18:53:11 +00:00
"fig_dpi = 200\n",
"fig_export = False\n",
"\n",
"x = np.linspace(-4, 8, 300) # x values for figures\n",
2020-12-31 19:30:39 +00:00
"x_label = \"Observation Space\"\n",
"y_label = \"Probability Density\""
2020-12-11 21:33:20 +00:00
]
},
{
"source": [
"State Probability Functions (1)\n",
"==================="
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2020-12-23 20:12:08 +00:00
"execution_count": 2,
2020-12-11 21:33:20 +00:00
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
2021-01-01 18:53:11 +00:00
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"280.8pt\" version=\"1.1\" viewBox=\"0 0 424.8 280.8\" width=\"424.8pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:50:57.931783</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 280.8 \nL 424.8 280.8 \nL 424.8 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.78125 243.24375 \nL 417.6 243.24375 \nL 417.6 22.318125 \nL 43.78125 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#p69d96452c6)\" d=\"M 60.773011 243.24375 \nL 60.773011 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"mf0f9a69005\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"60.773011\" xlink:href=\"#mf0f9a69005\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- − 4 -->\n <g transform=\"translate(53.401918 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 10.59375 35.5 \nL 73.1875 35.5 \nL 73.1875 27.203125 \nL 10.59375 27.203125 \nz\n\" id=\"DejaVuSans-8722\"/>\n <path d=\"M 37.796875 64.3125 \nL 12.890625 25.390625 \nL 37.796875 25.390625 \nz\nM 35.203125 72.90625 \nL 47.609375 72.90625 \nL 47.609375 25.390625 \nL 58.015625 25.390625 \nL 58.015625 17.1875 \nL 47.609375 17.1875 \nL 47.609375 0 \nL 37.796875 0 \nL 37.796875 17.1875 \nL 4.890625 17.1875 \nL 4.890625 26.703125 \nz\n\" id=\"DejaVuSans-52\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-8722\"/>\n <use x=\"83.789062\" xlink:href=\"#DejaVuSans-52\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#p69d96452c6)\" d=\"M 117.412216 243.24375 \nL 117.412216 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"117.412216\" xlink:href=\"#mf0f9a69005\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- − 2 -->\n <g transform=\"translate(110.041122 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20
2021-01-01 18:53:11 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJsAAAMMCAYAAAD0M6ZoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdd5hU5dnH8e+9hV26gIjCriDFAtaIBSKCMYJGRZPX2KIGS2JM87UlJqboG40l0RiTGE1UMCb2qBE1ERvFhmDBUERAQZYmvS7Lluf948zszszOzM7uzpwz5fe5rrl2zpkz59wz556ZnXueYs45RERERERERERE0qEo6ABERERERERERCR/qNgkIiIiIiIiIiJpo2KTiIiIiIiIiIikjYpNIiIiIiIiIiKSNio2iYiIiIiIiIhI2qjYJCIiIiIiIiIiaaNik4iIiIiIiIiIpI2KTSIiIiIiIiIikjYqNomIiIiIiIiISNqo2CQiIiIiIiIiImmjYpOIiIiIiIiIiKSNik0iIiIiIiIiIpI2KjaJiIiIiIiIiEjaqNgkIiIiIiIiIiJpo2KTiIiIiIiIiIikjYpNIiIiIiIiIiKSNio2iYiIiIiIiIhI2qjYJCIiIiIiIiIiaaNik4iIiIiIiIiIpI2KTSI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8/xpJYeUyv3MSGF7VN5HiO3CT/eF4j53MQrRP0mYtsGYECSYz8asW0dXuGlc5ztivA+u5+Jl6e0opVSa+6D96NAXczrqU/MNmXAbTGvkytTyMea0POzGDgyzrZfJ/rz4YIE+3w/Yps/kKBVK94PJl8HbmlPjuq
2020-12-11 21:33:20 +00:00
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"state_1_y = [gaussian(i, state1.mean, state1.std_dev) for i in x]\n",
"state_2_y = [gaussian(i, state2.mean, state2.std_dev) for i in x]\n",
"\n",
"plt.plot(x, state_1_y, c='r', label=\"State 1\")\n",
"plt.plot(x, state_2_y, c='b', label=\"State 2\")\n",
"\n",
"plt.legend()\n",
"plt.title(\"State Probability Density Functions\")\n",
"\n",
2020-12-31 19:30:39 +00:00
"plt.xlabel(x_label)\n",
"plt.ylabel(y_label)\n",
2020-12-11 21:33:20 +00:00
"plt.grid(linestyle=\"--\")\n",
"\n",
2021-01-01 18:53:11 +00:00
"fig = matplotlib.pyplot.gcf()\n",
"fig.set_dpi(fig_dpi)\n",
"fig.set_tight_layout(True)\n",
"if fig_export:\n",
" savefig(\"report/res/pdfs.png\")\n",
2020-12-11 21:33:20 +00:00
"plt.show()"
]
},
{
"source": [
"Output Probability Densities (2)\n",
"=========="
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2020-12-23 20:12:08 +00:00
"execution_count": 3,
2020-12-11 21:33:20 +00:00
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
2021-01-03 21:14:25 +00:00
"3.8 -> State 1: 0.02185157424475792, State 2: 0.5471239427774459\n4.2 -> State 1: 0.009496655019831194, State 2: 0.5471239427774459\n3.4 -> State 1: 0.04499247209432338, State 2: 0.3947074079064296\n-0.4 -> State 1: 0.16833223796171576, State 2: 1.500652790137751e-09\n1.9 -> State 1: 0.2509478601290037, State 2: 0.006331212017054291\n3.0 -> State 1: 0.08289761566062391, State 2: 0.2054255182126689\n1.6 -> State 1: 0.2933877723035829, State 2: 0.001596702666402633\n1.9 -> State 1: 0.2509478601290037, State 2: 0.006331212017054291\n5.0 -> State 1: 0.0012852324969092556, State 2: 0.2054255182126689\n"
2020-12-11 21:33:20 +00:00
]
}
],
"source": [
"for obs in observations:\n",
2021-01-01 18:53:11 +00:00
" print(f'{obs} -> State 1: {gaussian(obs, state1.mean, state1.std_dev)},', \n",
2021-01-03 21:14:25 +00:00
" f'State 2: {gaussian(obs, state2.mean, state2.std_dev)}')"
2020-12-11 21:33:20 +00:00
]
},
{
"cell_type": "code",
2021-01-05 11:10:29 +00:00
"execution_count": 4,
2020-12-11 21:33:20 +00:00
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
2021-01-01 18:53:11 +00:00
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"280.8pt\" version=\"1.1\" viewBox=\"0 0 424.8 280.8\" width=\"424.8pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:50:58.447265</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 280.8 \nL 424.8 280.8 \nL 424.8 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.78125 243.24375 \nL 417.6 243.24375 \nL 417.6 22.318125 \nL 43.78125 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"PathCollection_1\">\n <defs>\n <path d=\"M -4.031129 4.031129 \nL 4.031129 -4.031129 \nM -4.031129 -4.031129 \nL 4.031129 4.031129 \n\" id=\"m2749552464\" style=\"stroke:#800000;stroke-width:1.5;\"/>\n </defs>\n <g clip-path=\"url(#pbf48cc8067)\">\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"281.665909\" xlink:href=\"#m2749552464\" y=\"225.499678\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"292.99375\" xlink:href=\"#m2749552464\" y=\"229.854401\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"270.338068\" xlink:href=\"#m2749552464\" y=\"217.343233\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"162.72358\" xlink:href=\"#m2749552464\" y=\"173.869812\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"227.858665\" xlink:href=\"#m2749552464\" y=\"144.750382\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"259.010227\" xlink:href=\"#m2749552464\" y=\"203.982852\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"219.362784\" xlink:href=\"#m2749552464\" y=\"129.791637\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"227.858665\" xlink:href=\"#m2749552464\" y=\"144.750382\"/>\n <use style=\"fill:#800000;stroke:#800000;stroke-width:1.5;\" x=\"315.649432\" xlink:href=\"#m2749552464\" y=\"232.748672\"/>\n </g>\n </g>\n <g id=\"PathCollection_2\">\n <defs>\n <path d=\"M -4.031129 4.031129 \nL 4.031129 -4.031129 \nM -4.031129 -4.031129 \nL 4.031129 4.031129 \n\" id=\"m829208be9c\" style=\"stroke:#000080;stroke-width:1.5;\"/>\n </defs>\n <g clip-path=\"url(#pbf48cc8067)\">\n <use style=\"fill:#000080;stroke:#000080;stroke-width:1.5;\" x=\"281.665909\" xlink:href=\"#m829208be9c\" y=\"40.357551\"/>\n <use style=\"fill:#000080;stroke:#000080;stroke-width:1.5;\" x=\"292.99375\" xlink:href=\"#m829208be9c\" y=\"40.357551\"/>\n <use style=\"fill:#000080;stroke:#000080;stroke-width:1.5;\" x=\"270.338068\" xlink:href=\"#m829208be9c\" y=\"94.079626\"/>\n <use style=\"fill:#000080;stroke:#000080;stroke-width:1.5;\" x=\"162.72358\" xlink:href=\"#m829208be9c\" y=\"233.201676\"/>\n <use style=\"fill:#000080;stroke:#000080;stroke-width:1.5;\" x=\"227.858665\" xlink:href=\"#m829208be9c\" y=\"230.970121\"/>\n <use style=\"fill:#000080;stroke:#000080;stroke-width:1.5;\" x=\"259.010227\" xlink:href=\"#m829208be9c\" y=\"160.795588\"/>\n <use style=\"fill:#000080;stroke:#000080;stroke-width:1.5;\" x=\"219.362784\" xlink:href=\"#m829208be9c\" y=\"232.638888\"/>\n <use style=\"fill:#000080;stroke:#000080;str
2021-01-01 18:53:11 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJsAAAMMCAYAAAD0M6ZoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdeXxU1f3/8dcnCwkEArKICAiiuCDuqJWKa93qWmutrdpi9au12vpVsZvfWv1Vba1oXerWqri27tq6tK7ghqK4IAJuIBg2FdlDSAg5vz/OTObOZLYkM3OTzPv5eMwjc++ce+65uXfuvfO5ZzHnHCIiIiIiIiIiIrlQEnYBRERERERERESk61CwSUREREREREREckbBJhERERERERERyRkFm0REREREREREJGcUbBIRERERERERkZxRsElERERERERERHJGwSYREREREREREckZBZtERERERERERCRnFGwSEREREREREZGcUbBJRERERERERERyRsEmERERERERERHJGQWbREREREREREQkZxRsEhERERERERGRnFGwSUREREREREREckbBJhERERERERERyRkFm0REREREREREJGcUbBIRERERERERkZxRsElERERERERERHJGwSYREREREREREckZBZtERPLMzPY3Mxd5TQm7PKmY2Z2Bco7PUZ5ZbXsgjUuTZkog3f65KJ90LWY2PnCM3Bl2eaRz0Tmm88rH9SuS7yWBfC/JVb4dTbFsp8TTNVPyTcEmkSQiP5BvMrPpZvaVmTWYWZ2ZfRmZ9w8zO8/MxpiZhV3eriYYeEjy2mhmK8xsjpndY2bHm1lZ2GUWaYsMx/paM1scOdafMbMrzOy7ZlYddrmlcBJ+RLfmNT7sskvXZ2avBY65a7Jc5lcJx+qvslzuL4Fl3mhfyTsvM+ttZidF7kVnRe5T6yPXi3fN7EYz+7bujUQkbAo2iQSY2fZm9jowGTgL2B3oD5QDlcCAyLwfANcAbwEz0+SXlydtrZFtzZJOpAToA2wHnAw8BMw2sz3CLJR0DF3s6WwVMAh/rB8C/AZ4GFhsZreZ2agwC9dZmdnwwDEyP+zySH6ollLBvBx4v2+WyySma8tyL2W5TLPOXovDzMrN7H+BecC9+HvRUfj71G7468UuwM+Ap4APzOyoUAorBdfZj2/pmhTxFokws12BF/GBjKgvgOnAUsAB/YDRwNZAtEZTML3k3uPAosB0KTAQ2Acf/AMYCUw2s32dc+8UtngiOfM48cd6GbAJ/ryzK9A3Mr8KOA042cx+C/zFOZey+aF0KR8CL2SZdk4+CyIS8RLw68j7Xcysl3NuTarEZlYCfDNh9jfNrMQ515RmuWpg58Csl1Ol7Yoi2/84cEDCRzOBj4AV+HujXYGhkc+2Bf5tZhOBX+o6IS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4zOyrr7EX4uS/u+A7QNprojM+21g3vYpltsvkKYJ6NeaYzzhs0yvKQnLXhL47BL8w8nXMuRxB1DSnv9pkmPDAb9rYz6TA3l8liJN4nZuC8zOsJ1/y3BslwG3tuJ/f1mG7fgesCSLfJ4AeqfJZ3wg7Z3A5sArKfI6Fj/KXyOx7/RmWf7fbwrkc2uSz38RyDfT6wWSHPc5OL7j/hcZtmck8E4W65hO5vPTlED6/fF9vS1Mk2cj8D8Z8tyGzMds8LV1e7+jemV+qYNwES/YFO4oMxvlnJvdjvzuwv+QPYhYX1Av4EcSSvRmwvSm+Btt8Cfe2fjR8NYBPfE3a7vhb0h3Bl42s12cr+mQmO+N+BujYyPzFhPfhj8qcVnMP+l8MbK+qFnADGBtpJzjItvZB3jQzE5xzt2XJP98C9asStePw1j8TVQ5fptfxv8I3pT4/hAws78SX1NkLf6GbSmwGb4ZU0+gEviTmW3mnDsvy/Leif9h7fD7aTZ+n4/F31yCD/S8YGbfdM6tTpH
2020-12-11 21:33:20 +00:00
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"state_1_y = [gaussian(i, state1.mean, state1.std_dev) for i in x]\n",
"state_2_y = [gaussian(i, state2.mean, state2.std_dev) for i in x]\n",
"\n",
"plt.plot(x, state_1_y, c='r', label=\"State 1\")\n",
"plt.plot(x, state_2_y, c='b', label=\"State 2\")\n",
"\n",
"plt.legend()\n",
2020-12-31 19:30:39 +00:00
"plt.title(\"State Probability Density Functions With Observations\")\n",
2020-12-11 21:33:20 +00:00
"\n",
2020-12-31 19:30:39 +00:00
"plt.xlabel(x_label)\n",
"plt.ylabel(y_label)\n",
2021-01-01 18:53:11 +00:00
"plt.grid(linestyle=\"--\", axis='y')\n",
2020-12-11 21:33:20 +00:00
"\n",
"state1_pd = [gaussian(i, state1.mean, state1.std_dev) for i in observations]\n",
"state2_pd = [gaussian(i, state2.mean, state2.std_dev) for i in observations]\n",
"\n",
"#############################################\n",
"# Observation Marks \n",
"#############################################\n",
"\n",
"config = {\n",
" \"s\": 65,\n",
" \"marker\": 'x'\n",
"}\n",
"\n",
2021-01-01 18:53:11 +00:00
"[plt.axvline(x=i, ls='--', lw=1.0, c=(0,0,0), alpha=0.4) for i in observations]\n",
2020-12-11 21:33:20 +00:00
"plt.scatter(observations, state1_pd, color=(0.5, 0, 0), **config)\n",
"plt.scatter(observations, state2_pd, color=(0, 0, 0.5), **config)\n",
"\n",
2021-01-01 18:53:11 +00:00
"fig = matplotlib.pyplot.gcf()\n",
"fig.set_dpi(fig_dpi)\n",
"fig.set_tight_layout(True)\n",
"if fig_export:\n",
" savefig(\"report/res/pdfs-w-obs.png\")\n",
2020-12-11 21:33:20 +00:00
"plt.show()"
]
},
2020-12-23 20:12:08 +00:00
{
"source": [
"# Forward Procedure (3)"
],
"cell_type": "markdown",
"metadata": {}
},
2020-12-11 21:33:20 +00:00
{
"cell_type": "code",
2020-12-23 20:12:08 +00:00
"execution_count": 5,
2020-12-11 21:33:20 +00:00
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
2020-12-31 19:30:39 +00:00
"[[9.61469267e-03 2.00389806e-04 2.89433448e-04 4.30961030e-04\n 9.94968491e-05 7.58875028e-06 2.06308972e-06 4.76335758e-07\n 5.63267096e-10]\n [3.06389408e-01 1.56214298e-01 5.73475605e-02 8.00607227e-11\n 1.63710810e-07 1.25762776e-06 2.59451223e-09 7.98988065e-10\n 6.02373446e-09]]\n"
2020-12-11 21:33:20 +00:00
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
2020-12-31 19:30:39 +00:00
"1.9197737567283167e-10"
2020-12-11 21:33:20 +00:00
]
},
"metadata": {},
2020-12-23 20:12:08 +00:00
"execution_count": 5
2020-12-11 21:33:20 +00:00
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition)\n",
2020-12-11 21:33:20 +00:00
"model.populate_forward()\n",
"\n",
2020-12-31 19:30:39 +00:00
"print(model.forward)\n",
2020-12-11 21:33:20 +00:00
"\n",
2020-12-31 19:30:39 +00:00
"forward = model.forward\n",
"model.calculate_p_obs_forward()\n"
2020-12-11 21:33:20 +00:00
]
},
2021-01-01 18:53:11 +00:00
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"280.8pt\" version=\"1.1\" viewBox=\"0 0 424.8 280.8\" width=\"424.8pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:50:59.025235</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 280.8 \nL 424.8 280.8 \nL 424.8 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 48.982813 243.24375 \nL 417.6 243.24375 \nL 417.6 22.318125 \nL 48.982813 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#p76e0dc542c)\" d=\"M 65.738139 243.24375 \nL 65.738139 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m20283ca400\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"65.738139\" xlink:href=\"#m20283ca400\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 1 -->\n <g transform=\"translate(62.556889 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 12.40625 8.296875 \nL 28.515625 8.296875 \nL 28.515625 63.921875 \nL 10.984375 60.40625 \nL 10.984375 69.390625 \nL 28.421875 72.90625 \nL 38.28125 72.90625 \nL 38.28125 8.296875 \nL 54.390625 8.296875 \nL 54.390625 0 \nL 12.40625 0 \nz\n\" id=\"DejaVuSans-49\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-49\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#p76e0dc542c)\" d=\"M 107.626456 243.24375 \nL 107.626456 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"107.626456\" xlink:href=\"#m20283ca400\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 2 -->\n <g transform=\"translate(104.445206 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20.453125 19.1875 8.296875 \nz\n\" id=\"DejaVuSans-50\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-50\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path clip-path=\"url(#p76e0dc542c)\" d=\"M 149.514773 243.243
2021-01-01 18:53:11 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJsAAAMMCAYAAAD0M6ZoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdd5xU1fnH8c/ZvtJZisKuoICoqFgAARWwIlGxxBpLNBqNiSWJmp+JidHEnsRYElus0cSa2KKJLTTpqBBBqQrugiBlKQvb9/z+ODM7ZWdmZ3dnp9z9vl+v+9q59565c2aeubM7z57zXGOtRUREREREREREJBGyUt0BERERERERERHxDiWbREREREREREQkYZRsEhERERERERGRhFGySUREREREREREEkbJJhERERERERERSRglm0REREREREREJGGUbBIRERERERERkYRRsklERERERERERBJGySYREREREREREUkYJZtERERERERERCRhlGwSEREREREREZGEUbJJREREREREREQSRskmERERERERERFJGCWbREREREREREQkYZRsEhERERERERGRhFGySUREREREREREEkbJJhERERERERERSRglm0REREREREREJGGUbBIRERERERERkYRRsklERCQNGGOmGmOsb5mQ6v5IfIwxq4PiNjBKm7SMrTFmYFC/Vsdol7HPMd0YYy4Oep2eTnV/JLMFvZdsqvsiIhJOySYRkTQU9sWtJcuEVPdd0kNYguDiVPcnnRhjJuhLmkhsxpjxxph7jDFzjTGlxpgqY0y5MWapMeY1Y8zlxpi+qe5nujPGPN3K3+dRl1Q/JxGReOSkugMiIiIiIpIejDFHAH8ADo+wOx/oDgwFTgXuM8b8AbjbWluRtE6KiEjaU7JJRCT9zQfmxdl2bXt2REREvMsYcw3wR0JnP2wC5gLrgU7A3sBIwACFwC+BycaYSdbadcntcUZ4H2guEfejoNuvod/lIuIBSjaJiKS/t621t6S6EyLSlLV2YKr70N46wnMUMMb8HLgjaNMa4CfAG9ba+rC2/YCbgctxSaeDgNnGmFHW2g1J6nJGsNY+BzwXq40xJjjZdL+1dmqcxzZt6JqISLtSzSYRERERkQ7MGDMeuC1o02zgQGvtq+GJJgBr7Tpr7Q+AcwH//j2BvxpjlAARERElm0REREREOipjTDbwFIHvBaXAJGvtjubua619CfhZ0KYTgIsT3UcREck8SjaJiHQQxpjRxpg/GWOW+K4oVGWMKTPG/McYc5UxplMcx7gl6Io4t/i2FRpjLjXGvGuM+coYU+Pbf7DvMf3t58Q4boGvP/62C2K0zTPG7PK1qzbGFEZok2uMmei7ktIUY8w63/Erfc/538aYHxtjOsfxnCNeHt4Yc6Qx5nHflZm2+fbfF+H+WcaY7xpj3jPGrPf1Y7Ux5nVjzGnNPX66MM5ZxpjnjTGrjDEVvmWVMebvxpgzWzqiwRhzvDHmBd/7psoY87UxZoYx5kf+92Ok91w6MaFX/RuYgONdYIypDTrmr6K0yzXGXGiMeckY84UxZocxZqcx5ktfjE5P1AiT1j5HY0x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jhBZwTdr792Le+lrCRar72Pw1qW0+UzwZf22eC2i6L9Bxxn4VXEvjMrwPGJPJ11qJFS3KXlHdAixYtWrQ0XQj94jYP95/I5pb+YccYROjQ9x/FeLweuFE3/rZPRml3S9gfxe8QJUkTdJ/Dg59LhP0FQX9cPkPgi+jHEdrmEfiyXQ0UtvF1fjiobxG/1BH6hdziph/s08xx/aOc/Pf5bjNtw6c0TEjAeyj4C8bFrTzGJUHHqCHCF7mgtiMJJCAtcFGENtmETq16JMbx8nzv/eDX5ZYEnV8Tgo+bwNd5YJQ2wefzhKD
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
"\n",
"state_x = np.arange(1, 10)\n",
"\n",
"from numpy import log as ln\n",
"\n",
"plt.plot(state_x, [ln(i) for i in model.forward[0, :]], c='r', label=\"State 1\")\n",
"plt.plot(state_x, [ln(i) for i in model.forward[1, :]], c='b', label=\"State 2\")\n",
"\n",
"plt.ylim(top=0)\n",
"\n",
"plt.legend()\n",
"plt.title(\"Forward Log-Likelihoods Over Time\")\n",
"\n",
"plt.xlabel(\"Observation (t)\")\n",
"plt.ylabel(\"Log Likelihood\")\n",
"plt.grid(linestyle=\"--\")\n",
"\n",
"fig = matplotlib.pyplot.gcf()\n",
"fig.set_dpi(fig_dpi)\n",
"fig.set_tight_layout(True)\n",
"if fig_export:\n",
" savefig(\"report/res/forward-logline.png\")\n",
"plt.show()"
]
},
2020-12-23 20:12:08 +00:00
{
"source": [
"# Backward Procedure (4)"
],
"cell_type": "markdown",
"metadata": {}
},
2020-12-11 21:33:20 +00:00
{
"cell_type": "code",
2021-01-01 18:53:11 +00:00
"execution_count": 7,
2020-12-11 21:33:20 +00:00
"metadata": {},
2020-12-23 20:12:08 +00:00
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
2020-12-31 19:30:39 +00:00
"[[6.57892066e-11 2.92661737e-09 6.89869860e-08 4.45463420e-07\n 1.92898428e-06 2.51074677e-05 9.30059204e-05 3.93414211e-04\n 2.00000000e-02]\n [6.24515168e-10 1.22518178e-09 2.99943420e-09 2.11439342e-08\n 3.02470605e-07 1.14745634e-06 3.77015860e-05 5.73240014e-03\n 3.00000000e-02]]\n"
2020-12-23 20:12:08 +00:00
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
2020-12-31 19:30:39 +00:00
"1.9197737567283167e-10"
2020-12-23 20:12:08 +00:00
]
},
"metadata": {},
2021-01-01 18:53:11 +00:00
"execution_count": 7
2020-12-23 20:12:08 +00:00
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition)\n",
2020-12-23 20:12:08 +00:00
"model.populate_backward()\n",
"\n",
2020-12-24 14:58:45 +00:00
"print(model.backward)\n",
2020-12-31 19:30:39 +00:00
"\n",
"backward = model.backward\n",
2020-12-24 14:58:45 +00:00
"model.calculate_p_obs_backward()\n"
2020-12-23 20:12:08 +00:00
]
},
2021-01-01 18:53:11 +00:00
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"280.8pt\" version=\"1.1\" viewBox=\"0 0 424.8 280.8\" width=\"424.8pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:50:59.518369</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 280.8 \nL 424.8 280.8 \nL 424.8 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 48.982813 243.24375 \nL 417.6 243.24375 \nL 417.6 22.318125 \nL 48.982813 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#pdf544a5844)\" d=\"M 65.738139 243.24375 \nL 65.738139 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m756d8e9c83\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"65.738139\" xlink:href=\"#m756d8e9c83\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 1 -->\n <g transform=\"translate(62.556889 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 12.40625 8.296875 \nL 28.515625 8.296875 \nL 28.515625 63.921875 \nL 10.984375 60.40625 \nL 10.984375 69.390625 \nL 28.421875 72.90625 \nL 38.28125 72.90625 \nL 38.28125 8.296875 \nL 54.390625 8.296875 \nL 54.390625 0 \nL 12.40625 0 \nz\n\" id=\"DejaVuSans-49\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-49\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#pdf544a5844)\" d=\"M 107.626456 243.24375 \nL 107.626456 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"107.626456\" xlink:href=\"#m756d8e9c83\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 2 -->\n <g transform=\"translate(104.445206 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20.453125 19.1875 8.296875 \nz\n\" id=\"DejaVuSans-50\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-50\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path clip-path=\"url(#pdf544a5844)\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bj3mkNwieeaaPXyHK8IeBuXmAL3vM0N1G8rLvnWC3eNdIh1vDgMqnP/mSYe52nPsXoZY3paa5cCWGvLjTEvAL8MbD8H95hi8Y7/FK0V62mBcwf/35XiEn9LcM/3rrjkXQ7uPXq2MeZga+2qGOc2wFO4xKQF5uH+Rxtg78C6TPQY7kegKtz/o8W4BNQxuJkGAf4v0AJtAu4HpP1x/+9m4N73t8UNaN4J93zcb4z52Fo7O9pJjTEDgImEXrPB1/WiwHIv3LVcgJvhcJYx5nBr7dfNf8gi0iypznbppptuuvn5RiNaNuGSQz94yr8co/wduAHFO0TZboARwE+eYx7VwPEOILzFwyfAoVHK7oCbQei6CNsu9BxjXITtxwNbPGX+A2RFOc83nnL1fq3EfekMbvc+zn0jlC3ybP8xyvkuBi6j4V+w98V90A0e688NlL3ZU64y8PcFoGudcllAbmC5C7DKs9/nwB4Ryl+H+0JU7im7JAGv2UGe49lmHOcIwluJTQK61SmTD/zdez7g6gZez9M95dbgkip1yx0TeP7qPje9mvvcBI4/rqHXdxOf52lRyvRqKLa4xJC3JeRMoFOUY93qKbcCOIUILZdw7yk/e8qeHsdr++YEPcbyQNwWA4dEqVuFp/z5DTy/D3jKVQFXUud9BuiLSwQEy22I9joJPNebPGU/AvpEuC6vJrxV1v0N1NHb0rKcCC1ZccmmJZ4ywfKDIpT9p2f7DKB7lPPm4JL0TxFni9cox3nUc77VzTjOPp7jWOCcOtsHeLatjFVnQgkdi0ssto1QZi9cAs4GXnN3AdtGKNcbl6CsfR+L47UefK//HNgnQtn8pj5XEY51oee89d4j4txvXByPqYzQe0zvOuXaEN7SeiFu0HiLa921fZ3ynQh/L3+vgXruQPj
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
"\n",
"state_x = np.arange(1, 10)\n",
"\n",
"from numpy import log as ln\n",
"\n",
"plt.plot(state_x, [ln(i) for i in model.backward[0, :]], c='r', label=\"State 1\")\n",
"plt.plot(state_x, [ln(i) for i in model.backward[1, :]], c='b', label=\"State 2\")\n",
"\n",
"plt.ylim(top=0)\n",
"\n",
"plt.legend()\n",
"plt.title(\"Backward Log-Likelihoods Over Time\")\n",
"\n",
"plt.xlabel(\"Observation (t)\")\n",
"plt.ylabel(\"Log Likelihood\")\n",
"plt.grid(linestyle=\"--\")\n",
"\n",
"fig = matplotlib.pyplot.gcf()\n",
"fig.set_dpi(fig_dpi)\n",
"fig.set_tight_layout(True)\n",
"if fig_export:\n",
" savefig(\"report/res/backward-logline.png\")\n",
"plt.show()"
]
},
2020-12-23 20:12:08 +00:00
{
"source": [
"# Compare Forward/Backward Final"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-01-01 18:53:11 +00:00
"execution_count": 9,
2020-12-23 20:12:08 +00:00
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
2020-12-31 19:30:39 +00:00
"forward: 1.9197737567283167e-10\nbackward: 1.9197737567283167e-10\ndiff: 0.0\n"
2020-12-23 20:12:08 +00:00
]
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition)\n",
2020-12-23 20:12:08 +00:00
"model.populate_forward()\n",
"model.populate_backward()\n",
"\n",
2020-12-24 14:58:45 +00:00
"print(\"forward:\", model.calculate_p_obs_forward())\n",
2020-12-31 19:30:39 +00:00
"print(\"backward:\", model.calculate_p_obs_backward())\n",
"\n",
"print(\"diff: \", model.p_obs_forward - model.p_obs_backward)\n"
2020-12-23 20:12:08 +00:00
]
2020-12-24 14:58:45 +00:00
},
{
"source": [
"# Occupation Likelihoods (5)"
],
"cell_type": "markdown",
"metadata": {}
},
2020-12-31 19:30:39 +00:00
{
"cell_type": "code",
2021-01-01 18:53:11 +00:00
"execution_count": 10,
2020-12-31 19:30:39 +00:00
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[[3.29488306e-03 3.05486147e-03 1.04007783e-01 9.99999991e-01\n 9.99742065e-01 9.92483109e-01 9.99490475e-01 9.76142401e-01\n 5.86805704e-02]\n [9.96705117e-01 9.96945139e-01 8.95992217e-01 8.81769869e-09\n 2.57935122e-04 7.51689067e-03 5.09524759e-04 2.38575993e-02\n 9.41319430e-01]]\n"
]
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
2020-12-31 19:30:39 +00:00
"\n",
"occupation = model.occupation\n",
"print(model.occupation)"
]
},
2021-01-01 18:53:11 +00:00
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1200x1200 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"424.8pt\" version=\"1.1\" viewBox=\"0 0 416.703013 424.8\" width=\"416.703013pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:51:00.058329</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 424.8 \nL 416.703013 424.8 \nL 416.703013 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"patch_2\">\n <path d=\"M 7.2 417.6 \nL 402.481875 417.6 \nL 402.481875 22.318125 \nL 7.2 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"pane3d_1\">\n <g id=\"patch_3\">\n <path d=\"M 49.005253 340.305731 \nL 135.065331 201.936667 \nL 131.351494 50.443663 \nL 40.252902 181.428404 \n\" style=\"fill:#f2f2f2;opacity:0.5;stroke:#f2f2f2;stroke-linejoin:miter;\"/>\n </g>\n </g>\n <g id=\"pane3d_2\">\n <g id=\"patch_4\">\n <path d=\"M 135.065331 201.936667 \nL 361.811916 244.232181 \nL 369.53318 90.353614 \nL 131.351494 50.443663 \n\" style=\"fill:#e6e6e6;opacity:0.5;stroke:#e6e6e6;stroke-linejoin:miter;\"/>\n </g>\n </g>\n <g id=\"pane3d_3\">\n <g id=\"patch_5\">\n <path d=\"M 49.005253 340.305731 \nL 294.873299 390.994429 \nL 361.811916 244.232181 \nL 135.065331 201.936667 \n\" style=\"fill:#ececec;opacity:0.5;stroke:#ececec;stroke-linejoin:miter;\"/>\n </g>\n </g>\n <g id=\"axis3d_1\">\n <g id=\"line2d_1\">\n <path d=\"M 49.005253 340.305731 \nL 294.873299 390.994429 \n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-width:0.8;\"/>\n </g>\n <g id=\"text_1\">\n <!-- Observation -->\n <g transform=\"translate(129.664429 399.369867)rotate(-348.350985)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 39.40625 66.21875 \nQ 28.65625 66.21875 22.328125 58.203125 \nQ 16.015625 50.203125 16.015625 36.375 \nQ 16.015625 22.609375 22.328125 14.59375 \nQ 28.65625 6.59375 39.40625 6.59375 \nQ 50.140625 6.59375 56.421875 14.59375 \nQ 62.703125 22.609375 62.703125 36.375 \nQ 62.703125 50.203125 56.421875 58.203125 \nQ 50.140625 66.21875 39.40625 66.21875 \nz\nM 39.40625 74.21875 \nQ 54.734375 74.21875 63.90625 63.9375 \nQ 73.09375 53.65625 73.09375 36.375 \nQ 73.09375 19.140625 63.90625 8.859375 \nQ 54.734375 -1.421875 39.40625 -1.421875 \nQ 24.03125 -1.421875 14.8125 8.828125 \nQ 5.609375 19.09375 5.609375 36.375 \nQ 5.609375 53.65625 14.8125 63.9375 \nQ 24.03125 74.21875 39.40625 74.21875 \nz\n\" id=\"DejaVuSans-79\"/>\n <path d=\"M 48.6875 27.296875 \nQ 48.6875 37.203125 44.609375 42.84375 \nQ 40.53125 48.484375 33.40625 48.484375 \nQ 26.265625 48.484375 22.1875 42.84375 \nQ 18.109375 37.203125 18.109375 27.296875 \nQ 18.109375 17.390625 22.1875 11.75 \nQ 26.265625 6.109375 33.40625 6.109375 \nQ 40.53125 6.109375 44.609375 11.75 \nQ 48.6875 17.390625 48.6875 27.296875 \nz\nM 18.109375 46.390625 \nQ 20.953125 51.265625 25.265625 53.625 \nQ 29.59375 56 35.59375 56 \nQ 45.5625 56 51.78125 48.09375 \nQ 58.015625 40.1875 58.015625 27.296875 \nQ 58.015625 14.40625 51.78125 6.484375 \nQ 45.5625 -1.421875 35.59375 -1.421875 \nQ 29.59375 -1.421875 25.265625 0.953125 \nQ 20.953125 3.328125 18.109375 8.203125 \nL 18.109375 0 \nL 9.078125 0 \nL 9.078125 75.984375 \nL 18.109375 75.984375 \nz\n\" id=\"DejaVuSans-98\"/>\n <path d=\"M 44.28125 53.078125 \n
2021-01-01 18:53:11 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABIUAAAScCAYAAAAVlT/+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAB7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w09PfOp0N/bawF8KAQ4jop5e4K7v8/Abw2+/MogKeyba6B/ndpR+8H8K/Q+78d+vPeDf2LneXZbV4JYL8Q4sMA7oE+V1QG+mfxAejPwWdCDzkB4K1CiMellN+0u1MhxHoAv4H++QDor7vHs/cfh/6cfgb09/3FAH4thHiulPJ3c37ERETN1uxUihdeeOm+C/K/Af/OHNp5A/K/vbvYYpsroB/QGds8DuAam/YWAXgLgLdZ/M4NPVwxf9P8OgAei229AJ4H4PsWv1tuauNIhY/ziOk2yyvYJglABfBvKKhcAbABwA7TtqcBDNi0eQ30k6RNJfq2AHq4Y7R3b4lta3nsFd0GwOdM22WghxKFj3019JN/Y7upEvvzDtN2RjXJVgCDBdsFoZ+kGtvOAAjV4TVivv/75tBOpfvPtgoA+on9o6Zt9gBYZtPOPxbs31fZvEaeCT1gNLYtes1lt7vVtM3Wej3G7N/0HIC/sNjuGdm+G9veXqLNtxW0+yEUVD5Bf1/5pWmbNOzfgwYK9ss+AFdabPdS5FfP/KhEH99t2k6DPp+bUrDNGgBPYvb9w9j+Vov23mj6/U4Aa23uVwDYAv21uXQOz+H/z3R/KoCeGtvpRX6F57sKfn+J6fdJFLzWLdobBJAy7dcVFtssAnDWdJ9fAXCRxXYLAXzPtN1I4d/I4rluVKYdg0XVCgB
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
"\n",
"fig = plt.figure(figsize=(6,6), dpi=fig_dpi, tight_layout=True)\n",
"ax = fig.add_subplot(1, 1, 1, projection=\"3d\", xmargin=0, ymargin=0)\n",
"\n",
"y_width = 0.3\n",
"\n",
"X = np.arange(1, 10) - 0.5\n",
"Y = np.arange(1, 3) - 0.5*y_width\n",
"X, Y = np.meshgrid(X, Y)\n",
"Z = np.zeros(model.forward.size)\n",
"\n",
"dx = np.ones(model.forward.size)\n",
"dy = y_width * np.ones(model.forward.size)\n",
"\n",
"colours = [*[(1.0, 0.1, 0.1) for i in range(9)], *[(0.2, 0.2, 1.0) for i in range(9)]]\n",
"ax.bar3d(X.flatten(), Y.flatten(), Z, \n",
" dx, dy, model.occupation.flatten(), \n",
" color=colours, shade=True)\n",
"\n",
"ax.set_yticks([1, 2])\n",
"ax.set_zlim(top=1.0)\n",
"\n",
"ax.set_title(\"Occupation Likelihoods Over Time\")\n",
"ax.set_xlabel(\"Observation\")\n",
"ax.set_ylabel(\"State\")\n",
"ax.set_zlabel(\"Occupation Likelihood\")\n",
"ax.view_init(35, -72)\n",
"if fig_export:\n",
" savefig(\"report/res/occupation-bars.png\")\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"280.8pt\" version=\"1.1\" viewBox=\"0 0 424.8 280.8\" width=\"424.8pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:51:00.581489</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 280.8 \nL 424.8 280.8 \nL 424.8 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.78125 243.24375 \nL 417.6 243.24375 \nL 417.6 22.318125 \nL 43.78125 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#p43428d315c)\" d=\"M 60.773011 243.24375 \nL 60.773011 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m4efd1fbc13\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"60.773011\" xlink:href=\"#m4efd1fbc13\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 1 -->\n <g transform=\"translate(57.591761 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 12.40625 8.296875 \nL 28.515625 8.296875 \nL 28.515625 63.921875 \nL 10.984375 60.40625 \nL 10.984375 69.390625 \nL 28.421875 72.90625 \nL 38.28125 72.90625 \nL 38.28125 8.296875 \nL 54.390625 8.296875 \nL 54.390625 0 \nL 12.40625 0 \nz\n\" id=\"DejaVuSans-49\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-49\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#p43428d315c)\" d=\"M 103.252415 243.24375 \nL 103.252415 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"103.252415\" xlink:href=\"#m4efd1fbc13\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- 2 -->\n <g transform=\"translate(100.071165 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20.453125 19.1875 8.296875 \nz\n\" id=\"DejaVuSans-50\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-50\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_3\">\n <g id=\"line2d_5\">\n <path clip-path=\"url(#p43428d315c)\" d=\"M 145.731818 243.24375
2021-01-01 18:53:11 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJsAAAMMCAYAAAD0M6ZoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdd5gb5bn38e+9fd0rNvYuNthU07GNKy0BQkIgIQmQEELLIe3kpJz0vCf1pJ6EkB6SE1oqkARCygmm497ABoyxsbHNro2Njbu9Xc/7x0ir0ayk1e6qzv4+16VrNaNHM49070ije55izjlERERERERERESyoazQFRARERERERERkfBQsklERERERERERLJGySYREREREREREckaJZtERERERERERCRrlGwSEREREREREZGsUbJJRERERERERESyRskmERERERERERHJGiWbREREREREREQka5RsEhERERERERGRrFGySUREREREREREskbJJhERERERERERyRolm0REREREREREJGuUbBIRERERERERkaxRsklERERERERERLJGySYREREREREREckaJZtERERERERERCRrlGwSEREREREREZGsUbJJRERERERERESyRskmERERERERERHJGiWbRERESpiZTTQzF71tLnR9Sk2m75+vjMtj9bplZtf76nZnijIl/RqLjZnd6Xuvri90faR0mdl5vv+lJwpdHxGRbFKySUSkhJjZBDP7DzP7PzNbb2b7zKzJzDab2UIz+5qZTSt0PUVyzcy+oh9pIqmZWa2ZXWFmvzaz1Wa23cxazWyHmT1rZreb2TvMrLbQdS120e9Yl8XbE4V+TSIiuVZR6AqIiEj3zGwU8BXgAyT/7J4Qvc0C/svMHgI+5Zx7Pm+VlD4zs4nApujiFufcxMLVRkRKkZkZ8D7gv4G6JEWOiN5OAW4AtprZF4G7nXNq1SYiIlmhZJOISJEzs5OAfwH1vtXtwBJgC9ACjMNLNA2JPn4xcJ6ZXeOc+3MeqysiIgViZlXAncC7Aw9tAJ4DdgEjgZOB46KPjY8+5yIzu94515aXypaWu/Det1TGA2/zLf+0m+291NcKiYgUOyWbRESKWDTRtAAYHl3VBnwP+L5z7vVA2Wrgqujjo4Fq4F4ze59z7nf5q7Xkk3NuM2CFrkep6g/vX394jQJmVgY8AFziW/0U8Enn3Mok5U8HfgCcF131HmC4mV3qnIvktLIlxjn35XSPm9l5+JJNzrl/z3C7T6BjU0RCSmM2iYgUKTOrAe4hnmg6DFzonPtCMNEE4Jxrcc7dDZxG/KppGXCbmR0XLC8iIqHyBRITTT8BzkuWaAJwzq1yzp0P/Ni3+hLg87mrooiI9Bd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GkBOoBPEmhpA5wEPO8r+yowPMU2z8b78XVymrodgZc0im3vkTRle/PaM3oO8DNfuXa8ZEfwtR+Ll1SIlduX5v38iq9crPXLncCIQLkBeD9+Y2UPAAOzcIz49/9EH7aT6fuXstUCXsJgma/Mi8BRKbZzY+D9fX+KY+R8vMRlrGyXYy5a7npfmTuz9RqjMX0NeFOScudE6x4r+6U02/xMYLvfItBSC+9z5SFfmTZSfwYND7wv64GzkpS7hsTWPg+mqeN/+cpF8MbLKw+UOQ5YRfzzI1b++iTb+5jv8TXA8Sn2a8A0vGOzvg//w//Pt78OYHAvtzOExBapXww8PsH3eAuBYz3J9kYArb739egkZcYCO3z7vAs4Mkm5McBffOWeDcYoyf96rCXdKyRpZQNU9/Y9T7Kt8/z/57183hMpyvhfU2v0vVwLnB4oV0Fii6fdwJei9+cH33+8hKK/JeZGoq2hktRhIIkt2/4JTErxP+T/rtkGDM3W+6ybbrqV1q3gFdBNN910063rDe/HVuxk7ct
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
"\n",
"state_x = np.arange(1, 10)\n",
"\n",
"plt.plot(state_x, model.occupation[0, :], c='r', label=\"State 1\")\n",
"plt.plot(state_x, model.occupation[1, :], c='b', label=\"State 2\")\n",
"\n",
"plt.legend()\n",
"plt.title(\"Occupation Likelihoods Over Time\")\n",
"\n",
"plt.xlabel(\"Observation (t)\")\n",
"plt.ylabel(\"Occupation Likelihood\")\n",
"plt.grid(linestyle=\"--\")\n",
"\n",
"fig = matplotlib.pyplot.gcf()\n",
"fig.set_dpi(fig_dpi)\n",
"fig.set_tight_layout(True)\n",
"if fig_export:\n",
" savefig(\"report/res/occupation-line.png\")\n",
"plt.show()"
]
},
2020-12-31 19:30:39 +00:00
{
"source": [
"# Re-estimate Mean & Variance (6)"
],
"cell_type": "markdown",
"metadata": {}
},
2020-12-24 14:58:45 +00:00
{
"cell_type": "code",
2021-01-01 18:53:11 +00:00
"execution_count": 13,
2020-12-24 14:58:45 +00:00
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
2020-12-31 19:30:39 +00:00
"mean: [1, 4]\nvariance: [1.44, 0.49]\n\nmean: [1.6747846620246418, 4.089148442531048]\nvariance: [1.8465047320872243, 0.37804421554121403]\n"
2020-12-24 14:58:45 +00:00
]
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
2020-12-31 19:30:39 +00:00
"\n",
"print(\"mean: \", [state1.mean, state2.mean])\n",
"print(\"variance: \", [state1.variance, state2.variance])\n",
"print()\n",
"\n",
"print(\"mean: \", model.reestimated_mean())\n",
"print(\"variance: \", model.reestimated_variance())\n"
]
},
{
"source": [
"New PDFs (7)\n",
"==================="
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-01-01 18:53:11 +00:00
"execution_count": 14,
2020-12-31 19:30:39 +00:00
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
2021-01-01 18:53:11 +00:00
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"277.314375pt\" version=\"1.1\" viewBox=\"0 0 385.78125 277.314375\" width=\"385.78125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:51:01.088056</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 277.314375 \nL 385.78125 277.314375 \nL 385.78125 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.78125 239.758125 \nL 378.58125 239.758125 \nL 378.58125 22.318125 \nL 43.78125 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#p3c177b1e1b)\" d=\"M 58.999432 239.758125 \nL 58.999432 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m0090ecdb57\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"58.999432\" xlink:href=\"#m0090ecdb57\" y=\"239.758125\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- − 4 -->\n <g transform=\"translate(51.628338 254.356562)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 10.59375 35.5 \nL 73.1875 35.5 \nL 73.1875 27.203125 \nL 10.59375 27.203125 \nz\n\" id=\"DejaVuSans-8722\"/>\n <path d=\"M 37.796875 64.3125 \nL 12.890625 25.390625 \nL 37.796875 25.390625 \nz\nM 35.203125 72.90625 \nL 47.609375 72.90625 \nL 47.609375 25.390625 \nL 58.015625 25.390625 \nL 58.015625 17.1875 \nL 47.609375 17.1875 \nL 47.609375 0 \nL 37.796875 0 \nL 37.796875 17.1875 \nL 4.890625 17.1875 \nL 4.890625 26.703125 \nz\n\" id=\"DejaVuSans-52\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-8722\"/>\n <use x=\"83.789062\" xlink:href=\"#DejaVuSans-52\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#p3c177b1e1b)\" d=\"M 109.726705 239.758125 \nL 109.726705 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"109.726705\" xlink:href=\"#m0090ecdb57\" y=\"239.758125\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- − 2 -->\n <g transform=\"translate(102.355611 254.356562)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.
2021-01-01 18:53:11 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABDAAAAMFCAYAAACChAaGAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdeZwcdZ3/8ddn7slJEiCQzOTmkhsCCJIQQC65WURWRUFYXX/qIoKuu3iArniCgicqBFB0OUQEcSUgkCBHSBAiZ8jNTELukHNmMsf390d1z1RX+pzp7qrufj8fj35MV/W3q77d9amerk9/D3POISIiIiIiIiISZVVhV0BEREREREREJBMlMEREREREREQk8pTAEBEREREREZHIUwJDRERERERERCJPCQwRERERERERiTwlMEREREREREQk8pTAEBEREREREZHIUwJDRERERERERCJPCQwRERERERERiTwlMEREREREREQk8pTAEBEREREREZHIUwJDRERERERERCJPCQwRERERERERiTwlMEREREREREQk8pTAEBEREREREZHIUwJDRERERERERCJPCQwRERERERERiTwlMEREREREREQk8pTAEBEREREREZHIUwJDRGSAzOwpM3Ox24yw6yPpmdly3/GaEHZ9osbMZvjen6fCrk8qZnaHr56X5mmbWb12XxmXpow+FyQtM7vUFyN3hF0fKS36jJFKVRN2BUQkvdiX6BPSFNkGbAJeB+YAdzrnVhahaiKCdzGb5uEeYAuwGpgP/Al40DnXVYy6ieRThljfjhfrm4G3gRdjt8ecc1uKUD2JgFgi5uP9eOplzrk78lsbESlHaoEhUvqGAM3AacC3gGVm9nUzs3CrVZr0i0b2zOw633t1Xdj1iagqYDdgf+CjwH3A62Z2VJiVkmgos3NoMLA3XqyfCvwXcD+wysx+bWbvCbNypcrMJvhiZHnY9ZHC0HcPkeypBYZIaZkHvBBYNxw4FDg4tlwLXId30XRVsSomIgA8CPhbQFUDo4HjgT1i6/YBnjSz6c65fxS3eiJ58yCJsV4DjABGAYcDI2PrBwOXAx81s/8GfuicS9eSQ8rHm8Dfsiz7RiErIiLlQwkMkdLyF+fcdckeMLPjgN8D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Au88/ZuZvc85tyXFdvIVf8mMB27Ce2+3AU/gff6NwXvtg/BmhPm6mVU5576WzQsvoJzPIefcBjN7APhXvHP+MrxBYVMys92Af/Gt+vWAaj1w99E3Y9ZBZrabc+7dYCEzO4DEc9rhnc+v4/2fGIvXRXIo3jF+zMzOcM49makCsV+xfx5bXAjMj21zf7z/eYYXjw+Z2QHOuV3OUTObipcoiH+P9v/v6sD7bJsce62DMtUphTfw/i8NBT4WW7cVuCvD835J3zH/hJndkMU55G8dc4dzrjvXypaYGuAPwMl4CYVn8b7/NOD9T40Phn463udKyjFbzGwIMAvvMzBuB97/6Ra8eBoLHIkXV7V4n0VxBf/uYWbX4H1HiuvA+97xNt5n5ol43/mqgc8D48zswiw/e78OxD9PX8Yb76YT73vLEbH1E4EHzeyIZN9PzOw8vB+g4rbg/WjVipdUGY73fecgoC6LOkm5CzuDoptuuqW/kUMLDLx/ym/7yt+XpuydvnILSZK9x/tn9mn6fqnqAo7N0+s6kL5sew/eP9fdkpSbBDztq+tfkpQZRd8vH13AxwFLsd+9gc8Bl2fxfu/ynvT3OST+ohR/P68H6gLlDgLe8ZX9XuyY7sS7AK8KlJ+Od8EWL/+xNPX8It6vULunKTMNL5EQ395H05S9LtvY9D1nL7wLy/jz7gT2TlJuNPCAr9w/SfGrEPC4r9y7wFlJypxB36+lO33lJ+Qhlv2/DKWNmVis+n+p+l7gcX8sdcbOja8AtYFy9b77FwX
2020-12-31 19:30:39 +00:00
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
2020-12-24 14:58:45 +00:00
"\n",
2020-12-31 19:30:39 +00:00
"new_mean = model.reestimated_mean()\n",
"new_var = model.reestimated_variance()\n",
"new_std_dev = [sqrt(x) for x in new_var]\n",
2020-12-24 14:58:45 +00:00
"\n",
2020-12-31 19:30:39 +00:00
"state_1_y = [gaussian(i, new_mean[0], new_std_dev[0]) for i in x]\n",
"state_2_y = [gaussian(i, new_mean[1], new_std_dev[1]) for i in x]\n",
2020-12-24 14:58:45 +00:00
"\n",
2020-12-31 19:30:39 +00:00
"plt.plot(x, state_1_y, c='r', label=\"State 1\")\n",
"plt.plot(x, state_2_y, c='b', label=\"State 2\")\n",
"\n",
"plt.legend()\n",
"plt.title(\"Re-estimated Probability Density Functions\")\n",
"\n",
"plt.xlabel(x_label)\n",
"plt.ylabel(y_label)\n",
"plt.grid(linestyle=\"--\")\n",
"\n",
2021-01-01 18:53:11 +00:00
"fig = matplotlib.pyplot.gcf()\n",
"fig.set_dpi(fig_dpi)\n",
2020-12-31 19:30:39 +00:00
"plt.show()"
]
},
{
"source": [
"# Compare PDFs (7)"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-01-01 18:53:11 +00:00
"execution_count": 15,
2020-12-31 19:30:39 +00:00
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
2021-01-01 18:53:11 +00:00
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"280.8pt\" version=\"1.1\" viewBox=\"0 0 424.8 280.8\" width=\"424.8pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:51:01.565307</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 280.8 \nL 424.8 280.8 \nL 424.8 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.78125 243.24375 \nL 417.6 243.24375 \nL 417.6 22.318125 \nL 43.78125 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#p76fff50835)\" d=\"M 60.773011 243.24375 \nL 60.773011 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"mdf53c47469\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"60.773011\" xlink:href=\"#mdf53c47469\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- − 4 -->\n <g transform=\"translate(53.401918 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 10.59375 35.5 \nL 73.1875 35.5 \nL 73.1875 27.203125 \nL 10.59375 27.203125 \nz\n\" id=\"DejaVuSans-8722\"/>\n <path d=\"M 37.796875 64.3125 \nL 12.890625 25.390625 \nL 37.796875 25.390625 \nz\nM 35.203125 72.90625 \nL 47.609375 72.90625 \nL 47.609375 25.390625 \nL 58.015625 25.390625 \nL 58.015625 17.1875 \nL 47.609375 17.1875 \nL 47.609375 0 \nL 37.796875 0 \nL 37.796875 17.1875 \nL 4.890625 17.1875 \nL 4.890625 26.703125 \nz\n\" id=\"DejaVuSans-52\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-8722\"/>\n <use x=\"83.789062\" xlink:href=\"#DejaVuSans-52\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#p76fff50835)\" d=\"M 117.412216 243.24375 \nL 117.412216 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"117.412216\" xlink:href=\"#mdf53c47469\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- − 2 -->\n <g transform=\"translate(110.041122 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20
2021-01-01 18:53:11 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJsAAAMMCAYAAAD0M6ZoAAA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CyZiXOepuDUl+Y458rPGPM8gS1F9uDcqG8EDsCpV/Vw3tPHjDEHWGujna1yNKXjwc0EFuHcXPXFOVfgfE6/NsYcZ63dFSafeNW/UNoBI3De2z3ANzjXv1Y4r70uzsyA9xtj0qy190XzwhMo5s+QtXarMeYD4A84n/nLcQacD8sY0xD4nWvTa5UqdeWNpXTm1O7GmIbW2h3BiYwxhxD4mbY4n+dFOP8nWuN0E6+Pc46/MsYMsdZOLK8A3tYhL3lXfwFme/PsivM/z+DUx0+MMYdYa8t8Ro0xvXCCOr57A/f/riKca1tH72utW16ZwliM83+pPnCpd9tu4F/l7PcKpef8CmPMI1F8htytzkZba0tiLWw1kwH8FzgRJ/gzDef7TzbO/1TfRCun4lxXwo4xZoypB4zHuQb67MX5P70Wpz61Bo7CqVeZONcin4R/9zDG3IbzHcmnCOd7xxqca+bxON/50oGbgAONMedFee29H/BdT3/EGZ9tP873liO92w8CPjLGHBnq+4kx5mycHwt9duH8wLgOJwDWAOf7TnegThRlEqmeUh3t0kMPPWrfgxhaNuF8gVrjSj82Qto3Xel+IcSvYjhfPK6h9BfgYuDYOL2ubpT+iuXB+SLUMES6DsC3rrJ+HiJNE0p/USwGLgNMmOO2BK4Hrozi/S7znlR0HwJ/qfW9n8OBOkHpugO/utI+7j2n+3CCJWlB6Qfg3Fz70l8aoZy34/y62zRCmv44QR9ffhdHSPtAtHXTtc8BOEEA335vAi1
2020-12-31 19:30:39 +00:00
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
2020-12-31 19:30:39 +00:00
"\n",
"new_mean = model.reestimated_mean()\n",
"new_var = model.reestimated_variance()\n",
"new_std_dev = [sqrt(x) for x in new_var]\n",
"\n",
"#######################################\n",
"# Original\n",
"#######################################\n",
"state_1_y = [gaussian(i, state1.mean, state1.std_dev) for i in x]\n",
"state_2_y = [gaussian(i, state2.mean, state2.std_dev) for i in x]\n",
"plt.plot(x, state_1_y, '--', c='r', label=\"State 1\", linewidth=1.0)\n",
"plt.plot(x, state_2_y, '--', c='b', label=\"State 2\", linewidth=1.0)\n",
"\n",
"#######################################\n",
"# Re-Estimated\n",
"#######################################\n",
"state_1_new_y = [gaussian(i, new_mean[0], new_std_dev[0]) for i in x]\n",
"state_2_new_y = [gaussian(i, new_mean[1], new_std_dev[1]) for i in x]\n",
"plt.plot(x, state_1_new_y, c='r', label=\"New State 1\")\n",
"plt.plot(x, state_2_new_y, c='b', label=\"New State 2\")\n",
"\n",
"plt.legend()\n",
"plt.title(\"Re-estimated Probability Density Functions\")\n",
"\n",
"plt.xlabel(x_label)\n",
"plt.ylabel(y_label)\n",
"plt.grid(linestyle=\"--\")\n",
"\n",
2021-01-01 18:53:11 +00:00
"fig = matplotlib.pyplot.gcf()\n",
"fig.set_dpi(fig_dpi)\n",
"fig.set_tight_layout(True)\n",
"if fig_export:\n",
" savefig(\"report/res/re-est-pdfs.png\")\n",
2020-12-31 19:30:39 +00:00
"plt.show()"
]
},
{
"source": [
"# Multiple Iterations"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-01-05 11:10:29 +00:00
"execution_count": 16,
2020-12-31 19:30:39 +00:00
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
2021-01-05 11:10:29 +00:00
"mean (0): [1.6747846620246418, 4.089148442531048]\n",
"var (0): [1.8465047320872243, 0.37804421554121403]\n",
"[[0.70176362 0.57084996]\n",
" [1.6956088 0.26442637]]\n",
"\n",
"mean (1): [1.8732627187085478, 4.1264787288916045]\n",
"var (1): [1.741702511836495, 0.3397362903623662]\n",
"[[0.8060609 0.14928497]\n",
" [0.3747969 0.38642879]]\n",
"\n",
"mean (2): [1.9467921888680977, 4.144829018638114]\n",
"var (2): [1.802927096107906, 0.3244337549372125]\n",
"[[0.82078158 0.13830527]\n",
" [0.34355999 0.40237225]]\n",
"\n",
"mean (3): [1.998417533036004, 4.146391356501866]\n",
"var (3): [1.8794907388957407, 0.31336829013095496]\n",
"[[0.82382934 0.12631664]\n",
" [0.34908171 0.40883355]]\n",
"\n",
"mean (4): [2.0403185801109194, 4.137443801197436]\n",
"var (4): [1.9532263949235384, 0.30316834940556364]\n",
"[[0.82663329 0.11372608]\n",
" [0.35679246 0.4179057 ]]\n",
"\n",
"mean (5): [2.0768416135288152, 4.120742753858993]\n",
"var (5): [2.026102075205389, 0.291798571474891]\n",
"[[0.82952161 0.1002526 ]\n",
" [0.36446428 0.43140289]]\n",
"\n",
"mean (6): [2.11194659437116, 4.096434012657846]\n",
"var (6): [2.1032895125514766, 0.2773354097864741]\n",
"[[0.83266361 0.08482054]\n",
" [0.37298205 0.45042633]]\n",
"\n",
"mean (7): [2.149792870100123, 4.062396551986207]\n",
"var (7): [2.191678450688613, 0.2568529817420179]\n",
"[[0.8363706 0.0660714 ]\n",
" [0.3837438 0.47744431]]\n",
"\n",
"mean (8): [2.194489793285685, 4.014103644960269]\n",
"var (8): [2.2986239066545524, 0.22514847051325343]\n",
"[[0.84098808 0.04298428]\n",
" [0.39835926 0.51702684]]\n",
"\n",
"mean (9): [2.246078108416006, 3.9478836679900287]\n",
"var (9): [2.423237858945465, 0.17533830729899114]\n",
"[[0.84636913 0.01806124]\n",
" [0.41572836 0.57245506]]\n",
"\n",
"mean (10): [2.2856592028959346, 3.882184182166453]\n",
"var (10): [2.527476010893805, 0.11675401844606319]\n",
"[[0.85009354 0.00251453]\n",
" [0.420065 0.6209139 ]]\n",
"\n",
"mean (11): [2.290643073016055, 3.8598915740419946]\n",
"var (11): [2.5588220300129474, 0.09296081385828549]\n",
"[[8.49474403e-01 6.94178508e-05]\n",
" [4.04708642e-01 6.12273377e-01]]\n",
"\n",
"mean (12): [2.2914144510257906, 3.8594038663696892]\n",
"var (12): [2.559782940361538, 0.09129358424097164]\n",
"[[8.48816419e-01 2.56744984e-06]\n",
" [4.07814693e-01 5.92792027e-01]]\n",
"\n",
"mean (13): [2.2920722638916136, 3.8597894517174827]\n",
"var (13): [2.559397203251749, 0.09112610156222908]\n",
"[[8.48468970e-01 1.38599620e-07]\n",
" [4.08641855e-01 5.91369797e-01]]\n",
"\n",
"mean (14): [2.2923368298535873, 3.85996676996849]\n",
"var (14): [2.559213392145394, 0.0910669910055963]\n",
"[[8.48421180e-01 7.64719574e-09]\n",
" [4.08579843e-01 5.91420888e-01]]\n",
"\n",
"mean (15): [2.2924457175066317, 3.860041202681166]\n",
"var (15): [2.559136099327699, 0.09104297025788764]\n",
"[[8.48413724e-01 4.22240186e-10]\n",
" [4.08544019e-01 5.91456046e-01]]\n",
"\n",
"mean (16): [2.2924909067581587, 3.8600721725675933]\n",
"var (16): [2.559103947613575, 0.09103301880870453]\n",
"[[8.48411387e-01 2.33175631e-11]\n",
" [4.08528360e-01 5.91471648e-01]]\n",
"\n",
"mean (17): [2.2925096881606515, 3.8600850494050714]\n",
"var (17): [2.5590905823972907, 0.09102888377407325]\n",
"[[8.48410459e-01 1.28774690e-12]\n",
" [4.08521812e-01 5.91478189e-01]]\n",
"\n",
"mean (18): [2.292517496754187, 3.860090403678976]\n",
"var (18): [2.55908502565561, 0.09102716461059344]\n",
"[[8.48410077e-01 7.11193032e-14]\n",
" [4.08519090e-01 5.91480910e-01]]\n",
"\n",
"mean (19): [2.292520743671027, 3.860092630150436]\n",
"var (19): [2.559082715100272, 0.09102644975438301]\n",
"[[8.48409918e-01 3.92779179e-15]\n",
" [4.08517958e-01 5.91482042e-01]]\n",
"\n",
"mean (20): [2.2925220938511153, 3.860093556010955]\n",
"var (20): [2.5590817542930737, 0.09102615249086479]\n",
"[[8.48409852e-01 2.16925735e-16]\n",
" [4.08517488e-01 5.91482512e-01]]\n",
"\n",
"mean (21): [2.292522655314822, 3.8600939410271335]\n",
"var (21): [2.5590813547477076, 0.09102602887540412]\n",
"[[8.48409824e-01 1.19804846e-17]\n",
" [4.08517292e-01 5.91482708e-01]]\n",
"\n",
"mean (22): [2.2925228887980498, 3.8600941011356555]\n",
"var (22): [2.5590811885978098, 0.09102597747017212]\n",
"[[8.48409813e-01 6.61664720e-19]\n",
" [4.08517211e-01 5.91482789e-01]]\n",
"\n",
"mean (23): [2.2925229858918237, 3.8600941677167215]\n",
"var (23): [2.5590811195045364, 0.09102595609334513]\n",
"[[8.48409808e-01 3.65427891e-20]\n",
" [4.08517177e-01 5.91482823e-01]]\n",
"\n",
"mean (24): [2.2925230262682406, 3.8600941954044554]\n",
"var (24): [2.559081090772119, 0.09102594720379605]\n",
"[[8.48409806e-01 2.01820581e-21]\n",
" [4.08517163e-01 5.91482837e-01]]\n",
"\n",
"mean (25): [2.2925230430587726, 3.860094206918401]\n",
"var (25): [2.559081078823743, 0.09102594350707681]\n",
"[[8.48409805e-01 1.11462617e-22]\n",
" [4.08517157e-01 5.91482843e-01]]\n",
"\n",
"mean (26): [2.292523050041117, 3.8600942117064783]\n",
"var (26): [2.55908107385501, 0.0910259419697957]\n",
"[[8.48409805e-01 6.15592084e-24]\n",
" [4.08517154e-01 5.91482846e-01]]\n",
"\n",
"mean (27): [2.2925230529447265, 3.8600942136976]\n",
"var (27): [2.559081071788762, 0.09102594133051709]\n",
"[[8.48409805e-01 3.39982702e-25]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (28): [2.2925230541521926, 3.860094214525609]\n",
"var (28): [2.559081070929512, 0.09102594106467299]\n",
"[[8.48409805e-01 1.87767584e-26]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (29): [2.292523054654318, 3.860094214869936]\n",
"var (29): [2.5590810705721925, 0.09102594095412166]\n",
"[[8.48409805e-01 1.03701351e-27]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (30): [2.2925230548631266, 3.8600942150131257]\n",
"var (30): [2.5590810704236024, 0.09102594090814888]\n",
"[[8.48409805e-01 5.72727731e-29]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (31): [2.29252305494996, 3.8600942150726705]\n",
"var (31): [2.55908107036181, 0.09102594088903106]\n",
"[[8.48409805e-01 3.16309335e-30]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (32): [2.292523054986069, 3.8600942150974324]\n",
"var (32): [2.559081070336114, 0.09102594088108093]\n",
"[[8.48409805e-01 1.74693122e-31]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (33): [2.292523055001086, 3.8600942151077295]\n",
"var (33): [2.559081070325428, 0.09102594087777484]\n",
"[[8.48409805e-01 9.64805129e-33]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (34): [2.2925230550073303, 3.8600942151120115]\n",
"var (34): [2.559081070320984, 0.09102594087640002]\n",
"[[8.48409805e-01 5.32848074e-34]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (35): [2.2925230550099274, 3.860094215113793]\n",
"var (35): [2.5590810703191362, 0.09102594087582833]\n",
"[[8.48409805e-01 2.94284371e-35]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (36): [2.292523055011007, 3.8600942151145334]\n",
"var (36): [2.5590810703183675, 0.09102594087559052]\n",
"[[8.48409805e-01 1.62529049e-36]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (37): [2.292523055011456, 3.8600942151148416]\n",
"var (37): [2.559081070318048, 0.09102594087549164]\n",
"[[8.48409805e-01 8.97624695e-38]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (38): [2.292523055011643, 3.860094215114969]\n",
"var (38): [2.5590810703179154, 0.09102594087545052]\n",
"[[8.48409805e-01 4.95745282e-39]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (39): [2.2925230550117206, 3.8600942151150224]\n",
"var (39): [2.5590810703178604, 0.09102594087543343]\n",
"[[8.48409805e-01 2.73793029e-40]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (40): [2.2925230550117526, 3.860094215115045]\n",
"var (40): [2.5590810703178373, 0.09102594087542634]\n",
"[[8.48409805e-01 1.51211974e-41]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (41): [2.2925230550117663, 3.860094215115054]\n",
"var (41): [2.559081070317828, 0.09102594087542336]\n",
"[[8.48409805e-01 8.35122109e-43]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (42): [2.2925230550117717, 3.8600942151150575]\n",
"var (42): [2.559081070317824, 0.09102594087542212]\n",
"[[8.48409805e-01 4.61225997e-44]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (43): [2.292523055011774, 3.860094215115059]\n",
"var (43): [2.5590810703178217, 0.09102594087542162]\n",
"[[8.48409805e-01 2.54728522e-45]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (44): [2.292523055011775, 3.8600942151150592]\n",
"var (44): [2.5590810703178217, 0.09102594087542144]\n",
"[[8.48409805e-01 1.40682920e-46]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (45): [2.2925230550117752, 3.8600942151150592]\n",
"var (45): [2.5590810703178213, 0.09102594087542136]\n",
"[[8.48409805e-01 7.76971646e-48]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (46): [2.2925230550117752, 3.86009421511506]\n",
"var (46): [2.5590810703178213, 0.09102594087542135]\n",
"[[8.48409805e-01 4.29110328e-49]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (47): [2.2925230550117752, 3.86009421511506]\n",
"var (47): [2.559081070317821, 0.0910259408754213]\n",
"[[8.48409805e-01 2.36991497e-50]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (48): [2.2925230550117757, 3.86009421511506]\n",
"var (48): [2.5590810703178213, 0.09102594087542129]\n",
"[[8.48409805e-01 1.30887015e-51]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n",
"mean (49): [2.2925230550117752, 3.8600942151150606]\n",
"var (49): [2.5590810703178213, 0.09102594087542129]\n",
"[[8.48409805e-01 7.22870263e-53]\n",
" [4.08517153e-01 5.91482847e-01]]\n",
"\n"
2020-12-31 19:30:39 +00:00
]
},
{
"output_type": "display_data",
"data": {
2021-01-01 18:53:11 +00:00
"text/plain": "<Figure size 1200x800 with 1 Axes>",
2021-01-05 11:10:29 +00:00
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"280.8pt\" version=\"1.1\" viewBox=\"0 0 424.8 280.8\" width=\"424.8pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <metadata>\n <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n <cc:Work>\n <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n <dc:date>2021-01-05T10:51:02.252762</dc:date>\n <dc:format>image/svg+xml</dc:format>\n <dc:creator>\n <cc:Agent>\n <dc:title>Matplotlib v3.3.3, https://matplotlib.org/</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs>\n <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 280.8 \nL 424.8 280.8 \nL 424.8 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.78125 243.24375 \nL 414.41875 243.24375 \nL 414.41875 22.318125 \nL 43.78125 22.318125 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <path clip-path=\"url(#p2b70c44e18)\" d=\"M 43.78125 243.24375 \nL 43.78125 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_2\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m106450c27e\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"43.78125\" xlink:href=\"#m106450c27e\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- − 4 -->\n <g transform=\"translate(36.410156 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 10.59375 35.5 \nL 73.1875 35.5 \nL 73.1875 27.203125 \nL 10.59375 27.203125 \nz\n\" id=\"DejaVuSans-8722\"/>\n <path d=\"M 37.796875 64.3125 \nL 12.890625 25.390625 \nL 37.796875 25.390625 \nz\nM 35.203125 72.90625 \nL 47.609375 72.90625 \nL 47.609375 25.390625 \nL 58.015625 25.390625 \nL 58.015625 17.1875 \nL 47.609375 17.1875 \nL 47.609375 0 \nL 37.796875 0 \nL 37.796875 17.1875 \nL 4.890625 17.1875 \nL 4.890625 26.703125 \nz\n\" id=\"DejaVuSans-52\"/>\n </defs>\n <use xlink:href=\"#DejaVuSans-8722\"/>\n <use x=\"83.789062\" xlink:href=\"#DejaVuSans-52\"/>\n </g>\n </g>\n </g>\n <g id=\"xtick_2\">\n <g id=\"line2d_3\">\n <path clip-path=\"url(#p2b70c44e18)\" d=\"M 105.554167 243.24375 \nL 105.554167 22.318125 \n\" style=\"fill:none;stroke:#b0b0b0;stroke-dasharray:2.96,1.28;stroke-dashoffset:0;stroke-width:0.8;\"/>\n </g>\n <g id=\"line2d_4\">\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"105.554167\" xlink:href=\"#m106450c27e\" y=\"243.24375\"/>\n </g>\n </g>\n <g id=\"text_2\">\n <!-- − 2 -->\n <g transform=\"translate(98.183073 257.842188)scale(0.1 -0.1)\">\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.10937
"image/png": "iVBORw0KGgoAAAANSUhEUgAABJsAAAMMCAYAAAD0M6ZoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAB7CAAAewgFu0HU+AAEAAElEQVR4nOzdd5xU1f3/8dfZvvQqyoKAgBVLFDQYUTQKahRN4tdYI3YT49dv1CQm/mI0VRNjjInGkgiYqLHEAmoMaqRYQLAgYEOadOl1+57fH2dm587svVN2p7Lv5+Mxj7lz77nnnpl75s7MZ04x1lpERERERERERETSoSjXBRARERERERERkd2Hgk0iIiIiIiIiIpI2CjaJiIiIiIiIiEjaKNgkIiIiIiIiIiJpo2CTiIiIiIiIiIikjYJNIiIiIiIiIiKSNgo2iYiIiIiIiIhI2ijYJCIiIiIiIiIiaaNgk4iIiIiIi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syT7qBSbzOEz3pb00i/due9Je0sY6MT+Y5pZDHxCTSJ3wdY9LUht4/nwFH+qT9H1xAPZz+23GOfZUnnQUe9zvXobTDgD8CY3y23ZLqeyuZfXB/bniv0Z8CR/ikOx8X+A+nm5xkfazBXVsuAExMuoNijv1QW+pWwPHHB6QZ7UkzLcl8i3CBJu9n6Zd80lXggpVNRK6tvi1xY8paH6p7l/u8VuUxj38TqoddAvI1uM/ULzz5HxPnuU1M9Jq1Zh8y//2jJvQcT/ZJdywuWBdOe3NAfs940jwFdA9IVwGcCtyXjnqqm266tf2mMZtERFJgjPka4B0z59U4yUtwXRq+ZWP+YbbWNllr60MPb8YFIcD9eBpjrf3MJ/2
2020-12-31 19:30:39 +00:00
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
2021-01-05 11:10:29 +00:00
"iterations = 50\n",
"\n",
"fig = plt.figure(dpi=fig_dpi, tight_layout=True)\n",
"ax = fig.add_subplot(1, 1, 1, xmargin=0, ymargin=0)\n",
2020-12-31 19:30:39 +00:00
"\n",
2021-01-05 11:10:29 +00:00
"iter_mean = [state1.mean, state2.mean]\n",
"iter_var = [state1.variance, state2.variance]\n",
"iter_state_transitions = state_transition\n",
2020-12-31 19:30:39 +00:00
"\n",
2021-01-05 11:10:29 +00:00
"ax.plot(x, [gaussian(i, iter_mean[0], sqrt(iter_var[0])) for i in x], '--', c='r', linewidth=1.0)\n",
"ax.plot(x, [gaussian(i, iter_mean[1], sqrt(iter_var[1])) for i in x], '--', c='b', linewidth=1.0)\n",
2020-12-31 19:30:39 +00:00
"\n",
2021-01-01 18:53:11 +00:00
"label1=None\n",
"label2=None\n",
"\n",
2020-12-31 19:30:39 +00:00
"for i in range(iterations):\n",
2021-01-05 11:10:29 +00:00
" iter_model = MarkovModel(states=[State(iter_mean[0], iter_var[0], state1.entry, state1.exit), \n",
" State(iter_mean[1], iter_var[1], state2.entry, state2.exit)],\n",
" observations=observations,\n",
" state_transitions=iter_state_transitions).populate()\n",
"\n",
" # NEW PARAMETERS\n",
" iter_mean = iter_model.reestimated_mean()\n",
" iter_var = iter_model.reestimated_variance()\n",
" iter_state_transitions[1:3, 1:3] = iter_model.reestimated_state_transitions()\n",
"\n",
" print(f\"mean ({i}): \", iter_mean)\n",
" print(f\"var ({i}): \", iter_var)\n",
" print(iter_model.reestimated_state_transitions())\n",
2020-12-31 19:30:39 +00:00
" print()\n",
"\n",
2021-01-05 11:10:29 +00:00
" state_1_y = [gaussian(i, iter_mean[0], sqrt(iter_var[0])) for i in x]\n",
" state_2_y = [gaussian(i, iter_mean[1], sqrt(iter_var[1])) for i in x]\n",
2020-12-31 19:30:39 +00:00
"\n",
" style = '--'\n",
" linewidth = 1.0\n",
" if i == iterations - 1:\n",
" style = '-'\n",
" linewidth = 2.0\n",
2021-01-01 18:53:11 +00:00
" label1='State 1'\n",
" label2='State 2'\n",
2020-12-31 19:30:39 +00:00
"\n",
2021-01-05 11:10:29 +00:00
" ax.plot(x, state_1_y, style, c='r', label=label1, linewidth=linewidth)\n",
" ax.plot(x, state_2_y, style, c='b', label=label2, linewidth=linewidth)\n",
2020-12-31 19:30:39 +00:00
"\n",
2021-01-05 11:10:29 +00:00
"ax.set_title(\"Probability Density Function Iterations\")\n",
2020-12-31 19:30:39 +00:00
"\n",
2021-01-05 11:10:29 +00:00
"ax.set_xlabel(x_label)\n",
"ax.set_ylabel(y_label)\n",
"ax.grid(linestyle=\"--\")\n",
"ax.legend()\n",
2020-12-31 19:30:39 +00:00
"\n",
2021-01-05 11:10:29 +00:00
"if fig_export:\n",
2021-01-01 18:53:11 +00:00
" savefig(\"report/res/iterated-pdfs.png\")\n",
2021-01-05 11:10:29 +00:00
"fig.show()\n"
2020-12-31 19:30:39 +00:00
]
},
{
"source": [
"# Baum-Welch State Transition Re-estimations"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
2021-01-01 18:53:11 +00:00
"execution_count": 17,
2020-12-31 19:30:39 +00:00
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
2021-01-05 11:10:29 +00:00
"[[0.92 0.06]\n [0.04 0.93]]\n[[8.37336439e-01 6.15623114e-50]\n [3.50509494e-01 6.49490506e-01]]\n"
2020-12-31 19:30:39 +00:00
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
2021-01-05 11:10:29 +00:00
"array([[8.37336439e-01, 6.15623114e-50],\n",
" [3.50509494e-01, 6.49490506e-01]])"
2020-12-31 19:30:39 +00:00
]
},
"metadata": {},
2021-01-01 18:53:11 +00:00
"execution_count": 17
2020-12-31 19:30:39 +00:00
}
],
"source": [
2021-01-01 18:53:11 +00:00
"model = MarkovModel(states=[state1, state2], \n",
" observations=observations, \n",
" state_transitions=state_transition).populate()\n",
2020-12-31 19:30:39 +00:00
"\n",
"print(a_matrix)\n",
2021-01-05 11:10:29 +00:00
"print(model.reestimated_state_transitions())\n",
2020-12-31 19:30:39 +00:00
"model.reestimated_state_transitions()"
2020-12-24 14:58:45 +00:00
]
2021-01-05 11:10:29 +00:00
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
2020-12-11 21:33:20 +00:00
}
]
}