Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Insight Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
@sl8r000
sl8r000 / live_run.ipynb
Created May 13, 2015 16:42
Insight Example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 154,
"metadata": {
"collapsed": false
},
"outputs": [
{
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sl8r000
sl8r000 / markov.py
Created November 24, 2012 04:43
Simple Markov
import sys
import random
if __name__ == "__main__":
state, num_steps = sys.argv[1], int(sys.argv[2])
count = dict()
count['a'], count['b'] = 0, 0
for i in range(num_steps):
count[state] += 1
@sl8r000
sl8r000 / gist:4138528
Created November 24, 2012 05:13
Simple Markov Output
$ python markov.py a 100
a 0.72
b 0.28
$ python markov.py a 200
a 0.74
b 0.26
$ python markov.py a 1000
a 0.748
b 0.252
$ python markov.py a 10000
@sl8r000
sl8r000 / Simple_Markov_Matrix.txt
Created November 24, 2012 05:37
Simple Markov Matrix
$ python
>>> import numpy
>>> P = array([[1.0/3, 2.0/3], [1.0/4, 3.0/4]])
>>> P
array([[ 0.33333333, 0.66666667],
[ 0.25 , 0.75 ]])
>>> numpy.linalg.matrix_power(P, 2)
array([[ 0.27777778, 0.72222222],
[ 0.27083333, 0.72916667]])
>>> numpy.linalg.matrix_power(P, 3)
@sl8r000
sl8r000 / Theorem2_1.py
Created November 24, 2012 22:34
Theorem 2.1
import sys
import random
from numpy import *
import time
class Markov(object):
def __init__(self, transition_matrix, start_state):
self.P = transition_matrix
self.state = start_state