Esempio n. 1
0
def create_roc_report(file_prefix,
                      num_groups,
                      contrast_range,
                      num_trials,
                      reports_dir,
                      regenerate_plot=True):
    num_extra_trials = 10
    roc_report = Struct()
    roc_report.auc = get_auc(file_prefix, contrast_range, num_trials,
                             num_extra_trials, num_groups)
    roc_report.auc_single_option = []
    roc_url = 'img/roc.png'
    fname = os.path.join(reports_dir, roc_url)
    roc_report.roc_url = roc_url
    if regenerate_plot or not os.path.exists(fname):
        fig = plt.figure()
        for i in range(num_groups):
            roc = get_roc_single_option(file_prefix, contrast_range,
                                        num_trials, num_extra_trials, i)
            plt.plot(roc[:, 0], roc[:, 1], 'x-', label='option %d' % i)
            roc_report.auc_single_option.append(
                get_auc_single_option(file_prefix, contrast_range, num_trials,
                                      num_extra_trials, i))
        plt.plot([0, 1], [0, 1], '--')
        plt.xlabel('False Positive Rate')
        plt.ylabel('True Positive Rate')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/roc.eps'))
        plt.close()
    return roc_report
Esempio n. 2
0
def get_prob(x, output_dir):
    num_groups = 2
    trial_duration = 1 * second
    input_sum = 40.0
    num_trials = 5
    num_extra_trials = 10

    wta_params = default_params()
    wta_params.p_b_e = 0.1
    wta_params.p_x_e = 0.05
    wta_params.p_e_e = x[0]
    wta_params.p_e_i = x[1]
    wta_params.p_i_i = x[2]
    wta_params.p_i_e = x[3]

    file_desc='wta.groups.%d.duration.%0.3f.p_b_e.%0.3f.p_x_e.%0.3f.p_e_e.%0.3f.p_e_i.%0.3f.p_i_i.%0.3f.p_i_e.%0.3f' % \
              (num_groups, trial_duration, wta_params.p_b_e, wta_params.p_x_e, wta_params.p_e_e, wta_params.p_e_i,
               wta_params.p_i_i, wta_params.p_i_e)
    file_prefix = os.path.join(output_dir, file_desc)

    num_example_trials = [0, 0]
    for trial in range(num_trials):
        inputs = np.zeros(2)
        inputs[0] = np.random.random() * input_sum
        inputs[1] = input_sum - inputs[0]

        if inputs[0] > inputs[1]:
            num_example_trials[0] += 1
        else:
            num_example_trials[1] += 1

        if trial == num_trials - 1:
            if num_example_trials[0] == 0:
                inputs[
                    0] = input_sum * 0.5 + np.random.random() * input_sum * 0.5
                inputs[1] = input_sum - inputs[0]
                num_example_trials[0] += 1
            elif num_example_trials[1] == 0:
                inputs[
                    1] = input_sum * 0.5 + np.random.random() * input_sum * 0.5
                inputs[0] = input_sum - inputs[1]
                num_example_trials[1] += 1

        output_file = '%s.trial.%d.h5' % (file_prefix, trial)

        run_wta(wta_params,
                num_groups,
                inputs,
                trial_duration,
                output_file=output_file,
                record_lfp=False,
                record_voxel=False,
                record_neuron_state=False,
                record_spikes=False,
                record_firing_rate=True,
                record_inputs=True,
                single_inh_pop=False)

    auc = get_auc(file_prefix, num_trials, num_extra_trials, num_groups)
    return auc
Esempio n. 3
0
def get_prob(x, output_dir):
    num_groups=2
    trial_duration=1*second
    input_sum=40.0
    num_trials=5
    num_extra_trials=10

    wta_params=default_params()
    wta_params.p_b_e=0.1
    wta_params.p_x_e=0.05
    wta_params.p_e_e=x[0]
    wta_params.p_e_i=x[1]
    wta_params.p_i_i=x[2]
    wta_params.p_i_e=x[3]

    file_desc='wta.groups.%d.duration.%0.3f.p_b_e.%0.3f.p_x_e.%0.3f.p_e_e.%0.3f.p_e_i.%0.3f.p_i_i.%0.3f.p_i_e.%0.3f' % \
              (num_groups, trial_duration, wta_params.p_b_e, wta_params.p_x_e, wta_params.p_e_e, wta_params.p_e_i,
               wta_params.p_i_i, wta_params.p_i_e)
    file_prefix=os.path.join(output_dir,file_desc)

    num_example_trials=[0,0]
    for trial in range(num_trials):
        inputs=np.zeros(2)
        inputs[0]=np.random.random()*input_sum
        inputs[1]=input_sum-inputs[0]

        if inputs[0]>inputs[1]:
            num_example_trials[0]+=1
        else:
            num_example_trials[1]+=1

        if trial==num_trials-1:
            if num_example_trials[0]==0:
                inputs[0]=input_sum*0.5+np.random.random()*input_sum*0.5
                inputs[1]=input_sum-inputs[0]
                num_example_trials[0]+=1
            elif num_example_trials[1]==0:
                inputs[1]=input_sum*0.5+np.random.random()*input_sum*0.5
                inputs[0]=input_sum-inputs[1]
                num_example_trials[1]+=1

        output_file='%s.trial.%d.h5' % (file_prefix,trial)

        run_wta(wta_params, num_groups, inputs, trial_duration, output_file=output_file, record_lfp=False,
            record_voxel=False, record_neuron_state=False, record_spikes=False, record_firing_rate=True,
            record_inputs=True, single_inh_pop=False)

    auc=get_auc(file_prefix, num_trials, num_extra_trials, num_groups)
    return auc
Esempio n. 4
0
def create_roc_report(file_prefix, num_groups, contrast_range, num_trials, reports_dir, regenerate_plot=True):
    num_extra_trials=10
    roc_report=Struct()
    roc_report.auc=get_auc(file_prefix, contrast_range, num_trials, num_extra_trials, num_groups)
    roc_report.auc_single_option=[]
    roc_url = 'img/roc.png'
    fname=os.path.join(reports_dir, roc_url)
    roc_report.roc_url=roc_url
    if regenerate_plot or not os.path.exists(fname):
        fig=plt.figure()
        for i in range(num_groups):
            roc=get_roc_single_option(file_prefix, contrast_range, num_trials, num_extra_trials, i)
            plt.plot(roc[:,0],roc[:,1],'x-',label='option %d' % i)
            roc_report.auc_single_option.append(get_auc_single_option(file_prefix, contrast_range, num_trials, num_extra_trials, i))
        plt.plot([0,1],[0,1],'--')
        plt.xlabel('False Positive Rate')
        plt.ylabel('True Positive Rate')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/roc.eps'))
        plt.close()
    return roc_report