def test_save_load(): file_name = os.path.join(tempfile.mkdtemp(prefix='pyspike_'), "save_load.txt") N = 10 # generate some spike trains spike_trains = [] for n in range(N): spike_trains.append(spk.generate_poisson_spikes(1.0, [0, 100])) # save them into txt file spk.save_spike_trains_to_txt(spike_trains, file_name, precision=17) # load again spike_trains_loaded = spk.load_spike_trains_from_txt(file_name, [0, 100]) for n in range(N): assert_array_equal(spike_trains[n].spikes, spike_trains_loaded[n].spikes)
plt.plot(x, y, '--k') print("ISI distance: %.8f" % isi_profile.avrg()) plt.show() spike_profile = spk.spike_profile(spike_trains[0], spike_trains[1]) x, y = spike_profile.get_plottable_data() plt.plot(x, y, '--k') print("SPIKE distance: %.8f" % spike_profile.avrg()) plt.show() import numpy as np from matplotlib import pyplot as plt import pyspike as spk st1 = spk.generate_poisson_spikes(1.0, [0, 20]) st2 = spk.generate_poisson_spikes(1.0, [0, 20]) d = spk.spike_directionality(st1, st2) #print "Spike Directionality of two Poissonian spike trains:", d E = spk.spike_train_order_profile(st1, st2) plt.figure() x, y = E.get_plottable_data() plt.plot(x, y, '-ob') plt.ylim(-1.1, 1.1) plt.xlabel("t") plt.ylabel("E") plt.title("Spike Train Order Profile")
import pstats # in case you dont have the cython backends, disable the warnings as follows: # spk.disable_backend_warning = True M = 100 # number of spike trains r = 1.0 # rate of Poisson spike times T = 1E3 # length of spike trains print("%d spike trains with %d spikes" % (M, int(r*T))) spike_trains = [] t_start = datetime.now() for i in range(M): spike_trains.append(spk.generate_poisson_spikes(r, T)) t_end = datetime.now() runtime = (t_end-t_start).total_seconds() sort_by = 'tottime' # sort_by = 'cumtime' print("Spike generation runtime: %.3fs" % runtime) print() print("================ ISI COMPUTATIONS ================") print(" MULTIVARIATE DISTANCE") cProfile.run('spk.isi_distance(spike_trains)', 'performance.stat') p = pstats.Stats('performance.stat') p.strip_dirs().sort_stats(sort_by).print_stats(5)
import pstats # in case you dont have the cython backends, disable the warnings as follows: # spk.disable_backend_warning = True M = 100 # number of spike trains r = 1.0 # rate of Poisson spike times T = 1E3 # length of spike trains print("%d spike trains with %d spikes" % (M, int(r*T))) spike_trains = [] t_start = datetime.now() for i in range(M): spike_trains.append(spk.generate_poisson_spikes(r, T)) t_end = datetime.now() runtime = (t_end-t_start).total_seconds() sort_by = 'tottime' # sort_by = 'cumtime' print("Spike generation runtime: %.3fs" % runtime) print() print("================ ISI COMPUTATIONS ================") print(" MULTIVARIATE DISTANCE") cProfile.run('spk.isi_distance(spike_trains)', 'performance.stat') p = pstats.Stats('performance.stat') p.strip_dirs().sort_stats(sort_by).print_stats(5)
import numpy as np from matplotlib import pyplot as plt import pyspike as spk st1 = spk.generate_poisson_spikes(1.0, [0, 20]) st2 = spk.generate_poisson_spikes(1.0, [0, 20]) d = spk.spike_directionality(st1, st2) print "Spike Directionality of two Poissonian spike trains:", d E = spk.spike_train_order_profile(st1, st2) plt.figure() x, y = E.get_plottable_data() plt.plot(x, y, '-ob') plt.ylim(-1.1, 1.1) plt.xlabel("t") plt.ylabel("E") plt.title("Spike Train Order Profile") ###### Optimize spike train order of 20 Random spike trains ####### M = 20 spike_trains = [spk.generate_poisson_spikes(1.0, [0, 100]) for m in xrange(M)] F_init = spk.spike_train_order(spike_trains)