def build_topology(self, seed=None, topology_params={}): """ Builds a network for a BiNAM that has been trained up to the k'th sample """ # Fetch the data parameters for convenient access N = self.data_params["n_samples"] m = self.data_params["n_bits_in"] n = self.data_params["n_bits_out"] # Train the BiNAM mem = binam.BiNAM(m, n) for k in xrange(0, N): mem.train(self.mat_in[k], self.mat_out[k]) # Build input and output neurons t = TopologyParameters(topology_params) s = t["multiplicity"] net = pynl.Network() population_input_size = m * s population_input_params = [{} for _ in xrange(population_input_size)] net.add_population(count=population_input_size, _type=pynl.TYPE_SOURCE, params=population_input_params) population_output_size = n * s population_output_params = list(t.draw() for _ in xrange(population_output_size)) net.add_population(count=population_output_size, _type=t["neuron_type"], params=population_output_params, record=pynl.SIG_SPIKES) def in_coord(i, k=1): return (0, i * s + k) def out_coord(j, k=1): return (1, j * s + k) # Add all connections for i in xrange(m): for j in xrange(n): if mem[i, j] != 0: net.add_connections([ (in_coord(i, k), out_coord(j, l), t.draw_weight(), 0.0) for k in xrange(s) for l in xrange(s)]) return net
def build(self, weights, params={}, input_params={}, delay=0.1, terminating_neurons=1, flag=False): ''' Builds the network of the SCM :param weights: dict of different weights in the SCM: wCH,wCA,wCSigma, wCTInh, wCTExt, wAbort :param params: neuron params :param input_params: pynam.network.InputParameters :param terminating_neurons: Number of terminating neurons, Workaround for some platforms for higher weights to really terminate :param flag: change between SCM (False) and a single neuron in the CS(igma) population ''' net = pynl.Network() # Create the input spike trains trains, input_indices, input_split = pynam.network.NetworkBuilder.build_spike_trains( self.mat_in, 100, input_params=input_params) # Create the individual cell assemblies pop_C = pynl.Population(count=self.n_bits_out, _type=self._type, params=params, record=[pynl.SIG_SPIKES]) if (flag): pop_CS = pynl.Population(count=self.n_bits_out, _type=self._type, params=params, record=[pynl.SIG_SPIKES]) else: pop_CS = pynl.Population(pop_C) pop_CT = pynl.Population(count=terminating_neurons, _type=self._type, params=params, record=[pynl.SIG_SPIKES]) pop_source = pynl.Population(count=self.n_bits_in, _type=pynl.TYPE_SOURCE, params=map( lambda train: {"spike_times": train}, trains), record=[pynl.SIG_SPIKES]) # Create the connections def connections_from_matrix(mat, pSrc, pTar, w): connections = [] for i in xrange(mat.shape[0]): for j in xrange(mat.shape[1]): if mat[i, j] != 0: connections.append(((pSrc, i), (pTar, j), w, delay)) return connections def connections_all_to_all(m, n, pSrc, pTar, w): connections = map(lambda _: [], xrange(m * n)) for i in xrange(m): for j in xrange(n): connections[i * n + j] = (((pSrc, i), (pTar, j), w, delay)) return connections wCH = weights["wCH"] wCA = weights["wCA"] wCSigma = weights["wCSigma"] wCTExt = weights["wCTExt"] wCTInh = weights["wCTInh"] wAbort = weights["wAbort"] iC = 0 iCS = 1 iCT = 2 iSource = 3 if (flag): connections = ( connections_from_matrix(self.mat_CH, iSource, iC, wCH) + connections_from_matrix(self.mat_CA, iC, iC, wCA) + connections_all_to_all(self.n_bits_in, 1, iSource, iCS, wCH) + connections_all_to_all(self.n_bits_out, 1, iC, iCS, wCA) + # Sigma connections connections_all_to_all(1, 1, iCS, iCS, wCSigma) + connections_all_to_all(1, self.n_bits_out, iCS, iC, wCSigma) + # Connections to CT connections_all_to_all(self.n_bits_out, terminating_neurons, iC, iCT, wCTExt) + connections_all_to_all(1, terminating_neurons, iCS, iCT, wCTInh) + # Connections from CT to all other populations connections_all_to_all(terminating_neurons, self.n_bits_out, iCT, iC, wAbort) + connections_all_to_all(terminating_neurons, 1, iCT, iCS, wAbort) + connections_all_to_all(terminating_neurons, terminating_neurons, iCT, iCT, wAbort)) else: connections = ( connections_from_matrix(self.mat_CH, iSource, iC, wCH) + connections_from_matrix(self.mat_CH, iSource, iCS, wCH) + connections_from_matrix(self.mat_CA, iC, iCS, wCA) + connections_from_matrix(self.mat_CA, iC, iC, wCA) + # Sigma connections connections_all_to_all(self.n_bits_out, self.n_bits_out, iCS, iCS, wCSigma) + connections_all_to_all(self.n_bits_out, self.n_bits_out, iCS, iC, wCSigma) + # Connections to CT connections_all_to_all(self.n_bits_out, terminating_neurons, iC, iCT, wCTExt) + connections_all_to_all(self.n_bits_out, terminating_neurons, iCS, iCT, wCTInh) + # Connections from CT to all other populations connections_all_to_all(terminating_neurons, self.n_bits_out, iCT, iC, wAbort) + connections_all_to_all(terminating_neurons, self.n_bits_out, iCT, iCS, wAbort) + connections_all_to_all(terminating_neurons, terminating_neurons, iCT, iCT, wAbort)) return pynl.Network( populations=[pop_C, pop_CS, pop_CT, pop_source], connections=connections), input_indices, input_split, trains
# along with this program. If not, see <http://www.gnu.org/licenses/>. """ Simple network consisting of 10 disconnected neurons and a spike source array. """ import sys import common.setup # Common example code (checks command line parameters) import common.params # Parameters for the models which work with all systems import common.utils # Output functions import pynnless as pynl # Create a new pl instance with the given backend backend = sys.argv[1] sim = pynl.PyNNLess(backend) # Create and run network with two populations: One population consisting of a # spike source arrays and another population consisting of neurons. print("Simulating network...") count = 10 res = sim.run(pynl.Network().add_source( spike_times=[100.0 * i for i in xrange(1, 9)]).add_population( pynl.IfCondExpPopulation( count=count, params=common.params.IF_cond_exp).record_spikes()).add_connections( [((0, 0), (1, i), 0.024, 0.0) for i in xrange(count)])) print("Done!") # Write the spike times for each neuron to disk print("Writing spike times to " + common.setup.outfile) common.utils.write_spike_times(common.setup.outfile, res[1]["spikes"])
import common.params # Parameters for the models which work with all systems import common.utils # Output functions import pynnless as pynl # Create a new pl instance with the given backend backend = sys.argv[1] sim = pynl.PyNNLess(backend) # Build and run the synfire chain print("Simulating network...") synfire_len = 100 w_syn = 0.024 res = sim.run(pynl.Network() .add_source(spike_times=[10.0]) .add_population( pynl.IfCondExpPopulation( count=synfire_len, params=common.params.IF_cond_exp) .record_spikes() ) .add_connections([ ((0, 0), (1, 0), w_syn, 0.0), ((1, synfire_len - 1), (1, 0), w_syn, 0.0) ] + [((1, i - 1), (1, i), w_syn, 0.0) for i in xrange(1, synfire_len)]), 1000.0) print("Done!") # Write the spike times for each neuron to disk print("Writing spike times to " + common.setup.outfile) common.utils.write_spike_times(common.setup.outfile, res[1]["spikes"])
import common.setup # Common example code (checks command line parameters) import common.params # Parameters for the models which work with all systems import common.utils # Output functions import pynnless as pynl # Create a new pl instance with the given backend backend = sys.argv[1] sim = pynl.PyNNLess(backend) # Create and run network with two populations: One population consisting of a # spike source arrays and another population consisting of neurons. print("Simulating network...") count = 10 res = sim.run(pynl.Network().add_population( pynl.SourcePopulation( count=count, spike_times=[ [10.0 + i, 20.0 + i, 30.0 + i] for i in xrange(count) ])).add_population( pynl.IfCondExpPopulation( count=count, params=[common.params.IF_cond_exp for i in xrange(count) ]).record_spikes()).add_connections([ ((0, i), (1, i), 0.024, 0.0) for i in xrange(count) ])) print("Done!") # Write the spike times for each neuron to disk print("Writing spike times to " + common.setup.outfile) common.utils.write_spike_times(common.setup.outfile, res[1]["spikes"])
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """ Simple usage example of PyNNLess: Creates a network containing a single LIF neuron and a spike source array. Records the output spikes of the LIF neuron. """ import sys import common.setup # Common example code (checks command line parameters) import common.params # Parameters for the models which work with all systems import pynnless as pynl # Create a new pl instance with the given backend backend = sys.argv[1] sim = pynl.PyNNLess(backend) # Create and run network with two populations: One population consisting of a # spike source array and another population consisting of a single neuron. Note # that the network structure built here can be stored in a JSON file, all # objects are dictionaries. You are not required to use the Network and # Population helper classes print("Simulating network...") res = sim.run( pynl.Network().add_source(spike_times=[0, 1000, 2000]).add_neuron( params=common.params.IF_cond_exp, record=pynl.SIG_SPIKES).add_connection((0, 0), (1, 0), weight=0.024)) print("Done!") # Print the output spikes (population 1, spikes, neuron 0) print("Spike Times: " + str(res[1]["spikes"][0]))
weight = 0.016 # Target simulator backend = "spikey" # Record from each neuron exactly once vs = [[]] * neuron_count ts = [[]] * neuron_count for i in xrange(neuron_count): print "Measuring data for neuron", i res = pynl.PyNNLessIsolated(backend).run(pynl.Network() .add_source(spike_times = spike_times) .add_populations([{ "type": pynl.TYPE_IF_COND_EXP, "params": params, "record": [pynl.SIG_V] if i == j else [] } for j in xrange(neuron_count)]) .add_connections([((0, 0), (j + 1, 0), weight, 0.0) for j in xrange(neuron_count)])) vs[i] = res[i + 1]["v"][0] ts[i] = res[i + 1]["v_t"] # Calculate the compound sample times ts_res = np.arange(0.0, 2000.0, 0.1) vs_res = np.zeros((neuron_count, len(ts_res))) for i in xrange(neuron_count): vs_res[i] = np.interp(ts_res, ts[i], vs[i]) # Create a version with corrected DC-offset vs_offs = np.zeros((neuron_count, len(ts_res)))
""" import sys import common.setup # Common example code (checks command line parameters) import common.params # Parameters for the models which work with all systems import pynnless as pynl # Create a new pl instance with the given backend backend = sys.argv[1] sim = pynl.PyNNLess(backend) # Same as in "single_neuron.py", but record the voltage print("Simulating network...") res = sim.run( pynl.Network().add_source(spike_times=[0, 1000, 2000]).add_population( pynl.IfCondExpPopulation(params=common.params.IF_cond_exp). record_spikes().record_v()).add_connection((0, 0), (1, 0), weight=0.024)) print("Done!") # Write the membrane potential for each neuron to disk (first column is time) print("Writing membrane potential to " + common.setup.outfile) f = open(common.setup.outfile, "w") # Iterate over all sample times for i in xrange(len(res[1]["v_t"])): # Write the current sample time f.write(str(res[1]["v_t"][i])) # Iterate over all neurons in the population and write the value for this # sample time for j in xrange(len(res[1]["v"])):