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
def traverse(g, node, bfs=True): | |
s = Staq() | |
s.insert(node) | |
scheduled = set([node]) | |
while s.size > 0: | |
node = s.pop(head=bfs, val=True) | |
print(node) | |
neighbors = g[node] |
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
class StaqNode: | |
def __init__(self, val=None, left=None, right=None): | |
self.val = val | |
self.left = left | |
self.right = right | |
class Staq: | |
def __init__(self): | |
self.head = None | |
self.tail = None |
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 pymc3 as pm | |
from theano import tensor as tt | |
import arviz as az | |
import numpy as np | |
scores = np.array([1,1,1,0,0,0 | |
]).flatten() | |
games = [(0,1), (0,2), (0,3), | |
(1,2), (1,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 pymc3 as pm | |
from theano import tensor as tt | |
import arviz as az | |
import numpy as np | |
# Binary, correct answer array | |
scores = np.array([1,1,1,0,0,0 | |
]).flatten() | |
# (student:question) tuples |
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 pymc3 as pm | |
from theano import tensor as tt | |
import arviz as az | |
import numpy as np | |
# Binary, correct answer array | |
scores = np.array([1,1,1,0,0,0 | |
]).flatten() | |
# (student:question) tuples |
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 pymc3 as pm | |
from theano import tensor as tt | |
import arviz as az | |
import numpy as np | |
# Binary, correct answer array | |
scores = np.array([1,1,1,0,0,0 | |
]).flatten() | |
# (student:question) tuples |
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
def rev_posterior(samples=100, size=len(X)): | |
for s in range(samples): | |
idx = random.choice(range(size)) | |
m = trace.get_values('m')[idx] | |
b = trace.get_values('b')[idx] | |
rev = X * np.exp(m*X +b) | |
plt.plot(X, rev) | |
return | |
# rev_posterior() |
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 | |
def post_plot(trace_obj=trace,samples=100,size=len(X)): | |
for itr in range(samples): | |
idx = random.choice(range(size)) | |
m = trace_obj.get_values('m')[idx] | |
b = trace_obj.get_values('b')[idx] | |
Y_hat = np.exp(m*X + b) | |
plt.plot(X,Y_hat) | |
plt.scatter(X,Y) |
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 pymc3 as pm | |
with pm.Model() as model: | |
m = pm.Normal('m',mu=0, sd=2) | |
b = pm.Normal('b',mu=0, sd=2) | |
s = pm.Exponential('s',lam=1) | |
y_hat = pm.math.dot(m, X) + b | |
lik = pm.Normal('lik', mu=y_hat, observed=pm.math.log(Y), sigma=s) | |
trace = pm.sample(chains=4) |
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 numpy as np | |
sd = 0.5 | |
m,b = -0.25, 5 | |
X = np.linspace(0,20,100) | |
Y = np.exp(np.random.normal(loc=m*X+b, scale=sd)) | |
import matplotlib.pyplot as plt | |
plt.scatter(X,Y) | |
Y_hat = np.exp(m*X+b) | |
plt.plot(X,Y_hat, color='r') |
NewerOlder