def test_spike_sync_empty(): st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_allclose(d, 1.0) prof = spk.spike_sync_profile(st1, st2) assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 1.0]) assert_array_equal(prof.y, [1.0, 1.0]) st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([ 0.4, ], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_allclose(d, 0.0) prof = spk.spike_sync_profile(st1, st2) assert_allclose(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 0.4, 1.0]) assert_array_equal(prof.y, [0.0, 0.0, 0.0]) st1 = SpikeTrain([ 0.6, ], edges=(0.0, 1.0)) st2 = SpikeTrain([ 0.4, ], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_almost_equal(d, 1.0, decimal=15) prof = spk.spike_sync_profile(st1, st2) assert_allclose(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.4, 0.6, 1.0], decimal=15) assert_array_almost_equal(prof.y, [1.0, 1.0, 1.0, 1.0], decimal=15) st1 = SpikeTrain([ 0.2, ], edges=(0.0, 1.0)) st2 = SpikeTrain([ 0.8, ], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_almost_equal(d, 0.0, decimal=15) prof = spk.spike_sync_profile(st1, st2) assert_allclose(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.2, 0.8, 1.0], decimal=15) assert_array_almost_equal(prof.y, [0.0, 0.0, 0.0, 0.0], decimal=15) # test with empty intervals st1 = SpikeTrain([2.0, 5.0], [0, 10.0]) st2 = SpikeTrain([2.1, 7.0], [0, 10.0]) st3 = SpikeTrain([5.1, 6.0], [0, 10.0]) res = spk.spike_sync_profile(st1, st2).avrg(interval=[3.0, 4.0]) assert_allclose(res, 1.0) res = spk.spike_sync(st1, st2, interval=[3.0, 4.0]) assert_allclose(res, 1.0) sync_matrix = spk.spike_sync_matrix([st1, st2, st3], interval=[3.0, 4.0]) assert_array_equal(sync_matrix, np.ones((3, 3)) - np.diag(np.ones(3)))
def test_spike_sync(): spikes1 = SpikeTrain([1.0, 2.0, 3.0], 4.0) spikes2 = SpikeTrain([2.1], 4.0) expected_x = np.array([0.0, 1.0, 2.0, 2.1, 3.0, 4.0]) expected_y = np.array([0.0, 0.0, 1.0, 1.0, 0.0, 0.0]) f = spk.spike_sync_profile(spikes1, spikes2) assert_array_almost_equal(f.x, expected_x, decimal=16) assert_array_almost_equal(f.y, expected_y, decimal=16) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) # test with some small max_tau, spike_sync should be 0 assert_almost_equal(spk.spike_sync(spikes1, spikes2, max_tau=0.05), 0.0, decimal=16) spikes2 = SpikeTrain([3.1], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([1.1], 4.0) expected_x = np.array([0.0, 1.0, 1.1, 2.0, 3.0, 4.0]) expected_y = np.array([1.0, 1.0, 1.0, 0.0, 0.0, 0.0]) f = spk.spike_sync_profile(spikes1, spikes2) assert_array_almost_equal(f.x, expected_x, decimal=16) assert_array_almost_equal(f.y, expected_y, decimal=16) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([0.9], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([3.0], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([1.0], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([1.5, 3.0], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.4, decimal=16)
def test_single_prof(): st1 = np.array([1.0, 2.0, 3.0, 4.0]) st2 = np.array([1.1, 2.1, 3.8]) st3 = np.array([0.9, 3.1, 4.1]) # cython implementation try: from pyspike.cython.cython_profiles import \ coincidence_single_profile_cython as coincidence_impl except ImportError: from pyspike.cython.python_backend import \ coincidence_single_python as coincidence_impl sync_prof = spk.spike_sync_profile(SpikeTrain(st1, 5.0), SpikeTrain(st2, 5.0)) coincidences = np.array(coincidence_impl(st1, st2, 0, 5.0, 0.0)) print(coincidences) for i, t in enumerate(st1): assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], "At index %d" % i) coincidences = np.array(coincidence_impl(st2, st1, 0, 5.0, 0.0)) for i, t in enumerate(st2): assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], "At index %d" % i) sync_prof = spk.spike_sync_profile(SpikeTrain(st1, 5.0), SpikeTrain(st3, 5.0)) coincidences = np.array(coincidence_impl(st1, st3, 0, 5.0, 0.0)) for i, t in enumerate(st1): assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], "At index %d" % i) st1 = np.array([1.0, 2.0, 3.0, 4.0]) st2 = np.array([1.0, 2.0, 4.0]) sync_prof = spk.spike_sync_profile(SpikeTrain(st1, 5.0), SpikeTrain(st2, 5.0)) coincidences = np.array(coincidence_impl(st1, st2, 0, 5.0, 0.0)) for i, t in enumerate(st1): expected = sync_prof.y[sync_prof.x == t] / sync_prof.mp[sync_prof.x == t] assert_equal(coincidences[i], expected, "At index %d" % i)
def test_spike_sync_empty(): st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_equal(d, 1.0) prof = spk.spike_sync_profile(st1, st2) assert_equal(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 1.0]) assert_array_equal(prof.y, [1.0, 1.0]) st1 = SpikeTrain([], edges=(0.0, 1.0)) st2 = SpikeTrain([0.4, ], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_equal(d, 0.0) prof = spk.spike_sync_profile(st1, st2) assert_equal(d, prof.avrg()) assert_array_equal(prof.x, [0.0, 0.4, 1.0]) assert_array_equal(prof.y, [0.0, 0.0, 0.0]) st1 = SpikeTrain([0.6, ], edges=(0.0, 1.0)) st2 = SpikeTrain([0.4, ], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_almost_equal(d, 1.0, decimal=15) prof = spk.spike_sync_profile(st1, st2) assert_equal(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.4, 0.6, 1.0], decimal=15) assert_array_almost_equal(prof.y, [1.0, 1.0, 1.0, 1.0], decimal=15) st1 = SpikeTrain([0.2, ], edges=(0.0, 1.0)) st2 = SpikeTrain([0.8, ], edges=(0.0, 1.0)) d = spk.spike_sync(st1, st2) assert_almost_equal(d, 0.0, decimal=15) prof = spk.spike_sync_profile(st1, st2) assert_equal(d, prof.avrg()) assert_array_almost_equal(prof.x, [0.0, 0.2, 0.8, 1.0], decimal=15) assert_array_almost_equal(prof.y, [0.0, 0.0, 0.0, 0.0], decimal=15)
def get_data(): print 'Starting analysis of spike times per cell: ' + str(label_network) sync_data = [[[[] for i in range(2)] for x in range(len(gids))] for p in range(len(stats))] spktsRange = [ spkt for spkt in spkts if timeRange[0] <= spkt <= timeRange[1] ] for i, stat in enumerate(stats): for ii, subset in enumerate(gids): spkmat = [ pyspike.SpikeTrain([ spkt for spkind, spkt in zip(spkinds, spkts) if (spkind == gid and spkt in spktsRange) ], timeRange) for gid in set(subset) ] if stat == 'spike_sync_profile': print str(stat) + ", subset: " + str( ii) + ", number of trains: " + str(len(spkmat)) syncMat1 = pyspike.spike_sync_profile(spkmat) x, y = syncMat1.get_plottable_data() sync_data[i][ii][0] = x sync_data[i][ii][1] = y elif stat == 'spike_profile': print str(stat) + ", subset: " + str( ii) + ", number of trains: " + str(len(spkmat)) syncMat2 = pyspike.spike_profile(spkmat) x, y = syncMat2.get_plottable_data() sync_data[i][ii][0] = x sync_data[i][ii][1] = y elif stat == 'isi_profile': print str(stat) + ", subset: " + str( ii) + ", number of trains: " + str(len(spkmat)) syncMat3 = pyspike.isi_profile(spkmat) x, y = syncMat3.get_plottable_data() sync_data[i][ii][0] = x sync_data[i][ii][1] = y
print() f = spk.spike_profile(spike_trains[0], spike_trains[1]) print("SPIKE-distance: %.8f" % f.avrg()) spike1 = f.avrg(interval=(0, 1000)) spike2 = f.avrg(interval=(1000, 2000)) spike3 = f.avrg(interval=[(0, 1000), (2000, 3000)]) spike4 = f.avrg(interval=[(1000, 2000), (3000, 4000)]) print("SPIKE-distance (0-1000): %.8f" % spike1) print("SPIKE-distance (1000-2000): %.8f" % spike2) print("SPIKE-distance (0-1000) and (2000-3000): %.8f" % spike3) print("SPIKE-distance (1000-2000) and (3000-4000): %.8f" % spike4) print() f = spk.spike_sync_profile(spike_trains[0], spike_trains[1]) print("SPIKE-Synchronization: %.8f" % f.avrg()) spike_sync1 = f.avrg(interval=(0, 1000)) spike_sync2 = f.avrg(interval=(1000, 2000)) spike_sync3 = f.avrg(interval=[(0, 1000), (2000, 3000)]) spike_sync4 = f.avrg(interval=[(1000, 2000), (3000, 4000)]) print("SPIKE-Sync (0-1000): %.8f" % spike_sync1) print("SPIKE-Sync (1000-2000): %.8f" % spike_sync2) print("SPIKE-Sync (0-1000) and (2000-3000): %.8f" % spike_sync3) print("SPIKE-Sync (1000-2000) and (3000-4000): %.8f" % spike_sync4)
from __future__ import print_function import matplotlib.pyplot as plt import pyspike as spk spike_trains = spk.load_spike_trains_from_txt("../test/SPIKE_Sync_Test.txt", edges=(0, 4000)) plt.figure() f = spk.spike_sync_profile(spike_trains[0], spike_trains[1]) x, y = f.get_plottable_data() plt.plot(x, y, '--ok', label="SPIKE-SYNC profile") print(f.x) print(f.y) print(f.mp) print("Average:", f.avrg()) f = spk.spike_profile(spike_trains[0], spike_trains[1]) x, y = f.get_plottable_data() plt.plot(x, y, '-b', label="SPIKE-profile") plt.axis([0, 4000, -0.1, 1.1]) plt.legend(loc="center right") plt.figure()
def test_spike_sync(): spikes1 = SpikeTrain([1.0, 2.0, 3.0], 4.0) spikes2 = SpikeTrain([2.1], 4.0) expected_x = np.array([0.0, 1.0, 2.0, 2.1, 3.0, 4.0]) expected_y = np.array([0.0, 0.0, 1.0, 1.0, 0.0, 0.0]) f = spk.spike_sync_profile(spikes1, spikes2) assert_array_almost_equal(f.x, expected_x, decimal=16) assert_array_almost_equal(f.y, expected_y, decimal=16) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) # test with some small max_tau, spike_sync should be 0 assert_almost_equal(spk.spike_sync(spikes1, spikes2, max_tau=0.05), 0.0, decimal=16) spikes2 = SpikeTrain([3.1], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([1.1], 4.0) expected_x = np.array([0.0, 1.0, 1.1, 2.0, 3.0, 4.0]) expected_y = np.array([1.0, 1.0, 1.0, 0.0, 0.0, 0.0]) f = spk.spike_sync_profile(spikes1, spikes2) assert_array_almost_equal(f.x, expected_x, decimal=16) assert_array_almost_equal(f.y, expected_y, decimal=16) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([0.9], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([3.0], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([1.0], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.5, decimal=16) spikes2 = SpikeTrain([1.5, 3.0], 4.0) assert_almost_equal(spk.spike_sync(spikes1, spikes2), 0.4, decimal=16) spikes1 = SpikeTrain([1.0, 2.0, 4.0], 4.0) spikes2 = SpikeTrain([3.8], 4.0) spikes3 = SpikeTrain([ 3.9, ], 4.0) expected_x = np.array([0.0, 1.0, 2.0, 3.8, 4.0, 4.0]) expected_y = np.array([0.0, 0.0, 0.0, 1.0, 1.0, 1.0]) f = spk.spike_sync_profile(spikes1, spikes2) assert_array_almost_equal(f.x, expected_x, decimal=16) assert_array_almost_equal(f.y, expected_y, decimal=16) f2 = spk.spike_sync_profile(spikes2, spikes3) i1 = f.integral() i2 = f2.integral() f.add(f2) i12 = f.integral() assert_equal(i1[0] + i2[0], i12[0]) assert_equal(i1[1] + i2[1], i12[1])
#Make a list where we will put the set of "SpikeTrain" objects spikiTimesObjList = [] #Fill the list with spike trains for each neuron in the simulation for i in numpy.unique(poiSpikeNeuro): inds = numpy.argwhere(poiSpikeNeuro==i) #FInd tthe spike-times that correspond to neuron i inds = inds[:,0] #the variable "inds" is a 2D array, I just want a 1D array to give to the "SpikeTrain" class. spikiTimesObjList.append(spk.SpikeTrain(poiSpikeTimes[inds], edges=(0., 1.), is_sorted=True)) #Append the spikiTimesObjList with a "SpikeTrain" object #Make a "spike_profile", which essentially is a simultaneous comparison of all the spike trains together simutaneously spike_profile = spk.spike_profile(spikiTimesObjList) #Make a "isi_profile", which essentially is a simultaneous comparison of all the spike trains together simutaneously isi_profile = spk.isi_profile(spikiTimesObjList) #Make a "spike_sync_profile", which essentially is a simultaneous comparison of all the spike trains together simutaneously sync_profile = spk.spike_sync_profile(spikiTimesObjList) #Now I want to pring out want these profiles that have just been created look like. plt.figure(1) x, y = spike_profile.get_plottable_data() plt.plot(x, y, '--k') plt.figure(2) x, y = isi_profile.get_plottable_data() plt.plot(x,y, '--k') plt.figure(3) x, y = sync_profile.get_plottable_data() plt.plot(x,y, '--k') plt.show()
def iter_plot0(md): import seaborn as sns import pickle with open('cell_indexs.p', 'rb') as f: returned_list = pickle.load(f) index_exc = returned_list[0] index_inh = returned_list[1] index, mdf1 = md #wgf = {0.025:None,0.05:None,0.125:None,0.25:None,0.3:None,0.4:None,0.5:None,1.0:None,1.5:None,2.0:None,2.5:None,3.0:None} wgf = { 0.0025: None, 0.0125: None, 0.025: None, 0.05: None, 0.125: None, 0.25: None, 0.3: None, 0.4: None, 0.5: None, 1.0: None, 1.5: None, 2.0: None, 2.5: None, 3.0: None } weight_gain_factors = {k: v for k, v in enumerate(wgf.keys())} print(len(weight_gain_factors)) print(weight_gain_factors.keys()) #weight_gain_factors = {0:0.5,1:1.0,2:1.5,3:2.0,4:2.5,5:3} #weight_gain_factors = {:None,1.0:None,1.5:None,2.0:None,2.5:None} k = weight_gain_factors[index] #print(len(mdf1.segments),'length of block') ass = mdf1.analogsignals[0] time_points = ass.times avg = np.mean(ass, axis=0) # Average over signals of Segment #maxx = np.max(ass, axis=0) # Average over signals of Segment std = np.std(ass, axis=0) # Average over signals of Segment #avg_minus = plt.figure() plt.plot([i for i in range(0, len(avg))], avg) plt.plot([i for i in range(0, len(std))], std) plt.title("Mean and Standard Dev of $V_{m}$ amplitude per neuron ") plt.xlabel('time $(ms)$') plt.xlabel('Voltage $(mV)$') plt.savefig(str(index) + 'prs.png') vm_spiking = [] vm_not_spiking = [] spike_trains = [] binary_trains = [] max_spikes = 0 vms = np.array(mdf1.analogsignals[0].as_array().T) #print(data) #for i,vm in enumerate(data): cnt = 0 for spiketrain in mdf1.spiketrains: #spiketrain = mdf1.spiketrains[index] y = np.ones_like(spiketrain) * spiketrain.annotations['source_id'] #import sklearn #sklearn.decomposition.NMF(y) # argument edges is the time interval you want to be considered. pspikes = pyspike.SpikeTrain(spiketrain, edges=(0, len(ass))) spike_trains.append(pspikes) if len(spiketrain) > max_spikes: max_spikes = len(spiketrain) if np.max(ass[spiketrain.annotations['source_id']]) > 0.0: vm_spiking.append(vms[spiketrain.annotations['source_id']]) else: vm_not_spiking.append(vms[spiketrain.annotations['source_id']]) cnt += 1 for spiketrain in mdf1.spiketrains: x = conv.BinnedSpikeTrain(spiketrain, binsize=1 * pq.ms, t_start=0 * pq.s) binary_trains.append(x) end_floor = np.floor(float(mdf1.t_stop)) dt = float(mdf1.t_stop) % end_floor mdf1.t_start #v = mdf1.take_slice_of_analogsignalarray_by_unit() t_axis = np.arange(float(mdf1.t_start), float(mdf1.t_stop), dt) plt.figure() plt.clf() plt.figure() plt.clf() cleaned = [] data = np.array(mdf1.analogsignals[0].as_array().T) #print(data) for i, vm in enumerate(data): if np.max(vm) > 900.0 or np.min(vm) < -900.0: pass else: plt.plot(ass.times, vm) #,label='neuron identifier '+str(i))) cleaned.append(vm) #vm = s#.as_array()[:,i] assert len(cleaned) < len(ass) print(len(cleaned)) plt.title('neuron $V_{m}$') #plt.legend(loc="upper left") plt.savefig(str('weight_') + str(k) + 'analogsignals' + '.png') plt.xlabel('Time $(ms)$') plt.ylabel('Voltage $(mV)$') plt.close() #pass plt.figure() plt.clf() plt.title('Single Neuron $V_{m}$ trace') plt.plot(ass.times[0:int(len(ass.times) / 10)], vm_not_spiking[index_exc[0]][0:int(len(ass.times) / 10)]) plt.xlabel('$ms$') plt.ylabel('$mV$') plt.xlabel('Time $(ms)$') plt.ylabel('Voltage $(mV)$') plt.savefig(str('weight_') + str(k) + 'eespecific_analogsignals' + '.png') plt.close() plt.figure() plt.clf() plt.title('Single Neuron $V_{m}$ trace') plt.plot(ass.times[0:int(len(ass.times) / 10)], vm_not_spiking[index_inh[0]][0:int(len(ass.times) / 10)]) plt.xlabel('$ms$') plt.ylabel('$mV$') plt.savefig(str('weight_') + str(k) + 'inhibitory_analogsignals' + '.png') plt.close() cvs = [0 for i in range(0, len(spike_trains))] cvsd = {} cvs = [] cvsi = [] rates = [] # firing rates per cell. in spikes a second. for i, j in enumerate(spike_trains): rates.append(float(len(j) / 2.0)) cva = cv(j) if np.isnan(cva) or cva == 0: pass #cvs[i] = 0 #cvsd[i] = 0 else: pass #cvs[i] = cva #cvsd[i] = cva cvs.append(cva) #import pickle #with open(str('weight_')+str(k)+'coefficients_of_variation.p','wb') as f: # pickle.dump([cvs,cvsd],f) import numpy a = numpy.asarray(cvs) numpy.savetxt('pickles/' + str('weight_') + str(k) + 'coefficients_of_variation.csv', a, delimiter=",") import numpy a = numpy.asarray(rates) numpy.savetxt('pickles/' + str('weight_') + str(k) + 'firing_of_rate.csv', a, delimiter=",") cvs = [i for i in cvs if i != 0] cells = [i for i in range(0, len(cvs))] plt.clf() fig, axes = plt.subplots() axes.set_title('Coefficient of Variation Versus Neuron') axes.set_xlabel('Neuron number') axes.set_ylabel('CV estimate') mcv = np.mean(cvs) #plt.scatter(cells,cvs) cvs = np.array(cvs) plt.scatter(index_inh, cvs[index_inh], label="inhibitory cells") plt.scatter(index_exc, cvs[index_exc], label="excitatory cells") plt.legend(loc="upper left") fig.tight_layout() plt.savefig(str('weight_') + str(k) + 'cvs_mean_' + str(mcv) + '.png') plt.close() plt.clf() #frequencies, power = elephant.spectral.welch_psd(ass) #mfreq = frequencies[np.where(power==np.max(power))[0][0]] #fig, axes = plt.subplots() axes.set_title('Firing Rate Versus Neuron Number at mean f=' + str(np.mean(rates)) + str('(Spike Per Second)')) axes.set_xlabel('Neuron number') axes.set_ylabel('Spikes per second') rates = np.array(rates) plt.scatter(index_inh, rates[index_inh], label="inhibitory cells") plt.scatter(index_exc, rates[index_exc], label="excitatory cells") plt.legend(loc="upper left") fig.tight_layout() plt.savefig(str('firing_rates_per_cell_') + str(k) + str(mcv) + '.png') plt.close() ''' import pandas as pd d = {'coefficent_of_variation': cvs, 'cells': cells} df = pd.DataFrame(data=d) ax = sns.regplot(x='cells', y='coefficent_of_variation', data=df)#, fit_reg=False) plt.savefig(str('weight_')+str(k)+'cvs_regexp_'+str(mcv)+'.png'); plt.close() ''' spike_trains = [] ass = mdf1.analogsignals[0] tstop = mdf1.t_stop np.max(ass.times) == mdf1.t_stop #assert tstop == 2000 tstop = 2000 vm_spiking = [] for spiketrain in mdf1.spiketrains: vm_spiking.append( mdf1.analogsignals[0][spiketrain.annotations['source_id']]) y = np.ones_like(spiketrain) * spiketrain.annotations['source_id'] # argument edges is the time interval you want to be considered. pspikes = pyspike.SpikeTrain(spiketrain, edges=(0, tstop)) spike_trains.append(pspikes) # plot the spike times plt.clf() for (i, spike_train) in enumerate(spike_trains): plt.scatter(spike_train, i * np.ones_like(spike_train), marker='.') plt.xlabel('Time (ms)') plt.ylabel('Cell identifier') plt.title('Raster Plot for weight strength:' + str(k)) plt.savefig(str('weight_') + str(k) + 'raster_plot' + '.png') plt.close() f = spk.isi_profile(spike_trains, indices=[0, 1]) x, y = f.get_plottable_data() #text_file.close() text_file = open(str('weight_') + str(index) + 'net_out.txt', 'w') plt.figure() plt.plot(x, np.abs(y), '--k', label="ISI-profile") print("ISI-distance: %.8f" % f.avrg()) f = spk.spike_profile(spike_trains, indices=[0, 1]) x, y = f.get_plottable_data() plt.plot(x, y, '-b', label="SPIKE-profile") #print("SPIKE-distance: %.8f" % f.avrg()) string_to_write = str("ISI-distance:") + str(f.avrg()) + str("\n\n") plt.title(string_to_write) plt.xlabel('Time $(ms)$') plt.ylabel('ISI distance') plt.legend(loc="upper left") plt.savefig(str('weight_') + str(k) + 'ISI_distance_bivariate' + '.png') plt.close() text_file.write(string_to_write) #text_file.write("SPIKE-distance: %.8f" % f.avrg()) #text_file.write("\n\n") plt.figure() f = spk.spike_sync_profile(spike_trains[0], spike_trains[1]) x, y = f.get_plottable_data() plt.plot(x, y, '--ok', label="SPIKE-SYNC profile") print(f, f.avrg()) print("Average:" + str(f.avrg())) #print(len(f.avrg()),f.avrg()) string_to_write = str("instantaneous synchrony:") + str( f.avrg()) + 'weight: ' + str(index) plt.title(string_to_write) plt.xlabel('Time $(ms)$') plt.ylabel('instantaneous synchrony') text_file.write(string_to_write) #text_file.write(list()) f = spk.spike_profile(spike_trains[0], spike_trains[1]) x, y = f.get_plottable_data() plt.plot(x, y, '-b', label="SPIKE-profile") plt.axis([0, 4000, -0.1, 1.1]) plt.legend(loc="center right") plt.clf() plt.figure() plt.subplot(211) f = spk.spike_sync_profile(spike_trains) x, y = f.get_plottable_data() plt.plot(x, y, '-b', alpha=0.7, label="SPIKE-Sync profile") x1, y1 = f.get_plottable_data(averaging_window_size=50) plt.plot(x1, y1, '-k', lw=2.5, label="averaged SPIKE-Sync profile") plt.subplot(212) f_psth = spk.psth(spike_trains, bin_size=50.0) x, y = f_psth.get_plottable_data() plt.plot(x, y, '-k', alpha=1.0, label="PSTH") plt.savefig(str('weight_') + str(k) + 'multivariate_PSTH' + '.png') plt.close() plt.xlabel('Time $(ms)$') plt.ylabel('Spikes per bin') plt.clf() plt.figure() f_psth = spk.psth(spike_trains, bin_size=50.0) x, y = f_psth.get_plottable_data() plt.plot(x, y, '-k', alpha=1.0, label="PSTH") plt.savefig(str('weight_') + str(k) + 'exclusively_PSTH' + '.png') plt.close() plt.figure() isi_distance = spk.isi_distance_matrix(spike_trains) plt.imshow(isi_distance, interpolation='none') plt.title('Pairwise ISI distance, T=0-2000') plt.xlabel('post-synaptic neuron number') plt.ylabel('pre-synaptic neuron number') plt.title("ISI-distance") plt.savefig(str('weight_') + str(k) + 'ISI_distance' + '.png') plt.close() #plt.show() plt.figure() plt.clf() import seaborn as sns sns.set() sns.clustermap(isi_distance) #,vmin=-,vmax=1); plt.savefig(str('weight_') + str(k) + 'cluster_isi_distance' + '.png') plt.close() plt.figure() spike_distance = spk.spike_distance_matrix(spike_trains, interval=(0, float(tstop))) import pickle with open('spike_distance_matrix.p', 'wb') as f: pickle.dump(spike_distance, f) plt.imshow(spike_distance, interpolation='none') plt.title("Pairwise SPIKE-distance, T=0-2000") plt.xlabel('post-synaptic neuron number') plt.ylabel('pre-synaptic neuron number') plt.savefig(str('weight_') + str(k) + 'spike_distance_matrix' + '.png') plt.close() plt.figure() plt.clf() sns.set() sns.clustermap(spike_distance) plt.savefig(str('weight_') + str(k) + 'cluster_spike_distance' + '.png') plt.close() plt.figure() spike_sync = spk.spike_sync_matrix(spike_trains, interval=(0, float(tstop))) plt.imshow(spike_sync, interpolation='none') plt.title('Pairwise Spike Synchony, T=0-2000') plt.xlabel('post-synaptic neuron number') plt.ylabel('pre-synaptic neuron number') import numpy a = numpy.asarray(spike_sync) numpy.savetxt("spike_sync_matrix.csv", a, delimiter=",") plt.figure() plt.clf() sns.clustermap(spike_sync) plt.savefig( str('weight_') + str(k) + 'cluster_spike_sync_distance' + '.png') plt.close()
for index, times in enumerate(spike_times): spike_times[index] = [ time for time in times if (time > time_range[0] and time < time_range[1]) ] spike_trains[index] = spk.SpikeTrain(np.array(spike_times[index]), edges=time_range) return spike_trains spike_trains = make_spike_trains(spike_times, time_range=[500, 6000]) sync_profile = spk.spike_sync_profile(spike_trains) x, y = sync_profile.get_plottable_data() plt.figure() plt.plot(x, y) plt.ylabel('Synchrony Profile') plt.xlabel('Time (ms)') plt.title('Synchrony') print("Synchrony: %.8f" % sync_profile.avrg()) isi_profile = spk.isi_profile(spike_trains) x, y = isi_profile.get_plottable_data() plt.figure() plt.plot(x, y) plt.ylabel('ISI Profile') plt.xlabel('Time (ms)') plt.title('ISI Distance')