def __init__(self, sheet, parameters): DirectStimulator.__init__(self, sheet, parameters) exc_syn = self.sheet.sim.StaticSynapse( weight=self.parameters.exc_weight) inh_syn = self.sheet.sim.StaticSynapse( weight=self.parameters.inh_weight) if not self.sheet.parameters.mpi_safe: from pyNN.nest import native_cell_type if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.np_exc = self.sheet.sim.Population( 1, native_cell_type("poisson_generator"), {'rate': 0}) self.sheet.sim.Projection(self.np_exc, self.sheet.pop, self.sheet.sim.AllToAllConnector(), synapse_type=exc_syn, receptor_type='excitatory') if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0): self.np_inh = self.sheet.sim.Population( 1, native_cell_type("poisson_generator"), {'rate': 0}) self.sheet.sim.Projection(self.np_inh, self.sheet.pop, self.sheet.sim.AllToAllConnector(), synapse_type=inh_syn, receptor_type='inhibitory') else: if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.ssae = self.sheet.sim.Population( self.sheet.pop.size, self.sheet.sim.SpikeSourceArray()) seeds = mozaik.get_seeds((self.sheet.pop.size, )) self.stgene = [ stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0] ] self.sheet.sim.Projection(self.ssae, self.sheet.pop, self.sheet.sim.OneToOneConnector(), synapse_type=exc_syn, receptor_type='excitatory') if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0): self.ssai = self.sheet.sim.Population( self.sheet.pop.size, self.sheet.sim.SpikeSourceArray()) seeds = mozaik.get_seeds((self.sheet.pop.size, )) self.stgeni = [ stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0] ] self.sheet.sim.Projection(self.ssai, self.sheet.pop, self.sheet.sim.OneToOneConnector(), synapse_type=inh_syn, receptor_type='inhibitory')
def testInhAdaptingMarkov(self): stg = stgen.StGen() from numpy import array t = array([0.0, 5000.0]) # using parameters from paper a = array([23.18, 47.24]) bq = array([0.10912, 0.09794]) * 14.48 # expected mean firing rates for 2D case alpha = array([7.60, 10.66]) tau = 110.0 t_stop = 10000.0 st = stg.inh_adaptingmarkov_generator(a, bq, tau, t, t_stop) assert isinstance(st, signals.SpikeTrain) st = stg.inh_adaptingmarkov_generator(a, bq, tau, t, t_stop, array=True) assert isinstance(st, numpy.ndarray) assert st[-1] < t_stop assert st[0] > t[0]
def testStatsInhGamma(self): # this is a statistical test with non-zero chance of failure from numpy import array import NeuroTools.signals stg = stgen.StGen() # gamma step rate= 100Hz -> 200Hz, a = 3.0 st = stg.inh_gamma_generator( array([3.0, 3.0]), array([1.0 / 100.0 / 3.0, 1.0 / 200.0 / 3.0]), array([500.0, 1500.0]), 2500.0, array=True) assert (type(st) == numpy.ndarray) n1 = len(st[st < 1500.0]) n2 = len(st[st > 1500.0]) err = """ Number of spikes should be within 3 standard deviations of mean. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" if n2 > 200.0 + 3.0 * numpy.sqrt( 200.0) or n2 < 200.0 - 3.0 * numpy.sqrt(200.0): raise StatisticalError(err) if n1 > 100.0 + 3.0 * numpy.sqrt( 100.0) or n1 < 100.0 - 3.0 * numpy.sqrt(100.0): raise StatisticalError(err)
def __init__(self, sheet, parameters): DirectStimulator.__init__(self, sheet, parameters) population_selector = load_component( self.parameters.population_selector.component) self.ids = population_selector( sheet, self.parameters.population_selector.params ).generate_idd_list_of_neurons() d = dict((j, i) for i, j in enumerate(self.sheet.pop.all_cells)) self.local_and_to_stimulate_indexes = [ d[i] for i in set(self.ids) & set(self.sheet.pop.local_cells) ] exc_syn = self.sheet.sim.StaticSynapse( weight=self.parameters.exc_weight) if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0): self.ssae = self.sheet.sim.Population( self.sheet.pop.size, self.sheet.sim.SpikeSourceArray()) seeds = mozaik.get_seeds((self.sheet.pop.size, )) self.stgene = [ stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in self.local_and_to_stimulate_indexes ] self.sheet.sim.Projection(self.ssae, self.sheet.pop, self.sheet.sim.OneToOneConnector(), synapse_type=exc_syn, receptor_type='excitatory')
def __init__(self, rngseed, RateScale=1e6, Tstep=10): ''' Create a poisson generator, using the given seed for the random number generator ''' self.RateScale = RateScale self.Tstep = Tstep self.rng = NumpyRNG(seed=rngseed) self.stgen = stgen.StGen(self.rng)
def model_network(param_dict): """ This model network consists of a spike source and a neuron (IF_curr_alpha). The spike rate of the source and the weight can be specified in the param_dict. Returns the number of spikes fired during 1000 ms of simulation. Parameters: param_dict - dictionary with keys rate - the rate of the spike source (spikes/second) weight - weight of the connection source -> neuron Returns: dictionary with keys: source_rate - the rate of the spike source weight - weight of the connection source -> neuron neuron_rate - spike rate of the neuron """ #set up the network import pyNN.neuron as sim sim.setup(dt=0.01, min_delay=1., max_delay=1., debug=False, quit_on_end=False) weight = param_dict['weight'] import NeuroTools.stgen as stgen stgen = stgen.StGen() spiketrain = stgen.poisson_generator(param_dict['rate'], t_stop=1000.) source = sim.Population(1, sim.SpikeSourceArray, {'spike_times': spiketrain.spike_times}) neuron = sim.Population(1, sim.IF_cond_alpha) sim.Projection(source, neuron, method=sim.OneToOneConnector(weights=param_dict['weight'], delays=1.)) #set recorder neuron.record() neuron.record_v() #run the simulation sim.run(1001.) sim.end() # count the number of spikes spikes = neuron.getSpikes() numspikes = len(spikes) # return everything, including the input parameters return { 'source_rate': param_dict['rate'], 'weight': param_dict['weight'], 'neuron_rate': numspikes }
def testStatsOUGen(self): # this is a statistical test with non-zero chance of failure from numpy import array stg = stgen.StGen() (ou, t) = stg.OU_generator(0.1, 10.0, 2.0, 10.0, 500.0, 1500.0, array=True)
def testInh2DAdaptingMarkov(self): stg = stgen.StGen() from numpy import array t = array([0.0, 10000.0]) # using parameters from paper a = array([23.18, 47.24]) bq = array([0.10912, 0.09794]) * 14.48 # expected mean firing rates for 2D case alpha = array([7.60, 10.66]) tau_s = 110.0 tau_r = 1.97 qrqs = 221.96 t_stop = 20000.0 st = stg.inh_2Dadaptingmarkov_generator(a, bq, tau_s, tau_r, qrqs, t, t_stop) assert isinstance(st, signals.SpikeTrain) st = stg.inh_2Dadaptingmarkov_generator(a, bq, tau_s, tau_r, qrqs, t, t_stop, array=True) assert isinstance(st, numpy.ndarray) assert st[-1] < t_stop assert st[0] > t[0] spikes1 = len(st[st < 10000]) spikes2 = len(st[st > 10000]) # should be approximately alpha[0]*10.0 spikes assert numpy.clip(spikes1, 60, 100) == spikes1 # should be approximately alpha[1]*10.0 spikes assert numpy.clip(spikes2, 80, 140) == spikes2
def test_poisson(rate, t_start, t_stop): stg = stgen.StGen() dt = t_stop - t_start N = rate * dt / 1000.0 st = stg.poisson_generator(rate, t_start=t_start, t_stop=t_stop, array=True) if len(st) in (0, 1, 2, 3): assert N < 15 return assert st[-1] < t_stop assert st[0] > t_start # last spike should not be more than 4 ISI away from t_stop err = """ Last spike should not be more than 4 ISI behind t_stop. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" if st[-1] < t_stop - 4.0 * 1.0 / rate * 1000.0: raise StatisticalError(err) # first spike should not be more than 4 ISI away from t_start err = """ First spike should not be more than 4 ISI in front of t_start. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" if st[0] > t_start + 4.0 * 1.0 / rate * 1000.0: raise StatisticalError(err) err = """ Number of spikes should be within 3 standard deviations of mean. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" if len(st) > N + 3.0 * numpy.sqrt(N) or len( st) < N - 3.0 * numpy.sqrt(N): raise StatisticalError(err)
def __init__(self, SeqChannelAddress=None, channel=0, host='localhost', port_stim=50002, rates=None, period=1, seq_export=True, load_stim_filename=None): ''' *SeqChannelAddress:* Sequencer Channel Addressing object, if omitted, default channel is taken *host:* Monitoring and Sequencing AEX server hostname. (Must be same) *port_stim:* Port of the Monitoring Server (Default 50002) *rates:* Pairs of logical/physical addresses corresponding rate [addr, rate] *seq_export:* If True, use logical addresses and exportAER stuff *load_stim_filename:* If not None, stimByteStream is loaded from that file ''' #threading.Thread.__init__ ( self ) super(PoissonStimulator, self).__init__() #self.finished=threading.Event() self.is_running = True if SeqChannelAddress == None: self.SeqChannelAddress = pyST.getDefaultSeqChannelAddress() else: self.SeqChannelAddress = SeqChannelAddress #self.aexfd = os.open("/dev/aerfx2_0", os.O_RDWR | os.O_NONBLOCK) self.stim_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.stim_sock.connect((host, port_stim)) self.period = period #period in seconds self.sg = stgen.StGen() self.channel = channel self.rates = rates self.seq_export = seq_export self.load_stim_filename = load_stim_filename
def testShotNoiseFromSpikes(self): stg = stgen.StGen() from numpy import array st = stg.poisson_generator(10.0, 0.0, 1000.0) ge = stgen.shotnoise_fromspikes(st, 2.0, 10.0, dt=0.1) assert ge.t_start == 0.0 assert ge.t_stop == 1000.0 st = stg.poisson_generator(10.0, 0.0, 1000.0) ge = stgen.shotnoise_fromspikes(st, 2.0, 10.0, dt=0.1, t_start=500.0, t_stop=1500.0) assert ge.t_start == 500.0 assert ge.t_stop == 1500.0
def testMethodsBasic(self): stg = stgen.StGen() rate = 100.0 #Hz t_stop = 1000.0 # milliseconds st = stg.poisson_generator(rate, 0.0, t_stop) assert isinstance(st, signals.SpikeTrain) st = stg.poisson_generator(rate, 0.0, t_stop, array=True) assert isinstance(st, numpy.ndarray) st = stg.poisson_generator(rate, 0.0, t_stop, array=True, debug=True) assert isinstance(st[0], numpy.ndarray) assert isinstance(st[1], list) st = stg.poisson_generator(rate, 0.0, t_stop, debug=True) assert isinstance(st[0], signals.SpikeTrain) assert isinstance(st[1], list)
def testInhGammaBasic(self): from numpy import array import NeuroTools.signals stg = stgen.StGen() st = stg.inh_gamma_generator( array([3.0, 3.0]), array([1.0 / 100.0 / 3.0, 1.0 / 200.0 / 3.0]), array([500.0, 1500.0]), 2500.0, array=True) assert (type(st) == numpy.ndarray) st = stg.inh_gamma_generator( array([3.0, 3.0]), array([1.0 / 100.0 / 3.0, 1.0 / 200.0 / 3.0]), array([500.0, 1500.0]), 2500.0, array=False) assert (type(st) == NeuroTools.signals.spikes.SpikeTrain)
def run_multimodal_net(T_plastic=int(1e5), T_prune=int(1e5), T_pairstim=int(1e5), seed_type='diverse', savefile='default_run.pkl', rec_net_pars={}): rec_net.dt = .05 rec_net.N_E = 80 rec_net.N_I = 20 rec_net.r_max = 20.0 rec_net.N_orientations = 4 recurrent_factor = 1.0 rec_net.cbar = recurrent_factor * 1.05 / rec_net.N_E rec_net.w_theta = 0 * 0.25 * recurrent_factor * 1.3 / rec_net.N_E rec_net.a = rec_net.cbar rec_net.b = 5.0 * rec_net.cbar rec_net.ext_OU_noise = True rec_net.ext_OU_tau = 50.0 #rec_net.ext_OU_sigma= (.2**2)*(1.0/rec_net.dt + rec_net.ext_OU_tau)/rec_net.ext_OU_tau rec_net.ext_OU_sigma = 0.0 x = np.zeros((rec_net.N_E + rec_net.N_I, 1)) H_0 = 3.0 rec_net.H = np.ones((rec_net.N_E + rec_net.N_I)) * H_0 rec_net.H_max = 7.0 #*H_0 rec_net.H_min = H_0 for key in rec_net_pars.keys(): setattr(rec_net, key, rec_net_pars[key]) #W,Theta,C_E,orientation_prefs = rec_net.generate_connectivity_matrix(rec_net.N_E,rec_net.N_I) W = np.zeros((rec_net.N_E + rec_net.N_I, rec_net.N_E + rec_net.N_I)) rec_net.W_max = 0.08 * recurrent_factor #0.25 #1.0*recurrent_factor rec_net.W_inh_min = -0.04 * recurrent_factor rec_net.alpha = 1e-8 * 0.1 * recurrent_factor * 2.5 rec_net.BCM_target = 5.0 rec_net.BCM_lambda = 1.0 rec_net.eta = rec_net.alpha * 1.0 * 1.0 rec_net.pruned_synapses = False rec_net.theta_BCM = np.ones(rec_net.N_E) * rec_net.BCM_target * 1.10 rec_net.theta_BCM_dt = 1.0e-5 #rec_net.N_secondary_groups = 2 rec_net.fraction_secondary = 1.0 #_secondary_groups = np.array([[x]*(rec_net.N_E/rec_net.N_secondary_groups) for x in xrange(rec_net.N_secondary_groups)]).flatten() #np.random.shuffle(_secondary_groups) #rec_net.secondary_groups = _secondary_groups[:rec_net.N_E*rec_net.fraction_secondary] rec_net.H_max_variable = np.array([1.0, 1.0, 1.0, 1.0 ]) * 0.5 * rec_net.H_max rec_net.H_secondary_variable = np.array([1.0, 1.0, 1.0, 1.0 ]) * 0.5 * rec_net.H_secondary rec_net.H_visual_baseline = rec_net.H_max * 0.0 rec_net.H_auditory_baseline = rec_net.H_secondary * 0.0 rec_net.visual_responsive = np.zeros(rec_net.N_E) rec_net.visual_responsive[:int(rec_net.N_E * (1.0 - rec_net.frac_nonresponsive) * (1.0 - rec_net.frac_A_only))] = 1.0 rec_net.visual_responsive[int(rec_net.N_E * (1.0 - rec_net.frac_nonresponsive) * (1.0 - rec_net.frac_AV) ):int(rec_net.N_E * (1.0 - rec_net.frac_nonresponsive) * (1.0 - rec_net.frac_A_only))] = 1.0 rec_net.auditory_responsive = np.zeros(rec_net.N_E) rec_net.auditory_responsive[:int(rec_net.N_E * (1.0 - rec_net.frac_nonresponsive))] = 1.0 rec_net.auditory_responsive[:int(rec_net.N_E * (1.0 - rec_net.frac_nonresponsive) * rec_net.frac_V_only)] = 0.0 rec_net.auditory_responsive[int(rec_net.N_E * (1.0 - rec_net.frac_nonresponsive) * rec_net.frac_V_only ):int(rec_net.N_E * (1.0 - rec_net.frac_nonresponsive) * rec_net.frac_AV)] = 1.0 #rec_net.auditory_responsive[:rec_net.N_E*0.5] = 0.0 #rec_net.auditory_responsive[rec_net.N_E*0.5:rec_net.N_E*0.75] = 0.5 _secondary_groups = np.array( [[x] * (sum(rec_net.auditory_responsive > 0) / rec_net.N_secondary_groups) for x in xrange(rec_net.N_secondary_groups)]).flatten() _visual_groups = np.array( [[x] * (sum(rec_net.visual_responsive > 0) / rec_net.N_orientations) for x in xrange(rec_net.N_orientations)]).flatten() np.random.shuffle(_secondary_groups) np.random.shuffle(_visual_groups) sg = np.ones(rec_net.N_E) * -1 sg[rec_net.auditory_responsive > 0] = _secondary_groups vg = np.ones(rec_net.N_E) * -1 vg[rec_net.visual_responsive > 0] = _visual_groups rec_net.secondary_groups = sg rec_net.visual_groups = vg #for g_idx in rec_net.H_secondary_variable: # if rec_net.H_secondary_variable[g_idx] == 0.0: # rec_net.auditory_responsive[rec_net.secondary_groups == g_idx] = 0 T_static = 50000 T_measure = 10000 prob_prune = 1.0 rec_net.prune_threshold = 0.2 T = T_static + T_plastic + T_prune + T_pairstim rec_net.T_input_gen = min(100000, T_plastic / 10) rec_net.N_sample = rec_net.N_E rec_net.sample_res = 1000 rec_net.checkpoint_res = 1e4 for key in rec_net_pars.keys(): setattr(rec_net, key, rec_net_pars[key]) if rec_net_pars.has_key('init_Winh'): W[:rec_net.N_E, rec_net.N_E:] = rec_net_pars['init_Winh'] if rec_net_pars.has_key('init_Wexc'): W[:rec_net.N_E, :rec_net.N_E] = rec_net_pars['init_Wexc'] stgen_drive = stgen.StGen() rec_net.OU_drive = stgen_drive.OU_generator(1., 10.0, H_0, 0., 0., T).signal pop_rate = [] x = np.zeros((rec_net.N_E + rec_net.N_I, 1)) x, W, pop_rate_static, sample_rates_static, sample_inh_rates_static, _inputs = rec_net.run_net_static_input_type( x, W, T_static, rec_net.N_sample) x_static = x.copy() W_static = W.copy() y_bar = x.copy()[:rec_net.N_E] rec_net.theta_BCM = np.ones(rec_net.N_E) * rec_net.BCM_target * 1.10 print 'theta_BCM', rec_net.theta_BCM #x,W,pop_rate_plastic,sample_rates_plastic,sample_weights,sample_inh_weights,mean_incoming_weight,theta_BCM,sample_theta_BCM,sample_inh_rates_plastic = rec_net.run_net_plastic_BCM_and_inh_plasticity(x,W,rec_net.theta_BCM,T_plastic,rec_net.N_sample,'orientation_and_secondary_dynamic',rec_net.N_orientations) #x,W,pop_rate_plastic,sample_rates_plastic,sample_weights,sample_inh_weights,mean_incoming_weight,theta_BCM,sample_theta_BCM,sample_inh_rates_plastic = rec_net.run_net_static_threshold_exc_and_inh_plasticity(x,W,rec_net.theta_BCM,T_plastic,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) x, W, pop_rate_plastic, sample_rates_plastic, sample_weights, sample_inh_weights, mean_incoming_weight, theta_BCM, sample_theta_BCM, sample_inh_rates_plastic = rec_net.run_net_plastic_exc_BCM_and_inh_plasticity( x, W, rec_net.theta_BCM, T_plastic, rec_net.N_sample, 'audiovisual_random', rec_net.N_orientations, 0, savefile) #x,W,pop_rate_plastic,sample_rates_plastic,sample_weights,mean_incoming_weight,theta_BCM,sample_theta_BCM,sample_inh_rates_plastic = rec_net.run_net_plastic_sliding_threshold(x,W,rec_net.theta_BCM,T_plastic,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) #x,W,pop_rate_plastic,sample_rates_plastic,sample_weights,sample_inh_weights,theta_BCM,sample_theta_BCM,mean_incoming_weight,sample_inh_rates_plastic = rec_net.run_net_pure_Hebbian_EE_and_inh_plasticity(x,W,rec_net.theta_BCM,T_plastic,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) #x,W,pop_rate_plastic,sample_rates_plastic,sample_weights,mean_incoming_weight,theta_BCM,sample_theta_BCM,sample_inh_rates_plastic = rec_net.run_net_plastic_sliding_threshold_taro_fluct(x,W,rec_net.theta_BCM,T_plastic,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) #x,W,pop_rate_plastic,sample_rates_plastic,sample_weights,sample_inh_weights,mean_incoming_weight,theta_BCM,sample_theta_BCM,sample_inh_rates_plastic = rec_net.run_net_static_threshold_exc_and_inh_plasticity_taro_fluct(x,W,rec_net.theta_BCM,T_plastic,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) x_plastic = x.copy() W_plastic = W.copy() theta_BCM_plastic = theta_BCM.copy() # Pruning synapses which are below 0.1 W_max W_plastic_pruned = W_plastic.copy( )[:, :rec_net.N_E] < rec_net.W_max * rec_net.prune_threshold W_plastic_pruned[W_plastic_pruned == 1] = np.random.binomial( 1, prob_prune, W_plastic_pruned[W_plastic_pruned == 1].shape) rec_net.W_pruned = W_plastic_pruned rec_net.pruned_synapses = True print 'pruned with threshold ', rec_net.prune_threshold #x,W,pop_rate_pruned,sample_rates_pruned,sample_weights_pruned,sample_inh_weights_pruned,mean_incoming_weight,theta_BCM,sample_theta_BCM_pruned,sample_inh_rates_pruned = rec_net.run_net_plastic_BCM_and_inh_plasticity(x,W,rec_net.theta_BCM,T_prune,rec_net.N_sample,'orientation_and_secondary_dynamic',rec_net.N_orientations) #x,W,pop_rate_pruned,sample_rates_pruned,sample_weights_pruned,sample_inh_weights_pruned,mean_incoming_weight,theta_BCM,sample_theta_BCM_pruned,sample_inh_rates_pruned = rec_net.run_net_static_threshold_exc_and_inh_plasticity(x,W,rec_net.theta_BCM,T_prune,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) x, W, pop_rate_pruned, sample_rates_pruned, sample_weights_pruned, sample_inh_weights_pruned, mean_incoming_weight, theta_BCM, sample_theta_BCM_pruned, sample_inh_rates_pruned = rec_net.run_net_plastic_exc_BCM_and_inh_plasticity( x, W, rec_net.theta_BCM, T_prune, rec_net.N_sample, 'audiovisual_random', rec_net.N_orientations) #x,W,pop_rate_pruned,sample_rates_pruned,sample_weights_pruned,mean_incoming_weight,theta_BCM,sample_theta_BCM_pruned,sample_inh_rates_pruned = rec_net.run_net_plastic_sliding_threshold(x,W,rec_net.theta_BCM,T_prune,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) #x,W,pop_rate_pruned,sample_rates_pruned,sample_weights_pruned,sample_inh_weights_pruned,theta_BCM,sample_theta_BCM_pruned,mean_incoming_weight,sample_inh_rates_pruned = rec_net.run_net_pure_Hebbian_EE_and_inh_plasticity(x,W,rec_net.theta_BCM,T_prune,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) #x,W,pop_rate_pruned,sample_rates_pruned,sample_weights_pruned,mean_incoming_weight,theta_BCM,sample_theta_BCM_pruned,sample_inh_rates_pruned = rec_net.run_net_plastic_sliding_threshold_taro_fluct(x,W,rec_net.theta_BCM,T_prune,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) #x,W,pop_rate_pruned,sample_rates_pruned,sample_weights_pruned,sample_inh_weights_pruned,mean_incoming_weight,theta_BCM,sample_theta_BCM_pruned,sample_inh_rates_pruned = rec_net.run_net_static_threshold_exc_and_inh_plasticity_taro_fluct(x,W,rec_net.theta_BCM,T_prune,rec_net.N_sample,'audiovisual_random',rec_net.N_orientations) x_pruned = x.copy() W_pruned = W.copy() theta_BCM_pruned = theta_BCM.copy() #rec_net.H_max = 0 #rec_net.H_min = 1.0 rec_net.secondary_paired_idx = [0, None, None, None, None] #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,sample_inh_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_plastic_BCM_and_inh_plasticity(x,W,theta_BCM,T_depriv,rec_net.N_sample,'orientation_and_secondary_dynamic',rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,sample_inh_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_static_threshold_exc_and_inh_plasticity(x,W,theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_paired',rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,sample_inh_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_plastic_exc_BCM_and_inh_plasticity(x,W,theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_paired_only_0',rec_net.N_orientations) x, W, pop_rate_depriv, sample_rates_depriv, sample_weights_depriv, sample_inh_weights_depriv, mean_incoming_weight_depriv, theta_BCM, sample_theta_BCM_depriv, sample_inh_rates_depriv = rec_net.run_net_plastic_exc_BCM_and_inh_plasticity( x, W, theta_BCM, T_pairstim, rec_net.N_sample, 'audiovisual_repeating_only_tone_0', rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,sample_inh_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_static_threshold_exc_and_inh_plasticity(x,W,theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_paired_only_0',rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,sample_inh_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_static_threshold_exc_and_inh_plasticity(x,W,theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_repeating_only_tone_0',rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_plastic_sliding_threshold(x,W,theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_paired',rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,sample_inh_weights_depriv,theta_BCM,sample_theta_BCM_depriv,mean_incoming_weight_depriv,sample_inh_rates_depriv = rec_net.run_net_pure_Hebbian_EE_and_inh_plasticity(x,W,rec_net.theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_paired',rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_plastic_sliding_threshold_taro_fluct(x,W,theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_paired',rec_net.N_orientations) #x,W,pop_rate_depriv,sample_rates_depriv,sample_weights_depriv,sample_inh_weights_depriv,mean_incoming_weight_depriv,theta_BCM,sample_theta_BCM_depriv,sample_inh_rates_depriv = rec_net.run_net_static_threshold_exc_and_inh_plasticity_taro_fluct(x,W,theta_BCM,T_pairstim,rec_net.N_sample,'audiovisual_paired',rec_net.N_orientations) x_depriv = x.copy() W_depriv = W.copy() results = { 'pop_rate_plastic': pop_rate_plastic, 'pop_rate_depriv': pop_rate_depriv, 'x_static': x_static, 'x_pruned': x_pruned, 'x_plastic': x_plastic, 'x_depriv': x_depriv, 'W_static': W_static, 'W_plastic': W_plastic, 'W_plastic_pruned': W_plastic_pruned, 'W_depriv': W_depriv, 'sample_weights': sample_weights, 'sample_weights_depriv': sample_weights_depriv, 'sample_theta_BCM': sample_theta_BCM, 'sample_theta_BCM_depriv': sample_theta_BCM_depriv, 'sample_rates_plastic': sample_rates_plastic, 'sample_rates_static': sample_rates_static, 'sample_rates_depriv': sample_rates_depriv, 'sample_inh_rates_plastic': sample_inh_rates_plastic, 'sample_inh_rates_depriv': sample_inh_rates_depriv, 'pop_rate_pruned': pop_rate_pruned, 'W_pruned': W_pruned, 'W_plastic_pruned': W_plastic_pruned, 'sample_weights_pruned': sample_weights_pruned, 'sample_theta_BCM_pruned': sample_theta_BCM_pruned, 'sample_rates_pruned': sample_rates_pruned, 'sample_inh_rates_pruned': sample_inh_rates_pruned, 'sample_inh_weights': sample_inh_weights, 'sample_inh_weights_pruned': sample_inh_weights_pruned, 'sample_inh_weights_depriv': sample_inh_weights_depriv, 'secondary_groups': rec_net.secondary_groups, 'visual_groups': rec_net.visual_groups, 'rec_net_pars': rec_net_pars } if not savefile == None: py_scripts_yann.save_pickle_safe('pkl_results/' + savefile, results) return results
t = numpy.arange(0, 1000.0, dt) rate = numpy.ones_like(t) * 20.0 # stepup i_start = t.searchsorted(400.0, 'right') - 1 i_end = t.searchsorted(600.0, 'right') - 1 rate[i_start:i_end] = 40.0 a = numpy.ones_like(t) * 3.0 b = numpy.ones_like(t) / a / rate psth = zeros_like(t) stg = stgen.StGen() trials = 5000 tsim = 1000.0 print "Running %d trials of %.2f milliseconds" % (trials, tsim) for i in xrange(trials): if i % 100 == 0: print "%d" % i, sys.stdout.flush() st = stg.inh_gamma_generator(a, b, t, 1000.0, array=True) psth[1:] += numpy.histogram(st, t)[0] print "\n" # normalize
def run(sim): """ Run the mcb simulation with known random numbers for the given simulator backend""" stg = stgen.StGen() stg.seed(12345) rateE = 6.0 # firing rate of ghost excitatory neurons rateI = 10.5 # firing rate of ghost inhibitoryneurons connectionsE = 1000.0 # number of E connections every neuron recieves connectionsI = 250.0 # number of I connections every neuron recieves tsim = 1000.0 # ms globalWeight = 0.002 # Weights of all connection in uS dt = 0.01 # simulation time step in milliseconds sim.setup(timestep=dt, min_delay=dt, max_delay=30.0, debug=True, quit_on_end=False) params = NeuroTools.parameters.ParameterSet('standard_neurons.yaml') myModel = sim.IF_cond_exp_gsfa_grr popE = sim.Population((1, ), myModel, params.excitatory, label='popE') popI = sim.Population((1, ), myModel, params.inhibitory, label='popI') #poissonE_params = {'rate': rateE*connectionsE, 'start': 0.0, 'duration': tsim} #poissonE_params = {'rate': rateE, 'start': 0.0, 'duration': tsim} #poissonI_params = {'rate': rateI*connectionsI, 'start': 0.0, 'duration': tsim} #poissonI_params = {'rate': rateI, 'start': 0.0, 'duration': tsim} spike_times_E = stg.poisson_generator(rateE * connectionsE, 0.0, tsim, array=True) spike_times_I = stg.poisson_generator(rateI * connectionsI, 0.0, tsim, array=True) poissonE = sim.Population((1, ), cellclass=sim.SpikeSourceArray, cellparams={'spike_times': spike_times_E}, label='poissonE') poissonI = sim.Population((1, ), cellclass=sim.SpikeSourceArray, cellparams={'spike_times': spike_times_I}, label='poissonI') myconn = sim.AllToAllConnector(weights=globalWeight, delays=dt) prjE_E = sim.Projection(poissonE, popE, method=myconn, target='excitatory') prjI_E = sim.Projection(poissonI, popE, method=myconn, target='inhibitory') prjE_I = sim.Projection(poissonE, popI, method=myconn, target='excitatory') prjI_I = sim.Projection(poissonI, popI, method=myconn, target='inhibitory') ## Record the spikes ## popE.record(to_file=False) popE.record_v(to_file=False) popE.record_gsyn(to_file=False) popI.record(to_file=False) popI.record_v(to_file=False) popI.record_gsyn(to_file=False) #popE.record() #popE.record_v() #popI.record() #popI.record_v() sim.run(tsim) ## Get spikes ## spikesE = popE.getSpikes() v_E = popE.get_v() g_E = popE.get_gsyn() spikesI = popI.getSpikes() v_I = popE.get_v() g_I = popI.get_gsyn() #print(spikesE) # should be about 6.0Hz print(float(len(spikesE)) / tsim * 1000.0) # should be about 10.0Hz print(float(len(spikesI)) / tsim * 1000.0) sim.end() return spikesE, spikesI, v_E, v_I, g_E, g_I
def testStatsInhPoisson(self): # this is a statistical test with non-zero chance of failure stg = stgen.StGen() rate = 100.0 #Hz t_start = 500.0 t_stop = 1500.0 # milliseconds st = stg.inh_poisson_generator(numpy.array([rate]), numpy.array([t_start]), t_stop, array=True) assert st[-1] < t_stop assert st[0] > t_start # last spike should not be more than 4 ISI away from t_stop err = """ Last spike should not be more than 4 ISI behind t_stop. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" if st[-1] < t_stop - 4.0 * 1.0 / rate * 1000.0: raise StatisticalError(err) # first spike should not be more than 4 ISI away from t_start err = """ First spike should not be more than 4 ISI in front of t_start. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" if st[0] > t_start + 4.0 * 1.0 / rate * 1000.0: raise StatisticalError(err) err = """ Number of spikes should be within 3 standard deviations of mean. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" # time interval is one second if len(st) > rate + 3.0 * numpy.sqrt(rate) or len( st) < rate - 3.0 * numpy.sqrt(rate): raise StatisticalError(err) # step in the rate st = stg.inh_poisson_generator(numpy.array([100.0, 200.0]), numpy.array([500.0, 1500.0]), 2500.0, array=True) n1 = len(st[st < 1500.0]) n2 = len(st[st > 1500.0]) err = """ Number of spikes should be within 3 standard deviations of mean. There is a non-zero chance for this to occur during normal operation. Re-run the test to see if the error persists.""" if n2 > 200.0 + 3.0 * numpy.sqrt( 200.0) or n2 < 200.0 - 3.0 * numpy.sqrt(200.0): raise StatisticalError(err) if n1 > 100.0 + 3.0 * numpy.sqrt( 100.0) or n1 < 100.0 - 3.0 * numpy.sqrt(100.0): raise StatisticalError(err)
def testCreateWithNoArgs(self): """ With no arguments for the constructor, we should get a Numpy RNG. """ stg = stgen.StGen() assert isinstance(stg.rng, numpy.random.RandomState)