Skip to content

Commit

Permalink
Modification to testing
Browse files Browse the repository at this point in the history
  • Loading branch information
h-mayorquin committed Oct 17, 2016
1 parent 0d29a5f commit 558eb7e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 244 deletions.
50 changes: 0 additions & 50 deletions connectivity_visualization.py

This file was deleted.

2 changes: 2 additions & 0 deletions convergence_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,7 @@ def calculate_convergence_ratios(nn, N, time, patterns):
# Let's calculate how many of the patterns ended up in the one that they started closer too
fraction_of_well_behaviour = [start - end for start, end in zip(closest_pattern_start, closest_pattern_end)].count(0)
fraction_of_well_behaviour = fraction_of_well_behaviour * 1.0 / N
# import IPython
# IPython.embed()

return fraction_of_convergence, fraction_of_well_behaviour
8 changes: 4 additions & 4 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def __init__(self, hypercolumns, minicolumns, beta=None, w=None, o=None, s=None,
self.w = np.zeros((self.n_units, self.n_units))



# Set the adaptation to zeros by default
self.a = np.zeros_like(self.o)
# Set the clamping to zero by defalut
Expand All @@ -97,7 +96,7 @@ def empty_history(self):
'p_post': empty_array, 'p_co': empty_array_square, 'w': empty_array_square,
'beta': empty_array}

def reset_values(self):
def reset_values(self, keep_connectivity=False):
self.o = np.ones(self.n_units) * (1.0 / self.minicolumns)
self.s = np.log(np.ones(self.n_units) * (1.0 / self.minicolumns))
self.z_pre = np.ones_like(self.o) * (1.0 / self.minicolumns)
Expand All @@ -108,8 +107,9 @@ def reset_values(self):

self.a = np.zeros_like(self.o)

self.beta = np.log(np.ones_like(self.o) * (1.0 / self.minicolumns))
self.w = np.zeros((self.n_units, self.n_units))
if not keep_connectivity:
self.beta = np.log(np.ones_like(self.o) * (1.0 / self.minicolumns))
self.w = np.zeros((self.n_units, self.n_units))

def randomize_pattern(self):
self.o = self.prng.rand(self.n_units)
Expand Down
64 changes: 37 additions & 27 deletions notebooks/2016-10-01(Convergence Properties).ipynb

Large diffs are not rendered by default.

172 changes: 10 additions & 162 deletions play.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,170 +5,18 @@
import matplotlib.gridspec as gridspec
from mpl_toolkits.axes_grid1 import make_axes_locatable

from connectivity_functions import get_beta, get_w
from connectivity_functions import calculate_probability, calculate_coactivations
from data_transformer import build_ortogonal_patterns
from network import BCPNN
from connectivity_functions import softmax

np.set_printoptions(suppress=True)

hypercolumns = 3
minicolumns = 3
x = 0
points = np.logspace(0, 4, num=1000)
distance = np.zeros_like(points)

patterns_dic = build_ortogonal_patterns(hypercolumns, minicolumns)
patterns = list(patterns_dic.values())
for index, y in enumerate(points):
print(y)
array = np.array((x, y))
aux = softmax(array, minicolumns=2)
distance[index] = np.linalg.norm(aux[0] - aux[1])

P = calculate_coactivations(patterns)
p = calculate_probability(patterns)

w = get_w(P, p)
beta = get_beta(p)

dt = 0.001
T_simulation = 10.0
T_training = 1.0
simulation_time = np.arange(0, T_simulation + dt, dt)
training_time = np.arange(0, T_simulation + dt, dt)

prng = np.random.RandomState(seed=0)

tolerance = 1e-5

g_a_set = np.arange(0, 110, 10)
g_beta_set = np.arange(0, 22, 2)
g_w_set = np.arange(0, 12, 2)

nn = BCPNN(hypercolumns, minicolumns, beta, w, g_a=1, g_beta=1.0, g_w=1.0, g_I=10.0, prng=prng)


if False:
for pattern in reversed(patterns):
I = pattern
nn.randomize_pattern()
print('---------')
print('I')
print(I)
# Run the network for one minut clamped to the patternr
nn.k = 1.0
nn.run_network_simulation(training_time, I=I)
# Run the network free
print('---------')
print('This should look like I')
print(nn.o)
nn.k = 0.0
nn.run_network_simulation(training_time)
print('---------')
print('---------')
print(nn.o)


if True:
nn.randomize_pattern()
nn.k = 1.0
history = nn.run_network_simulation(training_time, save=True, I=patterns[0])
nn.run_network_simulation(training_time, save=True, I=None)
history = nn.run_network_simulation(training_time, save=True, I=patterns[1])
history = nn.run_network_simulation(training_time, save=True, I=patterns[2])

o = history['o']
s = history['s']
z_pre = history['z_pre']
p_pre = history['p_pre']
p_post = history['p_post']
p_co = history['p_co']
beta = history['beta']
w = history['w']
adaptation = history['a']

fig = plt.figure(figsize=(16, 12))

ax1 = fig.add_subplot(221)
im1 = ax1.imshow(o, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax1)
cax1 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im1, cax=cax1, ax=ax1)

ax2 = fig.add_subplot(222)
im2 = ax2.imshow(z_pre, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax2)
cax2 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im2, cax=cax2, ax=ax2)

ax3 = fig.add_subplot(223)
im3 = ax3.imshow(adaptation, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax3)
cax3 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im3, cax=cax3, ax=ax3)

ax4 = fig.add_subplot(224)
im4 = ax4.imshow(p_pre, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax4)
cax4 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im4, cax=cax4, ax=ax4)

plt.show()

if False:
nn.randomize_pattern()
nn.k = 1.0

history = nn.run_network_simulation(training_time, save=True, I=patterns[0])
o = history['o']
s = history['s']
z_pre = history['z_pre']
p_pre = history['p_pre']
p_post = history['p_post']
p_co = history['p_co']
beta = history['beta']
w = history['w']
adaptation = history['a']

history = nn.run_network_simulation(training_time, save=True, I=patterns[1])
o = np.concatenate((o, history['o']))
s = np.concatenate((s, history['s']))
z_pre = np.concatenate((z_pre, history['z_pre']))
p_pre = np.concatenate((p_pre, history['p_pre']))
p_post = history['p_post']
p_co = history['p_co']
beta = history['beta']
w = history['w']
adaptation = np.concatenate((adaptation, history['a']))

history = nn.run_network_simulation(training_time, save=True, I=patterns[2])
o = np.concatenate((o, history['o']))
s = np.concatenate((s, history['s']))
z_pre = np.concatenate((z_pre, history['z_pre']))
p_pre = np.concatenate((p_pre, history['p_pre']))
p_post = history['p_post']
p_co = history['p_co']
beta = history['beta']
w = history['w']
adaptation = np.concatenate((adaptation, history['a']))

fig = plt.figure(figsize=(16, 12))

ax1 = fig.add_subplot(221)
im1 = ax1.imshow(o, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax1)
cax1 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im1, cax=cax1, ax=ax1)

ax2 = fig.add_subplot(222)
im2 = ax2.imshow(z_pre, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax2)
cax2 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im2, cax=cax2, ax=ax2)

ax3 = fig.add_subplot(223)
im3 = ax3.imshow(adaptation, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax3)
cax3 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im3, cax=cax3, ax=ax3)

ax4 = fig.add_subplot(224)
im4 = ax4.imshow(p_pre, aspect='auto', interpolation='None', cmap='viridis', vmax=1, vmin=0)
divider = make_axes_locatable(ax4)
cax4 = divider.append_axes('right', size='5%', pad=0.05)
fig.colorbar(im4, cax=cax4, ax=ax4)

plt.show()
plt.plot(points, distance)
2 changes: 1 addition & 1 deletion test_convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_basic_convergence(self):
w = get_w(P, p)
beta = get_beta(p)

dt = 0.01
dt = 0.001
T = 1
time = np.arange(0, T + dt, dt)

Expand Down

0 comments on commit 558eb7e

Please sign in to comment.