This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import twitter_grab | |
SCREEN_NAMES = [ | |
'GineokwKoenig', | |
'RealNichelle', | |
'TheRealNimoy', | |
'WilliamShatner', | |
'GeorgeTakei', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer