<jupyter_start><jupyter_text>Training disconnected and connected patternsIn this notebook I will implement the next training scheme. First we will traing a couple of disconnected patterns with some space between them and then a sequence without space between them so that they can connect.<jupyter_code>from __future__ import print_function
import pprint
import subprocess
import sys 
sys.path.append('../')

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from mpl_toolkits.axes_grid1 import make_axes_locatable

from network import BCPNN, NetworkManager
from data_transformer import build_ortogonal_patterns
from analysis_functions import calculate_angle_from_history
from analysis_functions import calculate_winning_pattern_from_distances, calculate_patterns_timings

%matplotlib inline
matplotlib.rcParams.update({'font.size': 22})

np.set_printoptions(suppress=True, precision=2)<jupyter_output><empty_output><jupyter_text>GitThen we run the git files<jupyter_code>run_old_version = False
if run_old_version:
    hash_when_file_was_written = '127d8b9e08a368243e1775da92c304e74fc551e7'
    hash_at_the_moment = subprocess.check_output(["git", 'rev-parse', 'HEAD']).strip()
    print('Actual hash', hash_at_the_moment)
    print('Hash of the commit used to run the simulation', hash_when_file_was_written)
    subprocess.call(['git', 'checkout', hash_when_file_was_written])<jupyter_output><empty_output><jupyter_text>Network building and training<jupyter_code>hypercolumns = 4
minicolumns = 10
n_patterns = 10  # Number of patterns

patterns_dic = build_ortogonal_patterns(hypercolumns, minicolumns)
patterns = list(patterns_dic.values())
patterns = patterns[:n_patterns]

# BCPNN network
nn = BCPNN(hypercolumns, minicolumns)

# Network manager
dt = 0.001
T_training = 1.0
training_time = np.arange(0, T_training + dt, dt)

T_rest = 1.0
time_rest = np.arange(0, T_rest + dt, dt)

values_to_save = ['o', 'a', 'z_pre', 'p_pre']
manager = NetworkManager(nn=nn, values_to_save=values_to_save)<jupyter_output><empty_output><jupyter_text>Now we train the network with the different parameters<jupyter_code>for pattern in patterns[0:6]:
    nn.k = 1.0
    manager.run_network(time=training_time, I=pattern)
    nn.k = 0.0
    manager.run_network(time=time_rest, I=None)

for pattern in patterns[6:]:
    nn.k = 1.0
    manager.run_network(time=training_time, I=pattern)<jupyter_output><empty_output><jupyter_text>We plot the training<jupyter_code>history = manager.history

cmap = 'plasma'
extent = [0, minicolumns * hypercolumns, n_patterns * T_training, 0]

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

ax1 = fig.add_subplot(221)
im1 = ax1.imshow(history['o'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax1.set_title('Unit activation')

ax2 = fig.add_subplot(222)
im2 = ax2.imshow(history['z_pre'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax2.set_title('Traces of activity (z)')

ax3 = fig.add_subplot(223)
im3 = ax3.imshow(history['a'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax3.set_title('Adaptation')

ax4 = fig.add_subplot(224)
im4 = ax4.imshow(history['p_pre'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax4.set_title('Probability')

fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85, 0.12, 0.05, 0.79])
fig.colorbar(im1, cax=cbar_ax)<jupyter_output><empty_output><jupyter_text>Network recall<jupyter_code>nn.k = 0
manager.empty_history()
T_recalling = 10.0
time_recalling = np.arange(0, T_recalling + dt, dt)

manager.run_network(time=time_recalling)

history = manager.history<jupyter_output><empty_output><jupyter_text>Plot the recalling<jupyter_code>cmap = 'plasma'
extent = [0, minicolumns * hypercolumns, T_recalling, 0]

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

ax1 = fig.add_subplot(221)
im1 = ax1.imshow(history['o'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax1.set_title('Unit activation')

ax2 = fig.add_subplot(222)
im2 = ax2.imshow(history['z_pre'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax2.set_title('Traces of activity (z)')

ax3 = fig.add_subplot(223)
im3 = ax3.imshow(history['a'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax3.set_title('Adaptation')

ax4 = fig.add_subplot(224)
im4 = ax4.imshow(history['p_pre'], aspect='auto', interpolation='None', cmap=cmap, vmax=1, vmin=0, extent=extent)
ax4.set_title('Probability')

fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85, 0.12, 0.05, 0.79])
fig.colorbar(im1, cax=cbar_ax)<jupyter_output><empty_output><jupyter_text>Restore git<jupyter_code>if run_old_version:
    subprocess.call(['git', 'checkout', 'master'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12961055017514939, 'fraction_numerical': 0.036060168967648874, 'mean_word_length': 7.471204188481676, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '388549', 'license': 'MIT', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1804, 'n_words': 357, 'path': 'notebooks/2016-10-31(Training disconnected and connected patterns).ipynb', 'repo_name': 'h-mayorquin/attractor_sequences', 'size': '4853'}