manual:python_binary_toolkit
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
manual:python_binary_toolkit [2016/08/10 19:15] – Adds binary state monitor example zenke | manual:python_binary_toolkit [2016/08/30 18:21] (current) – Redirect zenke | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Auryn Python toolkit ====== | + | This page moved to [[python |
- | + | ||
- | Auryn v0.8.0 is the first version | + | |
- | + | ||
- | + | ||
- | ===== Example: Plot spikes from spk file ===== | + | |
- | + | ||
- | Suppose you have an '' | + | |
- | + | ||
- | The following code snipped will then plot the spikes from last 0.1 seconds in the file: | + | |
- | <code python> | + | |
- | import numpy as np | + | |
- | import pylab as pl | + | |
- | from auryn_binary_tools import * | + | |
- | + | ||
- | filename | + | |
- | seconds = 0.1 | + | |
- | + | ||
- | sf = AurynBinarySpikeFile(filename) | + | |
- | spikes = np.array(sf.get_last(seconds)) | + | |
- | + | ||
- | pl.scatter(spikes[:, | + | |
- | pl.xlabel(" | + | |
- | pl.ylabel(" | + | |
- | pl.show() | + | |
- | </ | + | |
- | + | ||
- | {{ : | + | |
- | + | ||
- | Instead of the the '' | + | |
- | + | ||
- | + | ||
- | ===== Example: Plot spikes from multiple spk files ===== | + | |
- | + | ||
- | In a parallel simulation you will typically have multiple spk output files because each rank writes its own file to disk. The Python toolkit provides a simple way how you can deal with this transparently. Suppose you ran the Vogels Abbott benchmark in parallel using 4 cores ('' | + | |
- | + | ||
- | <code python> | + | |
- | import numpy as np | + | |
- | import pylab as pl | + | |
- | from auryn_binary_tools import * | + | |
- | + | ||
- | num_mpi_ranks = 4 | + | |
- | seconds = 0.1 | + | |
- | + | ||
- | filenames | + | |
- | + | ||
- | sf = AurynBinarySpikeView(filenames) | + | |
- | spikes = np.array(sf.get_last(seconds)) | + | |
- | + | ||
- | pl.scatter(spikes[:, | + | |
- | pl.xlabel(" | + | |
- | pl.ylabel(" | + | |
- | pl.show() | + | |
- | </ | + | |
- | + | ||
- | The output should look similar to the plot above. | + | |
- | + | ||
- | + | ||
- | ===== Example: Compute a neurons receptive field via reverse correlations ===== | + | |
- | + | ||
- | Suppose you want to know the linear receptive field of a neuron. We will illustrate this on data from one of my published papers [[http:// | + | |
- | + | ||
- | To get the receptive field of a neuron we are interested in which input neurons were active just before a certain network neuron spiked. Moreover, because the network is plastic we would like to know how the receptive field changes over time. With the supplied Python toolkit this analysis is straight forward. Here is the code: | + | |
- | + | ||
- | <code python> | + | |
- | # | + | |
- | import numpy as np | + | |
- | import pylab as pl | + | |
- | from auryn_binary_tools import * | + | |
- | + | ||
- | datadir = "/ | + | |
- | num_mpi_ranks = 4 | + | |
- | + | ||
- | dim = 64 | + | |
- | n_max = dim**2 | + | |
- | t_bin = 100e-3 | + | |
- | integration_time = 400 | + | |
- | neuron_id | + | |
- | + | ||
- | outputfile = " | + | |
- | sf = AurynBinarySpikeFile(outputfile) | + | |
- | + | ||
- | stimfiles | + | |
- | sfo = AurynBinarySpikeView(stimfiles) | + | |
- | + | ||
- | start_times = np.arange(6)*500 | + | |
- | for i,t_start in enumerate(start_times): | + | |
- | t_end = t_start+integration_time | + | |
- | print(" | + | |
- | spike_times = np.array(sf.get_spike_times(neuron_id, | + | |
- | hist = sfo.time_triggered_histogram( spike_times, | + | |
- | pl.subplot(2, | + | |
- | pl.title(" | + | |
- | pl.imshow(hist.reshape((dim, | + | |
- | pl.show() | + | |
- | </ | + | |
- | + | ||
- | which will give you the following plot: | + | |
- | {{ : | + | |
- | as you can see the neuron here is torn between being selective to a square and a triangle. | + | |
- | + | ||
- | + | ||
- | ===== Example: Get membrane potential from BinaryStateMonitor file ===== | + | |
- | + | ||
- | Finally, here is an example of howto read binary state monitor files: | + | |
- | + | ||
- | <code python> | + | |
- | import numpy as np | + | |
- | import pylab as pl | + | |
- | from auryn_binary_tools import * | + | |
- | + | ||
- | # This code snipped assumes that you have run the example simulation | + | |
- | # sim_epsp_binmon with default parameters and adjusted the below | + | |
- | # filename to its output. | + | |
- | + | ||
- | filename | + | |
- | t_from=0.2 | + | |
- | t_to =2.5 | + | |
- | + | ||
- | sf = AurynBinaryStateFile(filename) | + | |
- | spikes = np.array(sf.get_data(t_from, | + | |
- | + | ||
- | pl.plot(spikes[:, | + | |
- | pl.xlabel(" | + | |
- | pl.ylabel(" | + | |
- | pl.show() | + | |
- | </ | + | |
- | + | ||
- | {{ : | + |
manual/python_binary_toolkit.1470856526.txt.gz · Last modified: 2016/08/10 19:15 by zenke