Skip to content

Instantly share code, notes, and snippets.

@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
@sl8r000
sl8r000 / Theorem2_1_1.txt
Created November 24, 2012 22:37
Theorem 2.1 Output 1
$ python Theorem2_1.py 0 10
1.7
$ python Theorem2_1.py 0 100
1.88
$ python Theorem2_1.py 0 1000
1.832
$ python Theorem2_1.py 0 10000
1.8291
$ python Theorem2_1.py 0 100000
1.81673
@sl8r000
sl8r000 / login.txt
Created December 1, 2012 20:04
Non-Archimedean PDFs
Slaters-MacBook-Pro:~ sstich$ ssh ubuntu@ec2-184-73-13-20.compute-1.amazonaws.com
ubuntu@ec2-184-73-13-20.compute-1.amazonaws.com's password:
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-31-virtual x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Sat Dec 1 19:59:27 UTC 2012
System load: 0.0 Processes: 58
Usage of /: 11.3% of 7.87GB Users logged in: 0
import math
class NearestNeighbor(object):
def __init__(self):
self._known_rows = []
def learn_from_row(self, row):
self._known_rows.append(row)
def predict_missing_column(
import urllib2
import json
import time
class QueryBuilder(object):
BASE_URL = 'https://api.twitter.com/1/statuses/user_timeline.json?'
DEFAULT_MAX_COUNT = 200
def __init__(self):
self._query_params = dict()
import random
import twitter_grab
SCREEN_NAMES = [
'GineokwKoenig',
'RealNichelle',
'TheRealNimoy',
'WilliamShatner',
'GeorgeTakei',
import os
import sys
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
if not path in sys.path:
sys.path.insert(1, path)
del path
import knn
from knn.nearest_neighbor1 import NearestNeighbor