<commit_before>{
 "metadata": {
  "name": "",
  "signature": "sha256:d7af98f5d5248adaaa0c934d8f9f81216508742a9c5beab4c481db938d3138e0"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Discrete hidden Markov model"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from bayespy.nodes import CategoricalMarkovChain, Categorical, Mixture\n",
      "N = 100\n",
      "# Initial state probabilities\n",
      "a0 = [0.6, 0.4]\n",
      "# State transition probabilities\n",
      "A = [[0.7, 0.3],[0.4,0.6]]\n",
      "# Markov chain\n",
      "Z = CategoricalMarkovChain(a0, A, states=N)\n",
      "# Emission probabilities\n",
      "P = [[0.1, 0.4, 0.5], [0.6, 0.3, 0.1]]\n",
      "# Observed process\n",
      "Y = Mixture(Z, Categorical, P)\n",
      "# Generate dummy data\n",
      "import numpy as np\n",
      "data = np.random.randint(3, size=N)\n",
      "# Observe data\n",
      "Y.observe(data)\n",
      "\n",
      "from bayespy.inference import VB\n",
      "Q = VB(Y, Z)\n",
      "\n",
      "Q.update()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Iteration 1: loglike=-1.126645e+02 (0.035 seconds)\n"
       ]
      }
     ],
     "prompt_number": 1
    }
   ],
   "metadata": {}
  }
 ]
}<commit_msg>DOC: Writing the discrete HMM IPython notebook<commit_after>{
 "metadata": {
  "name": "",
  "signature": "sha256:16d43e91be3052dda240f42cb920f9f0215acf08aa99850815373a80b2ad3394"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Discrete hidden Markov model"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from bayespy.nodes import CategoricalMarkovChain, Categorical, Mixture\n",
      "N = 100\n",
      "# Initial state probabilities\n",
      "a0 = [0.6, 0.4]\n",
      "# State transition probabilities\n",
      "A = [[0.7, 0.3],[0.4,0.6]]\n",
      "# Markov chain\n",
      "Z = CategoricalMarkovChain(a0, A, states=N)\n",
      "# Emission probabilities\n",
      "P = [[0.1, 0.4, 0.5], [0.6, 0.3, 0.1]]\n",
      "# Observed process\n",
      "Y = Mixture(Z, Categorical, P)\n",
      "# Generate dummy data\n",
      "import numpy as np\n",
      "data = np.random.randint(3, size=N)\n",
      "# Observe data\n",
      "Y.observe(data)\n",
      "\n",
      "from bayespy.inference import VB\n",
      "Q = VB(Y, Z)\n",
      "\n",
      "Q.update()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Iteration 1: loglike=-1.106996e+02 (0.035 seconds)\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Q = VB(a0, A, P, Y)\n",
      "Q.update(repeat=20)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "ename": "ValueError",
       "evalue": "Argument number 1 is not a node",
       "output_type": "pyerr",
       "traceback": [
        "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
        "\u001b[1;32m<ipython-input-2-a88fa17b34cd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mQ\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mVB\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mA\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mP\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mY\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mQ\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m20\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
        "\u001b[1;32m/home/jluttine/workspace/bayespy/bayespy/inference/vmp/vmp.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, tol, autosave_iterations, autosave_filename, callback, *nodes)\u001b[0m\n\u001b[0;32m     45\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mind\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnode\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnodes\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     46\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 47\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Argument number %d is not a node\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mind\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     48\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     49\u001b[0m         \u001b[1;31m# Remove duplicate nodes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
        "\u001b[1;31mValueError\u001b[0m: Argument number 1 is not a node"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from bayespy.nodes import CategoricalMarkovChain, Categorical, Mixture, Dirichlet\n",
      "N = 100\n",
      "# Initial state probabilities\n",
      "a0 = Dirichlet([20,10])\n",
      "# State transition probabilities\n",
      "A = Dirichlet([[8,2], [2,8]])\n",
      "# Markov chain\n",
      "Z = CategoricalMarkovChain(a0, A, states=N)\n",
      "# Emission probabilities\n",
      "P = Dirichlet([[3,4,3], [10,6,4]])\n",
      "# Observed process\n",
      "Y = Mixture(Z, Categorical, P)\n",
      "# Generate dummy data\n",
      "import numpy as np\n",
      "data = np.random.randint(3, size=N)\n",
      "# Observe data\n",
      "Y.observe(data)\n",
      "\n",
      "Q = VB(Y, Z, A, a0, P)\n",
      "Q.update(repeat=20)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Iteration 1: loglike=-1.140762e+02 (0.038 seconds)\n",
        "Iteration 2: loglike=-1.139522e+02 (0.038 seconds)\n",
        "Iteration 3: loglike=-1.138965e+02 (0.038 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 4: loglike=-1.138709e+02 (0.039 seconds)\n",
        "Iteration 5: loglike=-1.138586e+02 (0.037 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 6: loglike=-1.138523e+02 (0.037 seconds)\n",
        "Iteration 7: loglike=-1.138488e+02 (0.037 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 8: loglike=-1.138467e+02 (0.037 seconds)\n",
        "Iteration 9: loglike=-1.138454e+02 (0.037 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 10: loglike=-1.138445e+02 (0.037 seconds)\n",
        "Iteration 11: loglike=-1.138439e+02 (0.036 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 12: loglike=-1.138434e+02 (0.037 seconds)\n",
        "Iteration 13: loglike=-1.138431e+02 (0.037 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 14: loglike=-1.138429e+02 (0.036 seconds)\n",
        "Iteration 15: loglike=-1.138428e+02 (0.037 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 16: loglike=-1.138427e+02 (0.038 seconds)\n",
        "Iteration 17: loglike=-1.138426e+02 (0.038 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 18: loglike=-1.138425e+02 (0.037 seconds)\n",
        "Iteration 19: loglike=-1.138425e+02 (0.037 seconds)"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Iteration 20: loglike=-1.138425e+02 (0.038 seconds)\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}
{'fraction_non_alphanumeric': 0.2080295826730058, 'fraction_numerical': 0.13681986265187532, 'mean_word_length': 2.2675181221953746, 'pattern_counts': {'":': 104, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3506520', 'n_tokens_mistral': 4770, 'n_tokens_neox': 4095, 'n_words': 559}