コード例 #1
0
 def plot_mean_firing_rates(self, trials, plt_title='Mean Firing Rates'):
     if self.record_firing_rates:
         mean_e_pop_rates=[]
         std_e_pop_rates=[]
         for i in range(self.network_params.num_groups):
             pop_rate_mat=np.array(self.pop_rates['excitatory_rate_%d' % i])
             mean_e_pop_rates.append(np.mean(pop_rate_mat[trials,:],axis=0))
             std_e_pop_rates.append(np.std(pop_rate_mat[trials,:],axis=0)/np.sqrt(len(trials)))
         mean_e_pop_rates=np.array(mean_e_pop_rates)
         std_e_pop_rates=np.array(std_e_pop_rates)
         pop_rate_mat=np.array(self.pop_rates['inhibitory_rate'])
         mean_i_pop_rate=np.mean(pop_rate_mat[trials,:],axis=0)
         std_i_pop_rate=np.std(pop_rate_mat[trials,:],axis=0)/np.sqrt(len(trials))
         plot_network_firing_rates(np.array(mean_e_pop_rates), self.sim_params, self.network_params,
             std_e_rates=std_e_pop_rates, i_rate=mean_i_pop_rate, std_i_rate=std_i_pop_rate, plt_title=plt_title)
コード例 #2
0
 def plot_sorted_mean_firing_rates(self, trials, plt_title='Mean Firing Rates'):
     if self.record_firing_rates:
         chosen_pop_rates=[]
         unchosen_pop_rates=[]
         for trial_idx in trials:
             resp=self.trial_resp[0,trial_idx]
             if resp>-1:
                 chosen_pop_rates.append(self.pop_rates['excitatory_rate_%d' % resp][trial_idx])
                 unchosen_pop_rates.append(self.pop_rates['excitatory_rate_%d' % (1-resp)][trial_idx])
         if len(chosen_pop_rates)>1:
             chosen_pop_rates=np.array(chosen_pop_rates)
             unchosen_pop_rates=np.array(unchosen_pop_rates)
             mean_e_pop_rates=np.array([np.mean(chosen_pop_rates,axis=0), np.mean(unchosen_pop_rates,axis=0)])
             std_e_pop_rates=np.array([np.std(chosen_pop_rates,axis=0)/np.sqrt(len(trials)),
                                       np.std(unchosen_pop_rates,axis=0)/np.sqrt(len(trials))])
             plot_network_firing_rates(np.array(mean_e_pop_rates), self.sim_params, self.network_params,
                 std_e_rates=std_e_pop_rates, plt_title=plt_title, labels=['chosen','unchosen'])
コード例 #3
0
    def plot(self):

        # Spike raster plots
        if self.record_spikes:
            num_plots=self.network_params.num_groups+1
            figure()
            for i in range(self.network_params.num_groups):
                subplot(num_plots,1,i+1)
                raster_plot(self.monitors['excitatory_spike_%d' % i],newfigure=False)
            subplot(num_plots,1,num_plots)
            raster_plot(self.monitors['inhibitory_spike'],newfigure=False)

        # Network firing rate plots
        if self.record_firing_rate:

            e_rate_0=self.monitors['excitatory_rate_0'].smooth_rate(width=5*ms)/hertz
            e_rate_1=self.monitors['excitatory_rate_1'].smooth_rate(width=5*ms)/hertz
            i_rate=self.monitors['inhibitory_rate'].smooth_rate(width=5*ms)/hertz
            plot_network_firing_rates(np.array([e_rate_0, e_rate_1]), i_rate, self.sim_params, self.network_params)

        # Input firing rate plots
        if self.record_inputs:
            figure()
            ax=subplot(111)
            max_rate=0
            task_rates=[]
            for i in range(self.network_params.num_groups):
                task_monitor=self.monitors['task_rate_%d' % i]
                task_rate=task_monitor.smooth_rate(width=5*ms,filter='gaussian')/hertz
                if np.max(task_rate)>max_rate:
                    max_rate=np.max(task_rate)
                task_rates.append(task_rate)

            rect=Rectangle((0,0),(self.sim_params.stim_end_time-self.sim_params.stim_start_time)/ms, max_rate+5,
                alpha=0.25, facecolor='yellow', edgecolor='none')
            ax.add_patch(rect)
            #            ax.plot(self.monitors['background_rate'].times/ms,
            #                self.monitors['background_rate'].smooth_rate(width=5*ms)/hertz)
            for i in range(self.network_params.num_groups):
                ax.plot((np.array(range(len(task_rates[i])))*self.sim_params.dt)/ms-self.sim_params.stim_start_time/ms, task_rates[i])
            ylim(0,90)
            ylabel('Firing rate (Hz)')
            xlabel('Time (ms)')

        # Network state plots
        if self.record_neuron_state:
            network_monitor=self.monitors['network']
            max_conductances=[]
            for neuron_idx in self.record_idx:
                max_conductances.append(np.max(network_monitor['g_ampa_r'][neuron_idx]/nS))
                max_conductances.append(np.max(network_monitor['g_ampa_x'][neuron_idx]/nS))
                max_conductances.append(np.max(network_monitor['g_ampa_b'][neuron_idx]/nS))
                max_conductances.append(np.max(network_monitor['g_nmda'][neuron_idx]/nS))
                max_conductances.append(np.max(network_monitor['g_gaba_a'][neuron_idx]/nS))
                #max_conductances.append(np.max(self.network_monitor['g_gaba_b'][neuron_idx]/nS))
            max_conductance=np.max(max_conductances)

            fig=figure()
            for i in range(self.network_params.num_groups):
                neuron_idx=self.record_idx[i]
                ax=subplot(int('%d1%d' % (self.network_params.num_groups+1,i+1)))
                title('e%d' % i)
                ax.plot(network_monitor['g_ampa_r'].times/ms, network_monitor['g_ampa_r'][neuron_idx]/nS,
                    label='AMPA-recurrent')
                ax.plot(network_monitor['g_ampa_x'].times/ms, network_monitor['g_ampa_x'][neuron_idx]/nS,
                    label='AMPA-task')
                ax.plot(network_monitor['g_ampa_b'].times/ms, network_monitor['g_ampa_b'][neuron_idx]/nS,
                    label='AMPA-backgrnd')
                ax.plot(network_monitor['g_nmda'].times/ms, network_monitor['g_nmda'][neuron_idx]/nS,
                    label='NMDA')
                ax.plot(network_monitor['g_gaba_a'].times/ms, network_monitor['g_gaba_a'][neuron_idx]/nS,
                    label='GABA_A')
                #ax.plot(network_monitor['g_gaba_b'].times/ms, network_monitor['g_gaba_b'][neuron_idx]/nS,
                #    label='GABA_B')
                ylim(0,max_conductance)
                xlabel('Time (ms)')
                ylabel('Conductance (nS)')
                legend()

            neuron_idx=self.record_idx[self.network_params.num_groups]
            ax=subplot('%d1%d' % (self.network_params.num_groups+1,self.network_params.num_groups+1))
            title('i')
            ax.plot(network_monitor['g_ampa_r'].times/ms, network_monitor['g_ampa_r'][neuron_idx]/nS,
                label='AMPA-recurrent')
            ax.plot(network_monitor['g_ampa_x'].times/ms, network_monitor['g_ampa_x'][neuron_idx]/nS,
                label='AMPA-task')
            ax.plot(network_monitor['g_ampa_b'].times/ms, network_monitor['g_ampa_b'][neuron_idx]/nS,
                label='AMPA-backgrnd')
            ax.plot(network_monitor['g_nmda'].times/ms, network_monitor['g_nmda'][neuron_idx]/nS,
                label='NMDA')
            ax.plot(network_monitor['g_gaba_a'].times/ms, network_monitor['g_gaba_a'][neuron_idx]/nS,
                label='GABA_A')
            #ax.plot(network_monitor['g_gaba_b'].times/ms, network_monitor['g_gaba_b'][neuron_idx]/nS,
            #    label='GABA_B')
            ylim(0,max_conductance)
            xlabel('Time (ms)')
            ylabel('Conductance (nS)')
            legend()

            min_currents=[]
            max_currents=[]
            for neuron_idx in self.record_idx:
                max_currents.append(np.max(network_monitor['I_ampa_r'][neuron_idx]/nS))
                max_currents.append(np.max(network_monitor['I_ampa_x'][neuron_idx]/nS))
                max_currents.append(np.max(network_monitor['I_ampa_b'][neuron_idx]/nS))
                max_currents.append(np.max(network_monitor['I_nmda'][neuron_idx]/nS))
                max_currents.append(np.max(network_monitor['I_gaba_a'][neuron_idx]/nS))
                #max_currents.append(np.max(network_monitor['I_gaba_b'][neuron_idx]/nS))
                min_currents.append(np.min(network_monitor['I_ampa_r'][neuron_idx]/nS))
                min_currents.append(np.min(network_monitor['I_ampa_x'][neuron_idx]/nS))
                min_currents.append(np.min(network_monitor['I_ampa_b'][neuron_idx]/nS))
                min_currents.append(np.min(network_monitor['I_nmda'][neuron_idx]/nS))
                min_currents.append(np.min(network_monitor['I_gaba_a'][neuron_idx]/nS))
                #min_currents.append(np.min(network_monitor['I_gaba_b'][neuron_idx]/nS))
            max_current=np.max(max_currents)
            min_current=np.min(min_currents)

            fig=figure()
            for i in range(self.network_params.num_groups):
                ax=subplot(int('%d1%d' % (self.network_params.num_groups+1,i+1)))
                neuron_idx=self.record_idx[i]
                title('e%d' % i)
                ax.plot(network_monitor['I_ampa_r'].times/ms, network_monitor['I_ampa_r'][neuron_idx]/nA,
                    label='AMPA-recurrent')
                ax.plot(network_monitor['I_ampa_x'].times/ms, network_monitor['I_ampa_x'][neuron_idx]/nA,
                    label='AMPA-task')
                ax.plot(network_monitor['I_ampa_b'].times/ms, network_monitor['I_ampa_b'][neuron_idx]/nA,
                    label='AMPA-backgrnd')
                ax.plot(network_monitor['I_nmda'].times/ms, network_monitor['I_nmda'][neuron_idx]/nA,
                    label='NMDA')
                ax.plot(network_monitor['I_gaba_a'].times/ms, network_monitor['I_gaba_a'][neuron_idx]/nA,
                    label='GABA_A')
                #ax.plot(network_monitor['I_gaba_b'].times/ms, network_monitor['I_gaba_b'][neuron_idx]/nA,
                #    label='GABA_B')
                ylim(min_current,max_current)
                xlabel('Time (ms)')
                ylabel('Current (nA)')
                legend()

            ax=subplot(int('%d1%d' % (self.network_params.num_groups+1,self.network_params.num_groups+1)))
            neuron_idx=self.record_idx[self.network_params.num_groups]
            title('i')
            ax.plot(network_monitor['I_ampa_r'].times/ms, network_monitor['I_ampa_r'][neuron_idx]/nA,
                label='AMPA-recurrent')
            ax.plot(network_monitor['I_ampa_x'].times/ms, network_monitor['I_ampa_x'][neuron_idx]/nA,
                label='AMPA-task')
            ax.plot(network_monitor['I_ampa_b'].times/ms, network_monitor['I_ampa_b'][neuron_idx]/nA,
                label='AMPA-backgrnd')
            ax.plot(network_monitor['I_nmda'].times/ms, network_monitor['I_nmda'][neuron_idx]/nA,
                label='NMDA')
            ax.plot(network_monitor['I_gaba_a'].times/ms, network_monitor['I_gaba_a'][neuron_idx]/nA,
                label='GABA_A')
            #ax.plot(network_monitor['I_gaba_b'].times/ms, network_monitor['I_gaba_b'][neuron_idx]/nA,
            #    label='GABA_B')
            ylim(min_current,max_current)
            xlabel('Time (ms)')
            ylabel('Current (nA)')
            legend()

        # LFP plot
        if self.record_lfp:
            figure()
            ax=subplot(111)
            ax.plot(self.monitors['lfp'].times / ms, self.monitors['lfp'][0]/mA)
            xlabel('Time (ms)')
            ylabel('LFP (mA)')

        # Voxel activity plots
        if self.record_voxel:
            voxel_monitor=self.monitors['voxel']
            voxel_exc_monitor=None
            if 'voxel_exc' in self.monitors:
                voxel_exc_monitor=self.monitors['voxel_exc']
            syn_max=np.max(voxel_monitor['G_total'][0] / nS)
            y_max=np.max(voxel_monitor['y'][0])
            y_min=np.min(voxel_monitor['y'][0])
            figure()
            if voxel_exc_monitor is None:
                ax=subplot(211)
            else:
                ax=subplot(221)
                syn_max=np.max([syn_max, np.max(voxel_exc_monitor['G_total'][0])])
                y_max=np.max([y_max, np.max(voxel_exc_monitor['y'][0])])
                y_min=np.min([y_min, np.min(voxel_exc_monitor['y'][0])])
            ax.plot(voxel_monitor['G_total'].times / ms, voxel_monitor['G_total'][0] / nS)
            xlabel('Time (ms)')
            ylabel('Total Synaptic Activity (nS)')
            ylim(0, syn_max)
            if voxel_exc_monitor is None:
                ax=subplot(212)
            else:
                ax=subplot(222)
            ax.plot(voxel_monitor['y'].times / ms, voxel_monitor['y'][0])
            xlabel('Time (ms)')
            ylabel('BOLD')
            ylim(y_min, y_max)
            if voxel_exc_monitor is not None:
                ax=subplot(223)
                ax.plot(voxel_exc_monitor['G_total'].times / ms, voxel_exc_monitor['G_total'][0] / nS)
                xlabel('Time (ms)')
                ylabel('Total Synaptic Activity (nS)')
                ylim(0, syn_max)
                ax=subplot(224)
                ax.plot(voxel_exc_monitor['y'].times / ms, voxel_exc_monitor['y'][0])
                xlabel('Time (ms)')
                ylabel('BOLD')
                ylim(y_min, y_max)

        if self.record_connections:
            figure()
            ax=subplot(111)
            for mon in self.monitors:
                if mon.startswith('connection_'):
                    conn_name=mon[11:]
                    conns=np.zeros((len(self.monitors[mon].values),1))
                    conn_times=[]
                    for idx, (time, conn_matrix) in enumerate(self.monitors[mon].values):
                        conn_diag=np.diagonal(conn_matrix.todense())
                        mean_w=np.mean(conn_diag)
                        conns[idx,0]=mean_w
                        conn_times.append(time)
                    ax.plot(np.array(conn_times) / ms, conns[:,0]/nS, label=conn_name)
            legend(loc='best')
            xlabel('Time (ms)')
            ylabel('Connection Weight (nS)')