<jupyter_start><jupyter_text>Spreizer network in the Emulatorby <NAME> on December 3rd, 2021This is a demonstration of the Spreizer network implementation in the [Brian2Loihi Emulator](https://github.com/sagacitysite/brian2_loihi). It is based on [Leo Hiselius's Brian2 implementation of the Spreizer network](https://github.com/leohiselius/spreizer-net).  Imports<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
from brian2_loihi import *
from loihi_spreizer_net import *
from utils import get_root, make_animation<jupyter_output><empty_output><jupyter_text>Parameters<jupyter_code>root = get_root()                              # Get the absolute path
data_dir = root + '/saves/spike_monitors/'     # Where to store spike data
nPopE = params.network_dimensions['n_pop_e']   # Number of excitatory neurons in network
seed_value = 1                                 # Set seed, determines e.g. Perlin map
simtime = 1000                                 # Simulation time, Loihi timesteps
N = 1000                                       # Number of input neurons in spike generator
r = 200                                        # Firing rate of input neurons
T = simtime                                    # Input arrives throughout entire simulation<jupyter_output><empty_output><jupyter_text>Define Loihi Spreizer network<jupyter_code>sn = LoihiSpreizerNet()                 # instantiate loihi spreizer net object
sn.set_seed(seed_value)                 # set the seed for e.g. perlin map
sn.populate()                           # populates the network with neurons on torus
sn.connect()                            # makes recurrent connections according to Perlin map
sn.connect_spike_generator(N, r, T)     # connect a spike generator with N neurons, firing rate r, time (0,T)
sn.connect_spike_monitors()             # connect the spike monitors<jupyter_output><empty_output><jupyter_text>Run simulation and save data<jupyter_code>sn.run_sim(simulation_time=simtime)  
sn.save_monitors('loihi_spreizer_test')<jupyter_output><empty_output><jupyter_text>Build spike rasters<jupyter_code># first we build the spike raster, defining a window inside which spikes are summed
window = 20
n_bins = int(simtime/window)
spk_raster = np.zeros((nPopE, n_bins))
gs = np.load(data_dir + 'loihi_spreizer_test_e_i.npy')
ts = np.load(data_dir + 'loihi_spreizer_test_e_t.npy')
for j in range(n_bins): 
    mask = (ts>(j*window)) & (ts<((j+1)*window))
    spks = gs[mask]  
    spk_raster[:, j] = np.bincount(spks, minlength=nPopE)<jupyter_output><empty_output><jupyter_text>Plot example<jupyter_code>plt.figure()
plt.imshow(spk_raster, aspect='auto')
plt.colorbar()
plt.show()
plt.figure()
plt.scatter(ts[np.arange(0,len(ts),200)], gs[np.arange(0,len(ts),200)])
plt.xlim(0,simtime)
plt.ylim(0,nPopE)
plt.show()<jupyter_output><empty_output><jupyter_text>AnimationMake video of activity in 2D space<jupyter_code>binsize = 10
fps = 10

gs = np.load(data_dir + 'loihi_spreizer_test_e_i.npy')
ts = np.load(data_dir + 'loihi_spreizer_test_e_t.npy')
        
output_file = 'loihi_spreizer_test'
make_animation(gs, ts, binsize, simtime, nPopE, output_file, fps)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09574137395088592, 'fraction_numerical': 0.012433944668946224, 'mean_word_length': 3.6978102189781024, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '442676', 'license': 'MIT', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1082, 'n_words': 250, 'path': 'LoihiSpreizerNet_demo.ipynb', 'repo_name': 'andrewlehr/Brian2Loihi_SpreizerNet', 'size': '3222'}