In [1]:
from ipythonblocks import BlockGrid as bg
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
import random
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import Image
In [2]:
def array_city(x, p1, p2):
p0 = 1-(p1+p2)
p1 = 1-(p0+p2)
p2 = 1-(p0+p1)
grid = (np.random.choice([0, 1 , 2], size = (x, x), p = [p0, p1, p2]))
return grid
In [3]:
def visualize(grid):
g = bg(grid.shape[0], grid.shape[0])
for row in range(g.height):
for col in range(g.width):
block = g[row,col]
if grid[row,col] == 0:
block.blue = 1000
block.red = 1000
block.green = 1000
if grid[row,col] == 1:
block.blue = 2000
block.red = 0
block.green = 0
if grid[row,col] == 2:
block.red = 2000
block.green = 0
block.blue = 0
return g
In [4]:
def visualize_big(grid):
g = bg(grid.shape[0], grid.shape[0],block_size = 5)
for row in range(g.height):
for col in range(g.width):
block = g[row,col]
if grid[row,col] == 0:
block.blue = 1000
block.red = 1000
block.green = 1000
if grid[row,col] == 1:
block.blue = 2000
block.red = 0
block.green = 0
if grid[row,col] == 2:
block.red = 2000
block.green = 0
block.blue = 0
return g
In [5]:
g = array_city(90,0.1,0.1)
visualize_big(g)
Out[5]:
Example of low amount of empty squares
In [7]:
g = array_city(90,0.45,0.45)
visualize_big(g)
Out[7]:
In [8]:
def empties(Positive,Inverse):
print("Do you think the amount of empties has a positive or Inverse relationship with the amount of loops required grid to reach satisfaction?")
if Positive == True:
print ('Incorrect')
if Inverse == True:
print('Correct!')
In [9]:
interact(empties, Positive = False, Inverse = False);
In [10]:
#data
p0 = [0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8]
loops = [138,125,107,99,93,81,63,59,56,38,23,18,15,10,8]
In [11]:
#percent of empties in 40x40 grid at 20% satisfaction
plt.figure(figsize=(15,5))
plt.xlim(0.1, 0.8)
plt.plot(p0, loops)
plt.grid(True)
plt.xlabel('Percent of Empty Boxes')
plt.ylabel('Number of Loops')
plt.title('Empties vs. Loops');
In [12]:
#Example of small difference
g = array_city(100,0.45,0.45)
visualize_big(g)
Out[12]:
Example of large difference between reds and blues
In [13]:
#Example of large difference
g = array_city(100,0.1,0.8)
visualize_big(g)
Out[13]:
In [14]:
def difference(Positive,Inverse):
print("Do you think the difference between reds and blues has a positive or Inverse relationship with the amount of loops required grid to reach satisfaction?")
if Positive == True:
print ('Correct!')
if Inverse == True:
print('Incorrect')
In [15]:
interact(difference, Positive = False, Inverse = False);
In [16]:
diff = [0.1,0.2,0.3,0.4,0.5,0.6,0.7]
loops = [51,55,58,90,92,93,95]
In [17]:
#difference between p1 and p2 in 40x40 grid at 20% satisfaction
plt.figure(figsize=(15,5))
plt.grid(True)
plt.plot(diff, loops)
plt.xlabel('Difference between reds and blues')
plt.ylabel('Number of Loops')
plt.title('Difference vs. Loops');
In [18]:
g = array_city(5,0.5,0.5)
visualize(g)
Out[18]:
Example of large grid
In [19]:
g = array_city(150,0.4,0.4)
visualize_big(g)
Out[19]: