Example #1
0
    def create_populations(self):
        """ Creates the neuronal populations.

        The neuronal populations are created and the parameters are assigned
        to them. The initial membrane potential of the neurons is drawn from a
        normal distribution. Scaling of the number of neurons and of the
        synapses is performed. If scaling is performed extra DC input is added
        to the neuronal populations.

        """
        self.N_full = self.net_dict['N_full']
        self.N_scaling = self.net_dict['N_scaling']
        self.K_scaling = self.net_dict['K_scaling']
        self.synapses = get_total_number_of_synapses(self.net_dict)
        self.synapses_scaled = self.synapses * self.K_scaling
        self.nr_neurons = self.N_full * self.N_scaling
        self.K_ext = self.net_dict['K_ext'] * self.K_scaling
        self.w_from_PSP = get_weight(self.net_dict['PSP_e'], self.net_dict)
        self.weight_mat = get_weight(self.net_dict['PSP_mean_matrix'],
                                     self.net_dict)
        self.weight_mat_std = self.net_dict['PSP_std_matrix']
        self.w_ext = self.w_from_PSP
        if self.net_dict['poisson_input']:
            self.DC_amp_e = np.zeros(len(self.net_dict['populations']))
        else:
            if nest.Rank() == 0:
                print("""
                    no poisson input provided
                    calculating dc input to compensate
                    """)
            self.DC_amp_e = compute_DC(self.net_dict, self.w_ext)

        v0_type_options = ['original', 'optimized']
        if self.net_dict['V0_type'] not in v0_type_options:
            print('''
                '{0}' is not a valid option, replacing it with '{1}'
                Valid options are {2}
                '''.format(self.net_dict['V0_type'], v0_type_options[0],
                           v0_type_options))
            self.net_dict['V0_type'] = v0_type_options[0]
        if nest.Rank() == 0:
            print('The number of neurons is scaled by a factor of: %.2f' %
                  self.N_scaling)
            print('The number of synapses is scaled by a factor of: %.2f' %
                  self.K_scaling)

        # Scaling of the synapses.
        if self.K_scaling != 1:
            synapses_indegree = self.synapses / (
                self.N_full.reshape(len(self.N_full), 1) * self.N_scaling)
            self.weight_mat, self.w_ext, self.DC_amp_e = adj_w_ext_to_K(
                synapses_indegree, self.K_scaling, self.weight_mat,
                self.w_from_PSP, self.DC_amp_e, self.net_dict, self.stim_dict)

        # Create cortical populations.
        self.pops = []
        pop_file = open(os.path.join(self.data_path, 'population_nodeids.dat'),
                        'w+')
        for i, pop in enumerate(self.net_dict['populations']):
            population = nest.Create(self.net_dict['neuron_model'],
                                     int(self.nr_neurons[i]))
            population.set({
                'tau_syn_ex':
                self.net_dict['neuron_params']['tau_syn_ex'],
                'tau_syn_in':
                self.net_dict['neuron_params']['tau_syn_in'],
                'E_L':
                self.net_dict['neuron_params']['E_L'],
                'V_th':
                self.net_dict['neuron_params']['V_th'],
                'V_reset':
                self.net_dict['neuron_params']['V_reset'],
                't_ref':
                self.net_dict['neuron_params']['t_ref'],
                'I_e':
                self.DC_amp_e[i]
            })
            if self.net_dict['V0_type'] == 'optimized':
                population.set(
                    V_m=nest.random.normal(mean=self.net_dict['neuron_params']
                                           ['V0_mean']['optimized'][i],
                                           std=self.net_dict['neuron_params']
                                           ['V0_sd']['optimized'][i]))
            elif self.net_dict['V0_type'] == 'original':
                population.set(V_m=nest.random.normal(
                    mean=self.net_dict['neuron_params']['V0_mean']['original'],
                    std=self.net_dict['neuron_params']['V0_sd']['original']))
            self.pops.append(population)
            pop_file.write('%d  %d \n' % (population[0].get('global_id'),
                                          population[-1].get('global_id')))
        pop_file.close()
Example #2
0
    def create_populations(self):
        """ Creates the neuronal populations.

        The neuronal populations are created and the parameters are assigned
        to them. The initial membrane potential of the neurons is drawn from a
        normal distribution. Scaling of the number of neurons and of the
        synapses is performed. If scaling is performed extra DC input is added
        to the neuronal populations.

        """
        self.N_full = self.net_dict['N_full']
        self.N_scaling = self.net_dict['N_scaling']
        self.K_scaling = self.net_dict['K_scaling']
        self.synapses = get_total_number_of_synapses(self.net_dict)
        self.synapses_scaled = self.synapses * self.K_scaling
        self.nr_neurons = self.N_full * self.N_scaling
        self.K_ext = self.net_dict['K_ext'] * self.K_scaling
        self.w_from_PSP = get_weight(self.net_dict['PSP_e'], self.net_dict)
        self.weight_mat = get_weight(
            self.net_dict['PSP_mean_matrix'], self.net_dict
            )
        self.weight_mat_std = self.net_dict['PSP_std_matrix']
        self.w_ext = self.w_from_PSP
        if self.net_dict['poisson_input']:
            self.DC_amp_e = np.zeros(len(self.net_dict['populations']))
        else:
            if nest.Rank() == 0:
                print(
                    '''
                    no poisson input provided
                    calculating dc input to compensate
                    '''
                    )
            self.DC_amp_e = compute_DC(self.net_dict, self.w_ext)

        if nest.Rank() == 0:
            print(
                'The number of neurons is scaled by a factor of: %.2f'
                % self.N_scaling
                )
            print(
                'The number of synapses is scaled by a factor of: %.2f'
                % self.K_scaling
                )

        # Scaling of the synapses.
        if self.K_scaling != 1:
            synapses_indegree = self.synapses / (
                self.N_full.reshape(len(self.N_full), 1) * self.N_scaling)
            self.weight_mat, self.w_ext, self.DC_amp_e = adj_w_ext_to_K(
                synapses_indegree, self.K_scaling, self.weight_mat,
                self.w_from_PSP, self.DC_amp_e, self.net_dict, self.stim_dict
                )

        # Create cortical populations.
        self.pops = []
        pop_file = open(
            os.path.join(self.data_path, 'population_GIDs.dat'), 'w+'
            )
        for i, pop in enumerate(self.net_dict['populations']):
            population = nest.Create(
                self.net_dict['neuron_model'], int(self.nr_neurons[i])
                )
            nest.SetStatus(
                population, {
                    'tau_syn_ex': self.net_dict['neuron_params']['tau_syn_ex'],
                    'tau_syn_in': self.net_dict['neuron_params']['tau_syn_in'],
                    'E_L': self.net_dict['neuron_params']['E_L'],
                    'V_th': self.net_dict['neuron_params']['V_th'],
                    'V_reset':  self.net_dict['neuron_params']['V_reset'],
                    't_ref': self.net_dict['neuron_params']['t_ref'],
                    'I_e': self.DC_amp_e[i]
                    }
                )
            self.pops.append(population)
            pop_file.write('%d  %d \n' % (population[0], population[-1]))
        pop_file.close()
        for thread in np.arange(nest.GetKernelStatus('local_num_threads')):
            # Using GetNodes is a work-around until NEST 3.0 is released. It
            # will issue a deprecation warning.
            local_nodes = nest.GetNodes(
                [0], {
                    'model': self.net_dict['neuron_model'],
                    'thread': thread
                    }, local_only=True
                )[0]
            vp = nest.GetStatus(local_nodes)[0]['vp']
            # vp is the same for all local nodes on the same thread
            nest.SetStatus(
                local_nodes, 'V_m', self.pyrngs[vp].normal(
                    self.net_dict['neuron_params']['V0_mean'],
                    self.net_dict['neuron_params']['V0_sd'],
                    len(local_nodes))
                    )
    def create_populations(self):
        """ Creates the neuronal populations.

        The neuronal populations are created and the parameters are assigned
        to them. The initial membrane potential of the neurons is drawn from a
        normal distribution. Scaling of the number of neurons and of the
        synapses is performed. If scaling is performed extra DC input is added
        to the neuronal populations.

        """

        # -------------------------------------------
        '''Find model parameters'''
        # -------------------------------------------

        # Full model parameters
        self.N_full = self.net_dict['N_full']  # Full number of neurons
        self.synapses = get_total_number_of_synapses(
            self.net_dict)  # Full number of synapses

        # Scaling parameters
        self.N_scaling = self.net_dict['N_scaling']  # Neuron number scaling
        self.K_scaling = self.net_dict['K_scaling']  # Synapse number scaling

        # Scaled parameters
        self.nr_neurons = self.N_full * self.N_scaling  # Scaled number of neurons
        self.synapses_scaled = self.synapses * self.K_scaling  # Scaled (internal) synapses
        self.K_ext = self.net_dict[
            'K_ext'] * self.K_scaling  # Scaled (external) synapses

        # Calculated weights (to achieve a given change in the membrane potential)
        self.w_from_PSP = get_weight(self.net_dict['PSP_e'], self.net_dict)
        self.weight_mat = get_weight(self.net_dict['PSP_mean_matrix'],
                                     self.net_dict)
        self.weight_mat_std = self.net_dict['PSP_std_matrix']
        self.w_ext = self.w_from_PSP

        # Network simulated with Poisson input, or DC current?
        if self.net_dict['poisson_input']:
            self.DC_amp_e = np.zeros(len(self.net_dict['populations']))
        else:
            if nest.Rank() == 0:
                print("""
                    no poisson input provided
                    calculating dc input to compensate
                    """)
            self.DC_amp_e = compute_DC(self.net_dict, self.w_ext)

        # Scaling of the synapses.
        if nest.Rank() == 0:
            print('The number of neurons is scaled by a factor of: %.2f' %
                  self.N_scaling)
            print('The number of synapses is scaled by a factor of: %.2f' %
                  self.K_scaling)
        if self.K_scaling != 1:
            synapses_indegree = self.synapses / (
                self.N_full.reshape(len(self.N_full), 1) * self.N_scaling)
            self.weight_mat, self.w_ext, self.DC_amp_e = adj_w_ext_to_K(
                synapses_indegree, self.K_scaling, self.weight_mat,
                self.w_from_PSP, self.DC_amp_e, self.net_dict, self.stim_dict)

        # -------------------------------------------
        '''Create cortical population'''
        # -------------------------------------------

        # Initialise data stores
        self.pops = []
        pop_file = open(os.path.join(self.data_path, 'population_GIDs.dat'),
                        'w+')

        # Loop over populations
        for i, pop in enumerate(self.net_dict['populations']):

            # Create a population of a given size
            population = nest.Create(self.net_dict['neuron_model'],
                                     int(self.nr_neurons[i]))

            # Set the parameters for this population
            '''Note that no tau_m is stated here (meaning that all neurons have a default
            of 10ms. It is interesting to note that, in the paper by Mejias et al. (2016),
            the following tau_m values were used:
                For superficial neurons: τE = 6 ms, τI = 15 ms
                For infragranular neurons: τE = 30 ms, τI = 75 ms
            '''

            nest.SetStatus(
                population,
                {
                    'tau_syn_ex': self.net_dict['neuron_params']['tau_syn_ex'],
                    'tau_syn_in': self.net_dict['neuron_params']['tau_syn_in'],
                    'E_L': self.net_dict['neuron_params']['E_L'],
                    'V_th': self.net_dict['neuron_params']['V_th'],
                    'V_reset': self.net_dict['neuron_params']['V_reset'],
                    't_ref': self.net_dict['neuron_params']['t_ref'],
                    'I_e': self.DC_amp_e[i]  #,
                    # 'tau_m': self.net_dict['time_constants'][i]
                })

            # Save population to file
            self.pops.append(population)
            pop_file.write('%d  %d \n' % (population[0], population[-1]))
        pop_file.close()

        # Something about processing threads
        for thread in np.arange(nest.GetKernelStatus('local_num_threads')):
            # Using GetNodes is a work-around until NEST 3.0 is released. It
            # will issue a deprecation warning.
            local_nodes = nest.GetNodes([0], {
                'model': self.net_dict['neuron_model'],
                'thread': thread
            },
                                        local_only=True)[0]
            vp = nest.GetStatus(local_nodes)[0]['vp']
            # vp is the same for all local nodes on the same thread
            nest.SetStatus(
                local_nodes, 'V_m', self.pyrngs[vp].normal(
                    self.net_dict['neuron_params']['V0_mean'],
                    self.net_dict['neuron_params']['V0_sd'], len(local_nodes)))