import io from IPython.nbformat import current def execute_notebook(nbfile): with io.open(nbfile) as f: nb = current.read(f, 'json') ip = get_ipython() for cell in nb.worksheets[0].cells: if cell.cell_type != 'code': continue ip.run_cell(cell.input) execute_notebook("common.ipynb") epochs = 100 spikeMiliseconds = 100 spikeInterval = spikeMiliseconds * ms spikeIntervalUnformatted = spikeMiliseconds * .001 dictionaryLongitude = 4 spikesPerChar=3 firstLayerSize = 15 dictionary = dictionary() spiketimes = dictionary.spikeTimes(dictionaryLongitude, spikeInterval, spikesPerChar, epochs) LIK = SpikeGeneratorGroup(firstLayerSize, spiketimes) spikeMonitor = SpikeMonitor(LIK) run(spikesPerChar * dictionaryLongitude * spikeInterval , report='text') fig=plt.figure(figsize=(12,4)) for i in range(0,dictionaryLongitude): ax = fig.add_subplot(1,dictionaryLongitude,i+1) ax.imshow(dictionary.dictionary[i][1], interpolation="nearest", cmap = plt.cm.Greys_r) plt.xticks(np.arange(0,3, 1.0)) neuronArray = np.empty(0, dtype=int) firetimeArray = np.empty(0, dtype=double) neuronColor = np.random.rand(firstLayerSize) colors = np.empty(0, dtype=float) fig=plt.figure(figsize=(12,4)) for neuron in range(0,15): for fire in range(0,spikeMonitor.spiketimes[neuron].size): neuronArray = np.append(neuronArray, neuron) firetimeArray = np.append(firetimeArray,spikeMonitor.spiketimes[neuron][fire]) colors = np.append(colors,neuronColor[neuron]) plt.scatter(firetimeArray,neuronArray, s=100, c=colors) plt.xticks(np.arange(0,max(firetimeArray)+0.1, 0.1)) plt.yticks(np.arange(0,firstLayerSize, 1.0)) ylabel("Neuron number") xlabel("Time(seconds)") grid(True) neuronArray = np.empty(0, dtype=int) firetimeArray = np.empty(0, dtype=double) neuronColor = np.random.rand(4) colors = np.empty(0, dtype=float) #Each neuron learn to represent a random character neuronList=list(range(4)) np.random.shuffle(neuronList) neuronIndex = 0 time = 0 for charNumber in range(0 ,dictionaryLongitude ): neuronIndex = (neuronIndex + 1)%4 neuron = neuronList[neuronIndex] for charRepetetion in range(0,spikesPerChar): time = time + spikeInterval / ms neuronArray = np.append(neuronArray, neuron) firetimeArray = np.append(firetimeArray,time) colors = np.append(colors,neuronColor[neuron]) fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE'),figsize=(13,4)) points = plt.scatter(firetimeArray * ms,neuronArray, s=100, c=colors) plt.yticks(np.arange(0,4, 1.0)) ylabel("Neuron number") xlabel("Time(seconds)") grid(True)