In [2]:
%matplotlib inline
from matplotlib import pyplot as plt
import matplotlib.mlab as mlab
import csv
from scipy.stats import norm
import numpy as np
import scipy.stats as stats
In [3]:
data = open('../data/data.csv', 'r').readlines()
fieldnames = ['x', 'y', 'z', 'unmasked', 'synapses']
reader = csv.reader(data)
reader.next()
rows = [[int(col) for col in row] for row in reader]
In [43]:
sorted_y = sorted(list(set([r[1] for r in rows])))
sorted_z = sorted(list(set([r[2] for r in rows])))
# y vals = [1369, 1408, 1447, 1486, 1525, 1564, 1603, 1642, 1681,
#1720, 1759, 1798, 1837, 1876, 1915, 1954, 1993, 2032,
#2071, 2110, 2149, 2188, 2227, 2266, 2305, 2344, 2383,
#2422, 2461, 2500, 2539, 2578, 2617, 2656, 2695, 2734,
#2773, 2812, 2851, 2890, 2929, 2968, 3007, 3046, 3085,
#3124, 3163, 3202, 3241, 3280, 3319, 3358]
In [5]:
for i in sorted_y:
unmaskedSynapsesNoZero = ([r[-1] for r in rows if r[-2] != 0 if r[-1] !=0 if r[1] == i])
mean = np.mean(unmaskedSynapsesNoZero)
variance = np.var(unmaskedSynapsesNoZero)
plt.hist(unmaskedSynapsesNoZero, bins=50)
plt.title("Layer " + str(i))
plt.show()
print "Layer " + str(i) + " has a mean: " + str(mean) + " and variance: " + str(variance)
In [7]:
for i in sorted_y:
unmaskedSynapsesNoZero = ([r[-1] for r in rows if r[-2] != 0 if r[-1] !=0 if r[1] == i])
# best fit of data
(mu, sigma) = norm.fit(unmaskedSynapsesNoZero)
# the histogram of the data
n, bins, patches = plt.hist(unmaskedSynapsesNoZero, 60, normed=1, facecolor='green', alpha=0.75)
# add a 'best fit' line
y = mlab.normpdf( bins, mu, sigma)
l = plt.plot(bins, y, 'r--', linewidth=2)
#plot
plt.xlabel("Layer " + str(i))
plt.ylabel('Probability')
plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=%.3f,\ \sigma=%.3f$' %(mu, sigma))
plt.grid(True)
plt.show()
In [8]:
for i in sorted_y:
unmaskedSynapsesNoZero = ([r[-1] for r in rows if r[-2] != 0 if r[-1] !=0 if r[1] == i])
alpha, loc, beta=stats.gamma.fit(unmaskedSynapsesNoZero)
rv = stats.gamma(alpha,loc,beta)
h = plt.hist(unmaskedSynapsesNoZero, normed=True, bins=50)
x = np.linspace(0,400)
plt.plot(x, rv.pdf(x), lw=2)
plt.show()
In [13]:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
#print unmaskedSynapsesNoZero
x = []
y = []
z = []
val = []
for r in rows:
if r[-2] != 0:
if r[-1] !=0:
x.append(r[0])
y.append(r[1])
z.append(r[2])
ax.scatter(x, y, z, c='b')
plt.show()
In [21]:
#take into account for combined data
s = []
for r in rows:
if r[-2] != 0:
if r[-1] !=0:
s.append(float(r[-1])/float(r[-2]))
#GAUSSIAN
# best fit of data normal curve (gaussian)
(mu, sigma) = norm.fit(s)
# the histogram of the data
n, bins, patches = plt.hist(s, 60, normed=1, facecolor='green', alpha=0.75)
# add a 'best fit' line
y = mlab.normpdf( bins, mu, sigma)
l = plt.plot(bins, y, 'r--', linewidth=2)
plt.show()
In [24]:
#take into account unmasked for each layer
for i in sorted_y:
s = []
for r in rows:
if r[-2] != 0:
if r[-1] !=0:
if r[1] == i:
s.append(float(r[-1])/float(r[-2]))
#GAUSSIAN
# best fit of data normal curve (gaussian)
(mu, sigma) = norm.fit(s)
# the histogram of the data
n, bins, patches = plt.hist(s, 100, normed=1, facecolor='green', alpha=0.75)
# add a 'best fit' line
y = mlab.normpdf( bins, mu, sigma)
l = plt.plot(bins, y, 'r--', linewidth=2)
#GAMMA
#alpha, loc, beta=stats.gamma.fit(s)
#print alpha, loc, beta
#rv = stats.gamma(alpha,loc,beta)
#x = np.linspace(0,.005)
#plt.plot(x, rv.pdf(x), lw=3)
plt.title("Layer " + str(i))
plt.show()
In [42]:
import matplotlib
#print unmaskedSynapsesNoZero
allVal = []
for r in rows:
if r[-2] != 0:
if r[-1] !=0:
allVal.append(r[-1])
norm = matplotlib.colors.Normalize(vmin = np.min(allVal), vmax = np.max(allVal), clip = False)
for i in sorted_y:
x = []
z = []
val = []
for r in rows:
if r[-2] != 0:
if r[-1] !=0:
if r[1] == i:
x.append(r[0])
z.append(r[2])
val.append(r[-1])
plt.scatter(x,z,s = 100, c = val,norm=norm)
plt.show()
In [50]:
allVal = []
for r in rows:
if r[-2] != 0:
if r[-1] !=0:
allVal.append(float(r[-1])/r[-2])
norm = matplotlib.colors.Normalize(vmin = np.min(allVal), vmax = np.max(allVal), clip = False)
for i in sorted_z:
x = []
y = []
val = []
for r in rows:
if r[-2] != 0:
if r[-1] !=0:
if r[2] == i:
x.append(r[0])
y.append(r[1])
val.append(float(r[-1])/r[-2])
plt.scatter(x,y,s = 10, c = val,norm=norm)
plt.show()
In [ ]: