Esempio n. 1
0
    def __init__(self, subj_id, wta_params=default_params(), pyr_params=pyr_params(), inh_params=inh_params(),
                 plasticity_params=plasticity_params(), sim_params=simulation_params()):
        self.subj_id = subj_id
        self.wta_params = wta_params
        self.pyr_params = pyr_params
        self.inh_params = inh_params
        self.plasticity_params = plasticity_params
        self.sim_params = sim_params

        self.simulation_clock = Clock(dt=self.sim_params.dt)
        self.input_update_clock = Clock(dt=1 / (self.wta_params.refresh_rate / Hz) * second)

        self.background_input = PoissonGroup(self.wta_params.background_input_size,
            rates=self.wta_params.background_freq, clock=self.simulation_clock)
        self.task_inputs = []
        for i in range(self.wta_params.num_groups):
            self.task_inputs.append(PoissonGroup(self.wta_params.task_input_size,
                rates=self.wta_params.task_input_resting_rate, clock=self.simulation_clock))

        # Create WTA network
        self.wta_network = WTANetworkGroup(params=self.wta_params, background_input=self.background_input,
            task_inputs=self.task_inputs, pyr_params=self.pyr_params, inh_params=self.inh_params,
            plasticity_params=self.plasticity_params, clock=self.simulation_clock)


        # Create network monitor
        self.wta_monitor = WTAMonitor(self.wta_network, None, None, self.sim_params, record_lfp=False,
                                      record_voxel=False, record_neuron_state=False, record_spikes=False,
                                      record_firing_rate=True, record_inputs=True, record_connections=None,
                                      save_summary_only=False, clock=self.simulation_clock)


        # Create Brian network and reset clock
        self.net = Network(self.background_input, self.task_inputs, self.wta_network,
            self.wta_network.connections.values(), self.wta_monitor.monitors.values())
Esempio n. 2
0
def run_virtual_subjects(subj_ids, conditions, output_dir, behavioral_param_file):
    """
    Runs a set of virtual subjects on the given conditions
    subj_ids = list of subject IDs
    conditions = dictionary: {condition name: (simulation_params, reinit, coherence levels)}, reinit = whether or not
        to reinitialize state variables before running condition
    output_dir = directory to store h5 output files
    behavioral_param_file = h5 file containing softmax-RL parameter distributions, background freq is sampled using
        inverse temp param distribution
    """

    # Load alpha and beta params of control group from behavioral parameter file
    f = h5py.File(behavioral_param_file)
    control_group=f['control']
    alpha_vals=np.array(control_group['alpha'])
    beta_vals=np.array(control_group['beta'])

    # Run each subject
    for subj_id in subj_ids:
        print('***** Running subject %d *****' % subj_id)

        # Sample beta from subject distribution - don't use subjects with high alpha
        # beta_hist,beta_bins=np.histogram(beta_vals[np.where(alpha_vals<.99)[0]], density=True)
        # bin_width=beta_bins[1]-beta_bins[0]
        # beta_bin=np.random.choice(beta_bins[:-1], p=beta_hist*bin_width)
        # beta=beta_bin+np.random.rand()*bin_width

        beta = 7.329377505


        # Create virtual subject parameters - background freq from beta dist, resp threshold between 20 and 30Hz
        wta_params=default_params(background_freq=(beta-161.08)/-.17, resp_threshold=25)  #15+np.random.uniform(10)) #20
        # Set initial input weights #2 and 0.85. 1.9 and 0.95
        plasticity_pyr_params=pyr_params(w_nmda=0.145*nS, w_ampa_ext_correct=2.35*nS, w_ampa_ext_incorrect=0.6*nS)
        plas_params=plasticity_params()

        # Create a virtual subject
        subject=VirtualSubject(subj_id, wta_params=wta_params, pyr_params=plasticity_pyr_params,
            plasticity_params=plas_params)

        # Run through each condition
        for condition, (sim_params, reinit, coherence_levels) in conditions.items():
            print condition

            # Reinitialize state variables in subject network
            if reinit:
                subject.net.reinit(states=True)

            # Run session
            run_session(subject, condition, sim_params, coherence_levels,
                output_file=os.path.join(output_dir, 'subject.%d.%s.h5' % (subj_id,condition)))