Permalink
Browse files

ENH: make tests pass for python3

  • Loading branch information...
aflaxman committed Aug 31, 2017
1 parent 9c761aa commit 4b5d9e4a83bbba28147b3ae711cb80107e5e4522
Showing with 20 additions and 10 deletions.
  1. +6 −0 .travis.yml
  2. +0 −1 maze.py
  3. +7 −8 models.py
  4. +6 −0 requirements.txt
  5. +1 −1 views.py
View
@@ -0,0 +1,6 @@
language: python
python:
- "2.7"
- "3.6"
install: "pip install -r requirements.txt"
script: py.test test.py
View
@@ -7,7 +7,6 @@
import models
import views
reload(models); reload(views)
def random_maze(n=25):
G = models.my_grid_graph([n,n])
View
@@ -10,7 +10,6 @@
import networkx as nx
import random
import views
reload(views)
def my_grid_graph(shape):
""" Create an nxn grid graph, with uniformly random edge weights,
@@ -99,7 +98,7 @@ def BDST(G, root=(0,0), k=5, beta=1.):
@mc.stoch(dtype=nx.Graph)
def bdst(value=T, root=root, k=k, beta=beta):
path_len = pl.array(nx.shortest_path_length(value, root).values())
path_len = pl.array(list(nx.shortest_path_length(value, root).values()))
return -beta * pl.sum(path_len > k)
return bdst
@@ -121,7 +120,7 @@ def LDST(G, d=3, beta=1.):
@mc.stoch(dtype=nx.Graph)
def ldst(value=T, beta=beta):
return -beta * pl.sum(pl.array(T.degree().values()) >= d)
return -beta * pl.sum(pl.array(list(T.degree().values())) >= d)
return ldst
@@ -139,7 +138,7 @@ class STMetropolis(mc.Metropolis):
"""
def __init__(self, stochastic):
# Initialize superclass
mc.Metropolis.__init__(self, stochastic, scale=1., verbose=None, tally=False)
mc.Metropolis.__init__(self, stochastic, scale=1., verbose=0, tally=False)
def propose(self):
""" Add an edge and remove an edge from the cycle that it creates"""
@@ -186,10 +185,10 @@ def anneal_ldst(n=11, phases=10, iters=1000):
mod_mc.use_step_method(mc.NoStepper, beta)
for i in range(phases):
print 'phase %d' % (i+1),
print('phase %d' % (i+1),)
beta.value = i*5
mod_mc.sample(iters, burn=iters-1)
print 'frac of deg 2 vtx = %.2f' % pl.mean(pl.array(ldst.value.degree().values()) == 2)
print('frac of deg 2 vtx = %.2f' % pl.mean(pl.array(ldst.value.degree().values()) == 2))
return ldst.value
def anneal_bdst(n=11, depth=10, phases=10, iters=1000):
@@ -223,7 +222,7 @@ def max_depth(T=bdst, root=root):
for i in range(phases):
beta.value = i*5
mod_mc.sample(iters, thin=max(1, iters/100))
print 'cur depth', max_depth.value
print 'pct of trace with max_depth <= depth', pl.mean(mod_mc.trace(max_depth) <= depth)
print('cur depth', max_depth.value)
print('pct of trace with max_depth <= depth', pl.mean(mod_mc.trace(max_depth)[:] <= depth))
return bdst.value
View
@@ -0,0 +1,6 @@
numpy
matplotlib
pylab
pymc
networkx
Pillow
View
@@ -23,7 +23,7 @@ def plot_graph_and_tree(G, T, time):
pl.clf()
nx.draw_networkx_edges(G, G.pos, alpha=.75, width=.5, style='dotted')
nx.draw_networkx_edges(T, G.pos, alpha=.5, width=2)
X = pl.array(G.pos.values())
X = pl.array(list(G.pos.values()))
pl.plot(X[:,0], X[:,1], 'bo', alpha=.5)
pl.plot([G.pos[T.root][0]], [G.pos[T.root][1]], 'bo', ms=12, mew=4, alpha=.95)

0 comments on commit 4b5d9e4

Please sign in to comment.