示例#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())
示例#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)))
示例#3
0
文件: run.py 项目: jbonaiuto/pySBI
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}
    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 < 0.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=np.mean(beta_vals[np.where(alpha_vals<.99)[0]])

        # Create virtual subject parameters - background freq from beta dist, resp threshold between 15 and 25Hz
        wta_params = default_params(background_freq=(beta - 161.08) / -0.17, resp_threshold=18 + np.random.uniform(4))
        # Set initial input weights and modify NMDA recurrent
        pyramidal_params = pyr_params(w_nmda=0.145 * nS, w_ampa_ext_correct=1.6 * nS, w_ampa_ext_incorrect=0.9 * nS)

        # Create a virtual subject
        subject = VirtualSubject(subj_id, wta_params=wta_params, pyr_params=pyramidal_params)

        # Run through each condition
        for condition, sim_params in conditions.iteritems():
            # Reinitialize state variables in subject network
            subject.net.reinit(states=True)
            # Run session
            run_session(
                subject,
                condition,
                sim_params,
                output_file=os.path.join(output_dir, "subject.%d.%s.h5" % (subj_id, condition)),
            )
示例#4
0
def generate_virtual_subject(subj_id, behavioral_param_file):
    # 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'])

    # 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

    # Create virtual subject parameters - background freq from beta dist, resp threshold between 15 and 25Hz
    wta_params=default_params(background_freq=(beta-161.08)/-.17, resp_threshold=15+np.random.uniform(10))
    # Set initial input weights and modify NMDA recurrent
    pyramidal_params=pyr_params(w_nmda=0.15*nS, w_ampa_ext_correct=1.6*nS, w_ampa_ext_incorrect=0.0*nS)

    # Create a virtual subject
    subject=VirtualSubject(subj_id, wta_params=wta_params, pyr_params=pyramidal_params)
    return subject