Exemplo 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
Exemplo n.º 2
0
def render_joint_marginal_report(param1_name, param2_name, param1_range,
                                 param2_range, joint_posterior, file_prefix,
                                 reports_dir):
    if len(param1_range) > 1 < len(param2_range):
        fig = plt.figure()
        im = plt.imshow(joint_posterior,
                        extent=[
                            min(param2_range),
                            max(param2_range),
                            min(param1_range),
                            max(param1_range)
                        ],
                        interpolation='nearest',
                        origin='lower')
        fig.colorbar(im)
        plt.xlabel(param2_name)
        plt.ylabel(param1_name)
        furl = 'img/bayes_%s_joint_marginal_%s_%s.png' % (
            file_prefix, param1_name, param2_name)
        fname = os.path.join(reports_dir, furl)
        save_to_png(fig, fname)
        save_to_eps(
            fig,
            os.path.join(
                reports_dir, 'img/bayes_%s_joint_marginal_%s_%s.eps' %
                (file_prefix, param1_name, param2_name)))
        plt.close()
        return furl
    return None
Exemplo n.º 3
0
def run_mean_adaptation_simulation(design, baseline):
    N=150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params=default_params
    sim_params=rapid_design_params
    if design=='long':
        network_params.tau_a=5*second
        sim_params=long_design_params

    data_dir='../../data/adaptation/mean_shift/'

    x_delta_iter=10
    # If baseline is single stimulus - need to test x_delta=0
    x_delta_range=np.array(range(0,int(N/3),x_delta_iter))

    # High and low variance examples
    low_var=5
    high_var=15
    x=int(N/3)

    prob_low_var_adaptation=np.zeros(len(x_delta_range))
    prob_high_var_adaptation=np.zeros(len(x_delta_range))
    samp_low_var_adaptation=np.zeros(len(x_delta_range))
    samp_high_var_adaptation=np.zeros(len(x_delta_range))
    for i,x_delta in enumerate(x_delta_range):
        print('x_delta=%d' % x_delta)

        prob_low_var_adaptation[i]=adaptation_simulation(design, baseline, ProbabilisticPopulationCode, N, network_params,
            sim_params, x, x+x_delta, low_var, low_var, os.path.join(data_dir,'prob','low_var'),'low_var.xdelta-%d' % x_delta)
        prob_high_var_adaptation[i]=adaptation_simulation(design, baseline, ProbabilisticPopulationCode, N, network_params,
            sim_params, x, x+x_delta, high_var, high_var, os.path.join(data_dir,'prob','high_var'),'high_var.xdelta-%d' % x_delta)

        samp_low_var_adaptation[i]=adaptation_simulation(design, baseline, SamplingPopulationCode, N, network_params,
            sim_params, x, x+x_delta, low_var, low_var, os.path.join(data_dir,'samp','low_var'),'low_var.xdelta-%d' % x_delta)
        samp_high_var_adaptation[i]=adaptation_simulation(design, baseline, SamplingPopulationCode, N, network_params,
            sim_params, x, x+x_delta, high_var, high_var, os.path.join(data_dir,'samp','high_var'),'high_var.xdelta-%d' % x_delta)


    fig=plt.figure()
    plt.title('Probabilistic Population Code')
    plt.plot(x_delta_range,prob_low_var_adaptation,'r',label='low var')
    plt.plot(x_delta_range,prob_high_var_adaptation,'b',label='high var')
    plt.legend(loc='best')
    fname='%s.baseline-%s.prob_pop.mean_adaptation' % (design, baseline)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

    fig=plt.figure()
    plt.title('Sampling Population Code')
    plt.plot(x_delta_range,samp_low_var_adaptation,'r',label='low var')
    plt.plot(x_delta_range,samp_high_var_adaptation,'b',label='high var')
    plt.legend(loc='best')
    fname='%s.baseline-%s.samp_pop.mean_adaptation' % (design, baseline)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 4
0
def run_uncertainty_adaptation_simulation(design, baseline):

    N = 150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params = default_params
    sim_params = rapid_design_params
    if design == 'long':
        network_params.tau_a = 5 * second
        sim_params = long_design_params

    # Variance and mean values used
    low_var = 5
    high_var = 15
    x = int(N / 3)

    data_dir = '../../data/adaptation/var_shift/'

    print('prob low->high')
    prob_low_high_adaptation = adaptation_simulation(
        design, baseline, ProbabilisticPopulationCode, N, network_params,
        sim_params, x, x, low_var, high_var,
        os.path.join(data_dir, 'prob', 'low-high'), 'low_high')
    print('prob high->low')
    prob_high_low_adaptation = adaptation_simulation(
        design, baseline, ProbabilisticPopulationCode, N, network_params,
        sim_params, x, x, high_var, low_var,
        os.path.join(data_dir, 'prob', 'high-low'), 'high_low')

    print('samp low->high')
    samp_low_high_adaptation = adaptation_simulation(
        design, baseline, SamplingPopulationCode, N, network_params,
        sim_params, x, x, low_var, high_var,
        os.path.join(data_dir, 'samp', 'low-high'), 'low_high')
    print('samp high->low')
    samp_high_low_adaptation = adaptation_simulation(
        design, baseline, SamplingPopulationCode, N, network_params,
        sim_params, x, x, high_var, low_var,
        os.path.join(data_dir, 'prob', 'high-low'), 'high_low')

    fig = plt.figure()
    plt.plot([0, 1], [prob_low_high_adaptation, prob_high_low_adaptation],
             label='prob')
    plt.plot([0, 1], [samp_low_high_adaptation, samp_high_low_adaptation],
             label='samp')
    plt.legend(loc='best')
    fname = '%s.baseline-%s.var.adaptation' % (design, baseline)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 5
0
def render_joint_marginal_report(param1_name, param2_name, param1_range, param2_range, joint_posterior, file_prefix,
                                 reports_dir):
    if len(param1_range) > 1 < len(param2_range):
        fig = plt.figure()
        im = plt.imshow(joint_posterior, extent=[min(param2_range), max(param2_range), min(param1_range),
                                                 max(param1_range)], interpolation='nearest', origin='lower')
        fig.colorbar(im)
        plt.xlabel(param2_name)
        plt.ylabel(param1_name)
        furl = 'img/bayes_%s_joint_marginal_%s_%s.png' % (file_prefix, param1_name, param2_name)
        fname = os.path.join(reports_dir, furl)
        save_to_png(fig, fname)
        save_to_eps(fig,os.path.join(reports_dir, 'img/bayes_%s_joint_marginal_%s_%s.eps' % (file_prefix, param1_name, param2_name)))
        plt.close()
        return furl
    return None
Exemplo n.º 6
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
Exemplo n.º 7
0
def run_uncertainty_adaptation_simulation(design, baseline):

    N=150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params=default_params
    sim_params=rapid_design_params
    if design=='long':
        network_params.tau_a=5*second
        sim_params=long_design_params

    # Variance and mean values used
    low_var=5
    high_var=15
    x=int(N/3)

    data_dir='../../data/adaptation/var_shift/'

    print('prob low->high')
    prob_low_high_adaptation=adaptation_simulation(design, baseline, ProbabilisticPopulationCode, N, network_params, sim_params,
        x, x, low_var, high_var, os.path.join(data_dir,'prob','low-high'), 'low_high')
    print('prob high->low')
    prob_high_low_adaptation=adaptation_simulation(design, baseline, ProbabilisticPopulationCode, N, network_params, sim_params,
        x, x, high_var, low_var, os.path.join(data_dir,'prob','high-low'), 'high_low')

    print('samp low->high')
    samp_low_high_adaptation=adaptation_simulation(design, baseline, SamplingPopulationCode, N, network_params, sim_params,
        x, x, low_var, high_var, os.path.join(data_dir,'samp','low-high'), 'low_high')
    print('samp high->low')
    samp_high_low_adaptation=adaptation_simulation(design, baseline, SamplingPopulationCode, N, network_params, sim_params,
        x, x, high_var, low_var, os.path.join(data_dir,'prob','high-low'), 'high_low')


    fig=plt.figure()
    plt.plot([0,1],[prob_low_high_adaptation, prob_high_low_adaptation],label='prob')
    plt.plot([0,1],[samp_low_high_adaptation, samp_high_low_adaptation],label='samp')
    plt.legend(loc='best')
    fname='%s.baseline-%s.var.adaptation' % (design,baseline)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 8
0
def run_isi_simulation():
    N = 150
    network_params = default_params
    trial_duration = 2 * second
    var = 10
    x1 = 50
    x2 = 100
    isi_times = range(25, 750, 25)
    stim_dur = 100 * ms
    adaptation = np.zeros(len(isi_times))
    for i, isi in enumerate(isi_times):
        print('Testing isi=%dms' % isi)
        stim1_start_time = 1 * second
        stim1_end_time = stim1_start_time + stim_dur

        stim2_start_time = stim1_end_time + isi * ms
        stim2_end_time = stim2_start_time + stim_dur

        same_pop_monitor, same_voxel_monitor = run_pop_code(
            ProbabilisticPopulationCode, N, network_params, [x1, x1],
            [var, var], [stim1_start_time, stim2_start_time],
            [stim1_end_time, stim2_end_time], trial_duration)
        diff_pop_monitor, diff_voxel_monitor = run_pop_code(
            ProbabilisticPopulationCode, N, network_params, [x1, x2],
            [var, var], [stim1_start_time, stim2_start_time],
            [stim1_end_time, stim2_end_time], trial_duration)

        same_y_max = np.max(same_voxel_monitor['y'][0])
        diff_y_max = np.max(diff_voxel_monitor['y'][0])
        adaptation[i] = (diff_y_max - same_y_max) / diff_y_max * 100.0

    data_dir = '../../data/adaptation/isi'
    fig = plt.figure()
    plt.plot(isi_times, adaptation)
    plt.xlabel('ISI (ms)')
    plt.ylabel('Adaptation')
    fname = 'adaptation.isi.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)
Exemplo n.º 9
0
def run_isi_simulation():
    N=150
    network_params=default_params
    trial_duration=2*second
    var=10
    x1=50
    x2=100
    isi_times=range(25,750,25)
    stim_dur=100*ms
    adaptation=np.zeros(len(isi_times))
    for i,isi in enumerate(isi_times):
        print('Testing isi=%dms' % isi)
        stim1_start_time=1*second
        stim1_end_time=stim1_start_time+stim_dur

        stim2_start_time=stim1_end_time+isi*ms
        stim2_end_time=stim2_start_time+stim_dur

        same_pop_monitor,same_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params, [x1,x1], [var,var],
            [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration)
        diff_pop_monitor,diff_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params, [x1,x2], [var,var],
            [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration)

        same_y_max=np.max(same_voxel_monitor['y'][0])
        diff_y_max=np.max(diff_voxel_monitor['y'][0])
        adaptation[i]=(diff_y_max-same_y_max)/diff_y_max*100.0

    data_dir='../../data/adaptation/isi'
    fig=plt.figure()
    plt.plot(isi_times,adaptation)
    plt.xlabel('ISI (ms)')
    plt.ylabel('Adaptation')
    fname='adaptation.isi.%s'
    save_to_png(fig, os.path.join(data_dir,fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir,fname % 'eps'))
    plt.close(fig)
Exemplo n.º 10
0
def render_marginal_report(param_name, param_range, param_prior, param_likelihood, param_posterior, file_prefix, reports_dir, ylim):
    if len(param_range) > 1:
        param_step=param_range[1]-param_range[0]

        fig = plt.figure()
        param_prior[param_prior==0]=1e-7
        plt.bar(np.array(param_range) - .5*param_step, param_prior, param_step)
        plt.xlabel(param_name)
        plt.ylabel('p(%s|M)' % param_name)
        plt.ylim([0,ylim])
        prior_furl = 'img/bayes_%s_marginal_prior_%s.png' % (file_prefix,param_name)
        fname = os.path.join(reports_dir, prior_furl)
        save_to_png(fig, fname)
        save_to_eps(fig,os.path.join(reports_dir, 'img/bayes_%s_marginal_prior_%s.eps' % (file_prefix,param_name)))
        plt.close()

        fig = plt.figure()
        param_likelihood[param_likelihood==0]=1e-7
        plt.bar(np.array(param_range) - .5*param_step, param_likelihood, param_step)
        plt.xlabel(param_name)
        plt.ylabel('p(WTA|%s,M)' % param_name)
        plt.ylim([0,ylim])
        likelihood_furl = 'img/bayes_%s_marginal_likelihood_%s.png' % (file_prefix,param_name)
        fname = os.path.join(reports_dir, likelihood_furl)
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/bayes_%s_marginal_likelihood_%s.eps' % (file_prefix,param_name)))
        plt.close()

        fig = plt.figure()
        param_posterior[param_posterior==0]=1e-7
        plt.bar(np.array(param_range) - .5*param_step, param_posterior, param_step)
        plt.xlabel(param_name)
        plt.ylabel('p(%s|WTA,M)' % param_name)
        plt.ylim([0,ylim])
        posterior_furl = 'img/bayes_%s_marginal_posterior_%s.png' % (file_prefix, param_name)
        fname = os.path.join(reports_dir, posterior_furl)
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/bayes_%s_marginal_posterior_%s.eps' % (file_prefix, param_name)))
        plt.close()

        return prior_furl, likelihood_furl, posterior_furl
    return None, None, None
Exemplo n.º 11
0
def run_full_adaptation_simulation(design, baseline):
    N=150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params=default_params
    sim_params=rapid_design_params
    if design=='long':
        network_params.tau_a=5*second
        sim_params=long_design_params

    data_dir='../../data/adaptation/full_adaptation/'

    # High and low mean and variance examples
    low_var=5
    high_var=15
    low_mean=50
    high_mean=100

    stim=[(low_mean,low_var),(low_mean,high_var),(high_mean,low_var),(high_mean,high_var)]
    prob_adaptation=np.zeros([4,4])
    samp_adaptation=np.zeros([4,4])

    for i,(stim1_mean,stim1_var) in enumerate(stim):
        for j,(stim2_mean,stim2_var) in enumerate(stim):
            edesc=''
            if stim1_mean==low_mean:
                edesc+='low_mean.'
            else:
                edesc+='high_mean.'
            if stim1_var==low_var:
                edesc+='low_var-'
            else:
                edesc+='high_var-'
            if stim2_mean==low_mean:
                edesc+='low_mean.'
            else:
                edesc+='high_mean.'
            if stim2_var==low_var:
                edesc+='low_var'
            else:
                edesc+='high_var'
            print('prob stim1: mean=%d, var=%d; stim2: mean=%d, var=%d' % (stim1_mean,stim1_var,stim2_mean,stim2_var))
            prob_adaptation[i,j]=adaptation_simulation(design, baseline, ProbabilisticPopulationCode, N, network_params,
                sim_params, stim1_mean, stim2_mean, stim1_var, stim2_var, os.path.join(data_dir,'prob',edesc),edesc)
            print('prob adaptation=%.4f' % prob_adaptation[i,j])

            print('samp stim1: mean=%d, var=%d; stim2: mean=%d, var=%d' % (stim1_mean,stim1_var,stim2_mean,stim2_var))
            samp_adaptation[i,j]=adaptation_simulation(design, baseline, SamplingPopulationCode, N, network_params,
                sim_params, stim1_mean, stim2_mean, stim1_var, stim2_var, os.path.join(data_dir,'samp',edesc),edesc)
            print('samp adaptation=%.4f' % samp_adaptation[i,j])


    fig=plt.figure()
    plt.title('Probabilistic Population')
    plt.imshow(prob_adaptation,interpolation='none')
    plt.colorbar()
    fname='%s.baseline-%s.prob_pop' % (design,baseline)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

    fig=plt.figure()
    plt.title('Sampling Population')
    plt.imshow(samp_adaptation,interpolation='none')
    plt.colorbar()
    fname='%s.baseline-%s.samp_pop' % (design,baseline)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 12
0
def run_repeated_test():
    N=150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params=default_params
    sim_params=rapid_design_params

    # Compute stimulus start and end times
    stim1_start_time=1*second
    stim1_end_time=stim1_start_time+sim_params.stim_dur

    stim2_start_time=stim1_end_time+sim_params.isi
    stim2_end_time=stim2_start_time+sim_params.stim_dur

    x_delta_iter=5
    # If baseline is single stimulus - need to test x_delta=0
    x_delta_range=np.array(range(0,int(N/3),x_delta_iter))

    # High and low variance examples
    low_var=5
    x=int(N/3)

    prob_combined_y_max=np.zeros(len(x_delta_range))
    prob_repeated_y_max=np.zeros(len(x_delta_range))
    samp_combined_y_max=np.zeros(len(x_delta_range))
    samp_repeated_y_max=np.zeros(len(x_delta_range))
    for i,x_delta in enumerate(x_delta_range):
        print('x_delta=%d' % x_delta)

        pop_monitor,voxel_monitor,prob_repeated_y_max[i]=run_pop_code(ProbabilisticPopulationCode, N, network_params,
            [Stimulus(x,low_var,stim1_start_time,stim1_end_time),
             Stimulus(x+x_delta,low_var,stim2_start_time,stim2_end_time)],
            sim_params.trial_duration)
        pop_monitor,voxel_monitor,prob_first_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params,
            [Stimulus(x, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        pop_monitor,voxel_monitor,prob_second_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params,
            [Stimulus(x+x_delta, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        prob_combined_y_max[i]=prob_first_y_max+prob_second_y_max

        pop_monitor,voxel_monitor,samp_repeated_y_max[i]=run_pop_code(SamplingPopulationCode, N, network_params,
            [Stimulus(x,low_var,stim1_start_time,stim1_end_time),
             Stimulus(x+x_delta,low_var,stim2_start_time,stim2_end_time)],
            sim_params.trial_duration)
        pop_monitor,voxel_monitor,samp_first_y_max=run_pop_code(SamplingPopulationCode, N, network_params,
            [Stimulus(x, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        pop_monitor,voxel_monitor,samp_second_y_max=run_pop_code(SamplingPopulationCode, N, network_params,
            [Stimulus(x+x_delta, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        samp_combined_y_max[i]=samp_first_y_max+samp_second_y_max

    data_dir='../../data/adaptation/repeated_test/'

    fig=plt.figure()
    plt.plot(x_delta_range,prob_combined_y_max-prob_repeated_y_max,'r',label='prob')
    plt.plot(x_delta_range,samp_combined_y_max-samp_repeated_y_max,'b',label='samp')
    plt.legend(loc='best')
    fname='repeated_test'
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 13
0
def create_wta_network_report(file_prefix, contrast_range, num_trials, reports_dir, edesc, regenerate_network_plots=True,
                              regenerate_trial_plots=True):

    make_report_dirs(reports_dir)

    report_info=Struct()
    report_info.edesc=edesc
    report_info.trials=[]

    (data_dir, data_file_prefix) = os.path.split(file_prefix)

    total_trials=num_trials*len(contrast_range)
    trial_contrast=np.zeros([total_trials,1])
    trial_max_bold=np.zeros(total_trials)
    trial_max_input=np.zeros([total_trials,1])
    trial_max_rate=np.zeros([total_trials,1])
    trial_rt=np.zeros([total_trials,1])

    report_info.contrast_accuracy=np.zeros([len(contrast_range),1])

    max_bold=[]
    for j,contrast in enumerate(contrast_range):
        contrast_max_bold=[]
        report_info.contrast_accuracy[j]=0.0
        for i in range(num_trials):
            file_name='%s.contrast.%0.4f.trial.%d.h5' % (file_prefix, contrast, i)
            print('opening %s' % file_name)
            data=FileInfo(file_name)

            if not i:
                report_info.wta_params=data.wta_params
                report_info.voxel_params=data.voxel_params
                report_info.num_groups=data.num_groups
                report_info.trial_duration=data.trial_duration
                report_info.background_rate=data.background_rate
                report_info.stim_start_time=data.stim_start_time
                report_info.stim_end_time=data.stim_end_time
                report_info.network_group_size=data.network_group_size
                report_info.background_input_size=data.background_input_size
                report_info.task_input_size=data.task_input_size

            trial_idx=j*num_trials+i
            trial = create_trial_report(data, reports_dir, contrast, i, regenerate_plots=regenerate_trial_plots)
            trial_contrast[trial_idx]=trial.input_contrast
            if not math.isnan(trial.max_bold):
                trial_max_bold[trial_idx]=trial.max_bold
            else:
                if j>1 and max_bold[j-1]<1.0 and max_bold[j-2]<1.0:
                    trial_max_bold[trial_idx]=max_bold[j-1]+(max_bold[j-1]-max_bold[j-2])
                elif j>0 and max_bold[j-1]<1.0:
                    trial_max_bold[trial_idx]=max_bold[j-1]*2.0
                else:
                    trial_max_bold[trial_idx]=1.0

            report_info.contrast_accuracy[j]+=trial.correct

            trial_max_input[trial_idx]=trial.max_input
            trial_max_rate[trial_idx]=trial.max_rate
            trial_rt[trial_idx]=trial.rt
            report_info.trials.append(trial)

            contrast_max_bold.append(trial_max_bold[trial_idx])
        report_info.contrast_accuracy[j]/=float(num_trials)
        mean_contrast_bold=np.mean(np.array(contrast_max_bold))
        max_bold.append(mean_contrast_bold)

    clf=LinearRegression()
    clf.fit(trial_max_input,trial_max_rate)
    a=clf.coef_[0]
    b=clf.intercept_
    report_info.io_slope=a
    report_info.io_intercept=b
    report_info.io_r_sqr=clf.score(trial_max_input,trial_max_rate)

    furl='img/input_output_rate.png'
    fname=os.path.join(reports_dir, furl)
    report_info.input_output_rate_url=furl
    if regenerate_network_plots or not os.path.exists(fname):
        fig=plt.figure()
        plt.plot(trial_max_input, trial_max_rate, 'x')
        x_min=np.min(trial_max_input)
        x_max=np.max(trial_max_input)
        plt.plot([x_min,x_max],[x_min,x_max],'--')
        plt.plot([x_min,x_max],[a*x_min+b,a*x_max+b],'--')
        plt.xlabel('Max Input Rate')
        plt.ylabel('Max Population Rate')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/input_output_rate.eps'))
        plt.close()

    report_info.bold=create_bold_report(reports_dir, trial_contrast, trial_max_bold, trial_max_rate, trial_rt,
        regenerate_plot=regenerate_network_plots)

    report_info.roc=create_roc_report(file_prefix, report_info.num_groups, contrast_range, num_trials, reports_dir,
        regenerate_plot=regenerate_network_plots)

    #create report
    template_file='wta_network_instance.html'
    env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
    template=env.get_template(template_file)

    output_file='wta_network.%s.html' % data_file_prefix
    fname=os.path.join(reports_dir,output_file)
    stream=template.stream(rinfo=report_info)
    stream.dump(fname)

    return report_info
Exemplo n.º 14
0
def create_trial_report(data,
                        reports_dir,
                        contrast,
                        trial_idx,
                        regenerate_plots=True):
    trial = Struct()
    trial.input_freq = data.input_freq
    trial.input_contrast = abs(data.input_freq[0] - data.input_freq[1]) / sum(
        data.input_freq)
    trial.correct = 0.0
    option_idx = -1
    if data.input_freq[0] > data.input_freq[1]:
        option_idx = 0
    elif data.input_freq[1] > data.input_freq[0]:
        option_idx = 1
    if option_idx > -1:
        if np.max(data.e_firing_rates[option_idx, 6500:7500]) > np.max(
                data.e_firing_rates[1 - option_idx, 6500:7500]):
            trial.correct = 1.0
    trial.rt = data.rt

    max_input_idx = np.where(
        trial.input_freq == np.max(trial.input_freq))[0][0]
    trial.max_input = trial.input_freq[max_input_idx]
    trial.max_rate = np.max(data.e_firing_rates[max_input_idx])

    trial.e_raster_url = None
    trial.i_raster_url = None
    if data.e_spike_neurons is not None and data.i_spike_neurons is not None:
        furl = 'img/e_raster.contrast.%0.4f.trial.%d.png' % (contrast,
                                                             trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.e_raster_url = furl
        if regenerate_plots or not os.path.exists(fname):
            e_group_sizes = [
                int(4 * data.network_group_size / 5)
                for i in range(data.num_groups)
            ]
            fig = plot_raster(data.e_spike_neurons, data.e_spike_times,
                              e_group_sizes)
            save_to_png(fig, fname)
            save_to_eps(
                fig,
                os.path.join(
                    reports_dir, 'img/e_raster.contrast.%0.4f.trial.%d.eps' %
                    (contrast, trial_idx)))
            plt.close()

        furl = 'img/i_raster.contrast.%0.4f.trial.%d.png' % (contrast,
                                                             trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.i_raster_url = furl
        if regenerate_plots or not os.path.exists(fname):
            i_group_sizes = [
                int(data.network_group_size / 5)
                for i in range(data.num_groups)
            ]
            fig = plot_raster(data.i_spike_neurons, data.i_spike_times,
                              i_group_sizes)
            save_to_png(fig, fname)
            save_to_eps(
                fig,
                os.path.join(
                    reports_dir, 'img/i_raster.contrast.%0.4f.trial.%d.eps' %
                    (contrast, trial_idx)))
            plt.close()

    trial.firing_rate_url = None
    if data.e_firing_rates is not None and data.i_firing_rates is not None:
        furl = 'img/firing_rate.contrast.%0.4f.trial.%d.png' % (contrast,
                                                                trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.firing_rate_url = furl
        if regenerate_plots or not os.path.exists(fname):
            fig = plt.figure()
            ax = plt.subplot(211)
            for i, pop_rate in enumerate(data.e_firing_rates):
                ax.plot(np.array(range(len(pop_rate))) * .1,
                        pop_rate / Hz,
                        label='group %d' % i)
            plt.xlabel('Time (ms)')
            plt.ylabel('Firing Rate (Hz)')
            ax = plt.subplot(212)
            for i, pop_rate in enumerate(data.i_firing_rates):
                ax.plot(np.array(range(len(pop_rate))) * .1,
                        pop_rate / Hz,
                        label='group %d' % i)
            plt.xlabel('Time (ms)')
            plt.ylabel('Firing Rate (Hz)')
            save_to_png(fig, fname)
            save_to_eps(
                fig,
                os.path.join(
                    reports_dir,
                    'img/firing_rate.contrast.%0.4f.trial.%d.eps' %
                    (contrast, trial_idx)))
            plt.close()

    trial.neural_state_url = None
    if data.neural_state_rec is not None:
        furl = 'img/neural_state.contrast.%0.4f.trial.%d.png' % (contrast,
                                                                 trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.neural_state_url = furl
        if regenerate_plots or not os.path.exists(fname):
            fig = plt.figure()
            for i in range(data.num_groups):
                times = np.array(
                    range(len(data.neural_state_rec['g_ampa_r'][i * 2]))) * .1
                ax = plt.subplot(data.num_groups * 100 + 20 + (i * 2 + 1))
                ax.plot(times,
                        data.neural_state_rec['g_ampa_r'][i * 2] / nA,
                        label='AMPA-recurrent')
                ax.plot(times,
                        data.neural_state_rec['g_ampa_x'][i * 2] / nA,
                        label='AMPA-task')
                ax.plot(times,
                        data.neural_state_rec['g_ampa_b'][i * 2] / nA,
                        label='AMPA-backgrnd')
                ax.plot(times,
                        data.neural_state_rec['g_nmda'][i * 2] / nA,
                        label='NMDA')
                ax.plot(times,
                        data.neural_state_rec['g_gaba_a'][i * 2] / nA,
                        label='GABA_A')
                plt.xlabel('Time (ms)')
                plt.ylabel('Conductance (nA)')
                ax = plt.subplot(data.num_groups * 100 + 20 + (i * 2 + 2))
                ax.plot(times,
                        data.neural_state_rec['g_ampa_r'][i * 2 + 1] / nA,
                        label='AMPA-recurrent')
                ax.plot(times,
                        data.neural_state_rec['g_ampa_x'][i * 2 + 1] / nA,
                        label='AMPA-task')
                ax.plot(times,
                        data.neural_state_rec['g_ampa_b'][i * 2 + 1] / nA,
                        label='AMPA-backgrnd')
                ax.plot(times,
                        data.neural_state_rec['g_nmda'][i * 2 + 1] / nA,
                        label='NMDA')
                ax.plot(times,
                        data.neural_state_rec['g_gaba_a'][i * 2 + 1] / nA,
                        label='GABA_A')
                plt.xlabel('Time (ms)')
                plt.ylabel('Conductance (nA)')
            save_to_png(fig, fname)
            save_to_eps(
                fig,
                os.path.join(
                    reports_dir,
                    'img/neural_state.contrast.%0.4f.trial.%d.eps' %
                    (contrast, trial_idx)))
            plt.close()

    trial.lfp_url = None
    if data.lfp_rec is not None:
        furl = 'img/lfp.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.lfp_url = furl
        if regenerate_plots or not os.path.exists(fname):
            fig = plt.figure()
            ax = plt.subplot(111)
            lfp = get_lfp_signal(data)
            ax.plot(np.array(range(len(lfp))), lfp / mA)
            plt.xlabel('Time (ms)')
            plt.ylabel('LFP (mA)')
            save_to_png(fig, fname)
            save_to_eps(
                fig,
                os.path.join(
                    reports_dir, 'img/lfp.contrast.%0.4f.trial.%d.eps' %
                    (contrast, trial_idx)))
            plt.close()

    trial.voxel_url = None
    trial.max_bold = 0
    if data.voxel_rec is not None:
        trial.max_bold = -1000
        for val in data.voxel_rec['y'][0]:
            if not math.isnan(val) and val > trial.max_bold:
                trial.max_bold = val
        furl = 'img/voxel.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.voxel_url = furl
        if regenerate_plots or not os.path.exists(fname):
            end_idx = int(data.trial_duration / ms / .1)
            fig = plt.figure()
            ax = plt.subplot(211)
            ax.plot(
                np.array(range(end_idx)) * .1,
                data.voxel_rec['G_total'][0][:end_idx] / nA)
            plt.xlabel('Time (ms)')
            plt.ylabel('Total Synaptic Activity (nA)')
            ax = plt.subplot(212)
            ax.plot(
                np.array(range(len(data.voxel_rec['y'][0]))) * .1 * ms,
                data.voxel_rec['y'][0])
            plt.xlabel('Time (s)')
            plt.ylabel('BOLD')
            save_to_png(fig, fname)
            save_to_eps(
                fig,
                os.path.join(
                    reports_dir, 'img/voxel.contrast.%0.4f.trial.%d.eps' %
                    (contrast, trial_idx)))
            plt.close()
    return trial
Exemplo n.º 15
0
def create_bold_report(reports_dir,
                       trial_contrast,
                       trial_max_bold,
                       trial_max_rate,
                       trial_rt,
                       regenerate_plot=True):

    report_info = Struct()

    clf = LinearRegression()
    clf.fit(trial_contrast, trial_max_bold)
    a = clf.coef_[0]
    b = clf.intercept_
    report_info.bold_contrast_slope = a
    report_info.bold_contrast_intercept = b
    report_info.bold_contrast_r_sqr = clf.score(trial_contrast, trial_max_bold)

    furl = 'img/contrast_bold.png'
    fname = os.path.join(reports_dir, furl)
    report_info.contrast_bold_url = furl
    if regenerate_plot or not os.path.exists(fname):
        fig = plt.figure()
        plt.plot(trial_contrast, trial_max_bold, 'x')
        x_min = np.min(trial_contrast)
        x_max = np.max(trial_contrast)
        plt.plot([x_min, x_max], [a * x_min + b, a * x_max + b], '--')
        plt.xlabel('Input Contrast')
        plt.ylabel('Max BOLD')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/contrast_bold.eps'))
        plt.close()

    clf = LinearRegression()
    clf.fit(trial_max_rate, trial_max_bold)
    a = clf.coef_[0]
    b = clf.intercept_
    report_info.bold_firing_rate_slope = a
    report_info.bold_firing_rate_intercept = b
    report_info.bold_firing_rate_r_sqr = clf.score(trial_max_rate,
                                                   trial_max_bold)

    furl = 'img/firing_rate_bold.png'
    fname = os.path.join(reports_dir, furl)
    report_info.firing_rate_bold_url = furl
    if regenerate_plot or not os.path.exists(fname):
        fig = plt.figure()
        plt.plot(trial_max_rate, trial_max_bold, 'x')
        x_min = np.min(trial_max_rate)
        x_max = np.max(trial_max_rate)
        plt.plot([x_min, x_max], [a * x_min + b, a * x_max + b], '--')
        plt.xlabel('Max Firing Rate')
        plt.ylabel('Max BOLD')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/firing_rate_bold.eps'))
        plt.close()

    clf = LinearRegression()
    clf.fit(trial_rt, trial_max_bold)
    a = clf.coef_[0]
    b = clf.intercept_
    report_info.bold_rt_slope = a
    report_info.bold_rt_intercept = b
    report_info.bold_rt_r_sqr = clf.score(trial_rt, trial_max_bold)

    furl = 'img/response_time_bold.png'
    fname = os.path.join(reports_dir, furl)
    report_info.response_time_bold_url = furl
    if regenerate_plot or not os.path.exists(fname):
        fig = plt.figure()
        plt.plot(trial_rt, trial_max_bold, 'x')
        x_min = np.min(trial_rt)
        x_max = np.max(trial_rt)
        plt.plot([x_min, x_max], [a * x_min + b, a * x_max + b], '--')
        plt.xlabel('Response Time')
        plt.ylabel('Max BOLD')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir,
                                      'img/response_time_bold.eps'))
        plt.close()

    return report_info
Exemplo n.º 16
0
def run_full_adaptation_simulation(design, baseline):
    N = 150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params = default_params
    sim_params = rapid_design_params
    if design == 'long':
        network_params.tau_a = 5 * second
        sim_params = long_design_params

    data_dir = '../../data/adaptation/full_adaptation/'

    # High and low mean and variance examples
    low_var = 5
    high_var = 15
    low_mean = 50
    high_mean = 100

    stim = [(low_mean, low_var), (low_mean, high_var), (high_mean, low_var),
            (high_mean, high_var)]
    prob_adaptation = np.zeros([4, 4])
    samp_adaptation = np.zeros([4, 4])

    for i, (stim1_mean, stim1_var) in enumerate(stim):
        for j, (stim2_mean, stim2_var) in enumerate(stim):
            edesc = ''
            if stim1_mean == low_mean:
                edesc += 'low_mean.'
            else:
                edesc += 'high_mean.'
            if stim1_var == low_var:
                edesc += 'low_var-'
            else:
                edesc += 'high_var-'
            if stim2_mean == low_mean:
                edesc += 'low_mean.'
            else:
                edesc += 'high_mean.'
            if stim2_var == low_var:
                edesc += 'low_var'
            else:
                edesc += 'high_var'
            print('prob stim1: mean=%d, var=%d; stim2: mean=%d, var=%d' %
                  (stim1_mean, stim1_var, stim2_mean, stim2_var))
            prob_adaptation[i, j] = adaptation_simulation(
                design, baseline, ProbabilisticPopulationCode, N,
                network_params, sim_params, stim1_mean, stim2_mean, stim1_var,
                stim2_var, os.path.join(data_dir, 'prob', edesc), edesc)
            print('prob adaptation=%.4f' % prob_adaptation[i, j])

            print('samp stim1: mean=%d, var=%d; stim2: mean=%d, var=%d' %
                  (stim1_mean, stim1_var, stim2_mean, stim2_var))
            samp_adaptation[i, j] = adaptation_simulation(
                design, baseline, SamplingPopulationCode, N, network_params,
                sim_params, stim1_mean, stim2_mean, stim1_var, stim2_var,
                os.path.join(data_dir, 'samp', edesc), edesc)
            print('samp adaptation=%.4f' % samp_adaptation[i, j])

    fig = plt.figure()
    plt.title('Probabilistic Population')
    plt.imshow(prob_adaptation, interpolation='none')
    plt.colorbar()
    fname = '%s.baseline-%s.prob_pop' % (design, baseline)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    fig = plt.figure()
    plt.title('Sampling Population')
    plt.imshow(samp_adaptation, interpolation='none')
    plt.colorbar()
    fname = '%s.baseline-%s.samp_pop' % (design, baseline)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 17
0
def demo(N, network_params, trial_duration, x1, x2, low_var, high_var, isi,
         stim_dur):
    stim1_start_time = 1 * second
    stim1_end_time = stim1_start_time + stim_dur

    stim2_start_time = stim1_end_time + isi
    stim2_end_time = stim2_start_time + stim_dur

    low_var_prob_pop_monitor, low_var_prob_voxel_monitor = run_pop_code(
        ProbabilisticPopulationCode, N, network_params, [x1, x2],
        [low_var, low_var], [stim1_start_time, stim2_start_time],
        [stim1_end_time, stim2_end_time], trial_duration)

    high_var_prob_pop_monitor, high_var_prob_voxel_monitor = run_pop_code(
        ProbabilisticPopulationCode, N, network_params, [x1, x2],
        [high_var, high_var], [stim1_start_time, stim2_start_time],
        [stim1_end_time, stim2_end_time], trial_duration)

    low_var_samp_pop_monitor, low_var_samp_voxel_monitor = run_pop_code(
        SamplingPopulationCode, N, network_params, [x1, x2],
        [low_var, low_var], [stim1_start_time, stim2_start_time],
        [stim1_end_time, stim2_end_time], trial_duration)

    high_var_samp_pop_monitor, high_var_samp_voxel_monitor = run_pop_code(
        SamplingPopulationCode, N, network_params, [x1, x2],
        [high_var, high_var], [stim1_start_time, stim2_start_time],
        [stim1_end_time, stim2_end_time], trial_duration)

    data_dir = '../../data/adaptation/demo'

    fig = plt.figure()
    plt.subplot(411)
    plt.title('Probabilistic population, low variance - rate')
    plt.imshow(low_var_prob_pop_monitor['r'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, .2)
    plt.subplot(412)
    plt.title('Probabilistic population, high variance - rate')
    plt.imshow(high_var_prob_pop_monitor['r'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, .2)
    plt.subplot(413)
    plt.title('Sampling population, low variance - rate')
    plt.imshow(low_var_samp_pop_monitor['r'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, .2)
    plt.subplot(414)
    plt.title('Sampling population, high variance - rate')
    plt.imshow(high_var_samp_pop_monitor['r'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, .2)
    fname = 'firing_rate.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)

    fig = plt.figure()
    plt.subplot(411)
    plt.title('Probabilistic population, low variance - efficacy')
    plt.imshow(low_var_prob_pop_monitor['e'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, 1)
    plt.subplot(412)
    plt.title('Probabilistic population, high variance - efficacy')
    plt.imshow(high_var_prob_pop_monitor['e'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, 1)
    plt.subplot(413)
    plt.title('Sampling population, low variance - efficacy')
    plt.imshow(low_var_samp_pop_monitor['e'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, 1)
    plt.subplot(414)
    plt.title('Sampling population, high variance - efficacy')
    plt.imshow(high_var_samp_pop_monitor['e'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, 1)
    fname = 'efficacy.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)

    fig = plt.figure()
    plt.title('BOLD')
    plt.plot(low_var_prob_voxel_monitor['y'][0], label='prob,low var')
    plt.plot(high_var_prob_voxel_monitor['y'][0], label='prob,high var')
    plt.plot(low_var_samp_voxel_monitor['y'][0], label='samp,low var')
    plt.plot(high_var_samp_voxel_monitor['y'][0], label='samp,high var')
    plt.legend(loc='best')
    fname = 'bold.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)

    stim1_mid_time = stim1_start_time + (stim1_end_time - stim1_start_time) / 2
    idx1 = int(stim1_mid_time / defaultclock.dt)
    stim2_mid_time = stim2_start_time + (stim2_end_time - stim2_start_time) / 2
    idx2 = int(stim2_mid_time / defaultclock.dt)

    fig = plt.figure()
    plt.title('Probabilistic Population snapshot')
    plt.plot(low_var_prob_pop_monitor['r'][:, idx1],
             'r',
             label='low var, stim 1')
    plt.plot(low_var_prob_pop_monitor['r'][:, idx2],
             'r--',
             label='low var stim 2')
    plt.plot(high_var_prob_pop_monitor['r'][:, idx1],
             'b',
             label='high var, stim 1')
    plt.plot(high_var_prob_pop_monitor['r'][:, idx2],
             'b--',
             label='high var stim 2')
    plt.legend(loc='best')
    fname = 'prob_pop.firing_rate.snapshot.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)

    fig = plt.figure()
    plt.title('Sampling Population snapshot')
    plt.plot(low_var_samp_pop_monitor['r'][:, idx1],
             'r',
             label='low var, stim 1')
    plt.plot(low_var_samp_pop_monitor['r'][:, idx2],
             'r--',
             label='low var, stim 2')
    plt.plot(high_var_samp_pop_monitor['r'][:, idx1],
             'b',
             label='high var, stim 1')
    plt.plot(high_var_samp_pop_monitor['r'][:, idx2],
             'b--',
             label='high var, stim 2')
    plt.legend(loc='best')
    fname = 'samp_pop.firing_rate.snapshot.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)
Exemplo n.º 18
0
def test_simulation(design):
    N=150
    network_params=default_params
    sim_params=rapid_design_params
    network_params.tau_ar=100*ms
    if design=='long':
        network_params.tau_a=5*second
        sim_params=long_design_params
    var=10
    x1=50
    x2=100
    stim1_start_time=1*second
    stim1_end_time=stim1_start_time+sim_params.stim_dur
    stim2_start_time=stim1_end_time+sim_params.isi
    stim2_end_time=stim2_start_time+sim_params.stim_dur

    same_pop_monitor,same_voxel_monitor,same_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params,
        [Stimulus(x1,var,stim1_start_time,stim1_end_time),
         Stimulus(x1,var,stim2_start_time,stim2_end_time)],
        sim_params.trial_duration)
    diff_pop_monitor,diff_voxel_monitor,diff_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params,
        [Stimulus(x1,var,stim1_start_time,stim1_end_time),
         Stimulus(x2,var,stim2_start_time,stim2_end_time)],
        sim_params.trial_duration)
#    single_pop_monitor,single_voxel_monitor,single_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params,
#        [Stimulus(x1,var,stim1_start_time,stim1_end_time)],
#        sim_params.trial_duration)

    data_dir='../../data/adaptation/adaptation_test'
    fig=plt.figure()
    #plt.subplot(311)
    plt.subplot(211)
    plt.title('Same')
    plt.imshow(same_pop_monitor['r'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    #plt.subplot(312)
    plt.subplot(212)
    plt.title('Different')
    plt.imshow(diff_pop_monitor['r'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
#    plt.subplot(313)
#    plt.title('Single')
#    plt.imshow(single_pop_monitor['r'][:],aspect='auto')
#    plt.xlabel('time')
#    plt.ylabel('neuron')
#    plt.colorbar()
    fname='%s.firing_rate' % design
    #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

    fig=plt.figure()
    #plt.subplot(311)
    plt.subplot(211)
    plt.title('Same')
    plt.imshow(same_pop_monitor['e'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,1)
    #plt.subplot(312)
    plt.subplot(212)
    plt.title('Different')
    plt.imshow(diff_pop_monitor['e'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,1)
#    plt.subplot(313)
#    plt.title('Single')
#    plt.imshow(single_pop_monitor['e'][:],aspect='auto')
#    plt.xlabel('time')
#    plt.ylabel('neuron')
#    plt.colorbar()
#    plt.clim(0,1)
    fname='%s.efficacy' % design
    #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

    fig=plt.figure()
    plt.title('BOLD')
    plt.plot(same_voxel_monitor['y'][0],label='same')
    plt.plot(diff_voxel_monitor['y'][0],label='different')
    #plt.plot(single_voxel_monitor['y'][0],label='single')
    plt.legend(loc='best')
    fname='%s.bold' % design
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

#    fig=plt.figure()
#    plt.plot(same_pop_monitor['total_e'][0],label='same')
#    plt.plot(diff_pop_monitor['total_e'][0],label='different')
#    #plt.plot(single_pop_monitor['total_e'][0],label='single')
#    plt.legend(loc='best')
#    fname='%s.total_e' % design
#    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
#    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
#    plt.close(fig)
#
#    fig=plt.figure()
#    plt.plot(same_pop_monitor['total_r'][0],label='same')
#    plt.plot(diff_pop_monitor['total_r'][0],label='different')
#    #plt.plot(single_pop_monitor['total_r'][0],label='single')
#    plt.legend(loc='best')
#    fname='%s.total_r' % design
#    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
#    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
#    plt.close(fig)

    fig=plt.figure()
    plt.plot(same_voxel_monitor['G_total'][0][0:20000],label='same')
    plt.plot(diff_voxel_monitor['G_total'][0][0:20000],label='different')
    #plt.plot(single_voxel_monitor['G_total'][0][0:100000],label='single')
    plt.legend(loc='best')
    fname='%s.g_total' % design
    #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 19
0
def create_bold_report(reports_dir, trial_contrast, trial_max_bold, trial_max_rate, trial_rt, regenerate_plot=True):

    report_info=Struct()

    clf=LinearRegression()
    clf.fit(trial_contrast,trial_max_bold)
    a=clf.coef_[0]
    b=clf.intercept_
    report_info.bold_contrast_slope=a
    report_info.bold_contrast_intercept=b
    report_info.bold_contrast_r_sqr=clf.score(trial_contrast,trial_max_bold)

    furl='img/contrast_bold.png'
    fname=os.path.join(reports_dir, furl)
    report_info.contrast_bold_url=furl
    if regenerate_plot or not os.path.exists(fname):
        fig=plt.figure()
        plt.plot(trial_contrast, trial_max_bold, 'x')
        x_min=np.min(trial_contrast)
        x_max=np.max(trial_contrast)
        plt.plot([x_min,x_max],[a*x_min+b,a*x_max+b],'--')
        plt.xlabel('Input Contrast')
        plt.ylabel('Max BOLD')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/contrast_bold.eps'))
        plt.close()

    clf=LinearRegression()
    clf.fit(trial_max_rate,trial_max_bold)
    a=clf.coef_[0]
    b=clf.intercept_
    report_info.bold_firing_rate_slope=a
    report_info.bold_firing_rate_intercept=b
    report_info.bold_firing_rate_r_sqr=clf.score(trial_max_rate,trial_max_bold)

    furl='img/firing_rate_bold.png'
    fname=os.path.join(reports_dir, furl)
    report_info.firing_rate_bold_url=furl
    if regenerate_plot or not os.path.exists(fname):
        fig=plt.figure()
        plt.plot(trial_max_rate, trial_max_bold, 'x')
        x_min=np.min(trial_max_rate)
        x_max=np.max(trial_max_rate)
        plt.plot([x_min,x_max],[a*x_min+b,a*x_max+b],'--')
        plt.xlabel('Max Firing Rate')
        plt.ylabel('Max BOLD')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/firing_rate_bold.eps'))
        plt.close()

    clf=LinearRegression()
    clf.fit(trial_rt,trial_max_bold)
    a=clf.coef_[0]
    b=clf.intercept_
    report_info.bold_rt_slope=a
    report_info.bold_rt_intercept=b
    report_info.bold_rt_r_sqr=clf.score(trial_rt,trial_max_bold)

    furl='img/response_time_bold.png'
    fname=os.path.join(reports_dir, furl)
    report_info.response_time_bold_url=furl
    if regenerate_plot or not os.path.exists(fname):
        fig=plt.figure()
        plt.plot(trial_rt, trial_max_bold, 'x')
        x_min=np.min(trial_rt)
        x_max=np.max(trial_rt)
        plt.plot([x_min,x_max],[a*x_min+b,a*x_max+b],'--')
        plt.xlabel('Response Time')
        plt.ylabel('Max BOLD')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir, 'img/response_time_bold.eps'))
        plt.close()

    return report_info
Exemplo n.º 20
0
def create_trial_report(data, reports_dir, contrast, trial_idx, regenerate_plots=True):
    trial = Struct()
    trial.input_freq=data.input_freq
    trial.input_contrast=abs(data.input_freq[0]-data.input_freq[1])/sum(data.input_freq)
    trial.correct=0.0
    option_idx=-1
    if data.input_freq[0]>data.input_freq[1]:
        option_idx=0
    elif data.input_freq[1]>data.input_freq[0]:
        option_idx=1
    if option_idx>-1:
        if np.max(data.e_firing_rates[option_idx, 6500:7500])>np.max(data.e_firing_rates[1 - option_idx, 6500:7500]):
            trial.correct=1.0
    trial.rt=data.rt

    max_input_idx=np.where(trial.input_freq==np.max(trial.input_freq))[0][0]
    trial.max_input=trial.input_freq[max_input_idx]
    trial.max_rate=np.max(data.e_firing_rates[max_input_idx])

    trial.e_raster_url = None
    trial.i_raster_url = None
    if data.e_spike_neurons is not None and data.i_spike_neurons is not None:
        furl='img/e_raster.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname=os.path.join(reports_dir, furl)
        trial.e_raster_url = furl
        if regenerate_plots or not os.path.exists(fname):
            e_group_sizes=[int(4*data.network_group_size/5) for i in range(data.num_groups)]
            fig=plot_raster(data.e_spike_neurons, data.e_spike_times, e_group_sizes)
            save_to_png(fig, fname)
            save_to_eps(fig, os.path.join(reports_dir, 'img/e_raster.contrast.%0.4f.trial.%d.eps' % (contrast, trial_idx)))
            plt.close()

        furl='img/i_raster.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname=os.path.join(reports_dir, furl)
        trial.i_raster_url = furl
        if regenerate_plots or not os.path.exists(fname):
            i_group_sizes=[int(data.network_group_size/5) for i in range(data.num_groups)]
            fig=plot_raster(data.i_spike_neurons, data.i_spike_times, i_group_sizes)
            save_to_png(fig, fname)
            save_to_eps(fig, os.path.join(reports_dir, 'img/i_raster.contrast.%0.4f.trial.%d.eps' % (contrast, trial_idx)))
            plt.close()

    trial.firing_rate_url = None
    if data.e_firing_rates is not None and data.i_firing_rates is not None:
        furl = 'img/firing_rate.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.firing_rate_url = furl
        if regenerate_plots or not os.path.exists(fname):
            fig = plt.figure()
            ax = plt.subplot(211)
            for i, pop_rate in enumerate(data.e_firing_rates):
                ax.plot(np.array(range(len(pop_rate))) *.1, pop_rate / Hz, label='group %d' % i)
            plt.xlabel('Time (ms)')
            plt.ylabel('Firing Rate (Hz)')
            ax = plt.subplot(212)
            for i, pop_rate in enumerate(data.i_firing_rates):
                ax.plot(np.array(range(len(pop_rate))) *.1, pop_rate / Hz, label='group %d' % i)
            plt.xlabel('Time (ms)')
            plt.ylabel('Firing Rate (Hz)')
            save_to_png(fig, fname)
            save_to_eps(fig, os.path.join(reports_dir, 'img/firing_rate.contrast.%0.4f.trial.%d.eps' % (contrast, trial_idx)))
            plt.close()

    trial.neural_state_url=None
    if data.neural_state_rec is not None:
        furl = 'img/neural_state.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.neural_state_url = furl
        if regenerate_plots or not os.path.exists(fname):
            fig = plt.figure()
            for i in range(data.num_groups):
                times=np.array(range(len(data.neural_state_rec['g_ampa_r'][i*2])))*.1
                ax = plt.subplot(data.num_groups * 100 + 20 + (i * 2 + 1))
                ax.plot(times, data.neural_state_rec['g_ampa_r'][i * 2] / nA, label='AMPA-recurrent')
                ax.plot(times, data.neural_state_rec['g_ampa_x'][i * 2] / nA, label='AMPA-task')
                ax.plot(times, data.neural_state_rec['g_ampa_b'][i * 2] / nA, label='AMPA-backgrnd')
                ax.plot(times, data.neural_state_rec['g_nmda'][i * 2] / nA, label='NMDA')
                ax.plot(times, data.neural_state_rec['g_gaba_a'][i * 2] / nA, label='GABA_A')
                plt.xlabel('Time (ms)')
                plt.ylabel('Conductance (nA)')
                ax = plt.subplot(data.num_groups * 100 + 20 + (i * 2 + 2))
                ax.plot(times, data.neural_state_rec['g_ampa_r'][i * 2 + 1] / nA, label='AMPA-recurrent')
                ax.plot(times, data.neural_state_rec['g_ampa_x'][i * 2 + 1] / nA, label='AMPA-task')
                ax.plot(times, data.neural_state_rec['g_ampa_b'][i * 2 + 1] / nA, label='AMPA-backgrnd')
                ax.plot(times, data.neural_state_rec['g_nmda'][i * 2 + 1] / nA, label='NMDA')
                ax.plot(times, data.neural_state_rec['g_gaba_a'][i * 2 + 1] / nA, label='GABA_A')
                plt.xlabel('Time (ms)')
                plt.ylabel('Conductance (nA)')
            save_to_png(fig, fname)
            save_to_eps(fig, os.path.join(reports_dir, 'img/neural_state.contrast.%0.4f.trial.%d.eps' % (contrast, trial_idx)))
            plt.close()

    trial.lfp_url = None
    if data.lfp_rec is not None:
        furl = 'img/lfp.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.lfp_url = furl
        if regenerate_plots or not os.path.exists(fname):
            fig = plt.figure()
            ax = plt.subplot(111)
            lfp=get_lfp_signal(data)
            ax.plot(np.array(range(len(lfp))), lfp / mA)
            plt.xlabel('Time (ms)')
            plt.ylabel('LFP (mA)')
            save_to_png(fig, fname)
            save_to_eps(fig, os.path.join(reports_dir, 'img/lfp.contrast.%0.4f.trial.%d.eps' % (contrast, trial_idx)))
            plt.close()

    trial.voxel_url = None
    trial.max_bold=0
    if data.voxel_rec is not None:
        trial.max_bold=-1000
        for val in data.voxel_rec['y'][0]:
            if not math.isnan(val) and val>trial.max_bold:
                trial.max_bold=val
        furl = 'img/voxel.contrast.%0.4f.trial.%d.png' % (contrast, trial_idx)
        fname = os.path.join(reports_dir, furl)
        trial.voxel_url = furl
        if regenerate_plots or not os.path.exists(fname):
            end_idx=int(data.trial_duration/ms/.1)
            fig = plt.figure()
            ax = plt.subplot(211)
            ax.plot(np.array(range(end_idx))*.1, data.voxel_rec['G_total'][0][:end_idx] / nA)
            plt.xlabel('Time (ms)')
            plt.ylabel('Total Synaptic Activity (nA)')
            ax = plt.subplot(212)
            ax.plot(np.array(range(len(data.voxel_rec['y'][0])))*.1*ms, data.voxel_rec['y'][0])
            plt.xlabel('Time (s)')
            plt.ylabel('BOLD')
            save_to_png(fig, fname)
            save_to_eps(fig, os.path.join(reports_dir, 'img/voxel.contrast.%0.4f.trial.%d.eps' % (contrast, trial_idx)))
            plt.close()
    return trial
Exemplo n.º 21
0
def run_mean_adaptation_simulation(design, baseline):
    N = 150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params = default_params
    sim_params = rapid_design_params
    if design == 'long':
        network_params.tau_a = 5 * second
        sim_params = long_design_params

    data_dir = '../../data/adaptation/mean_shift/'

    x_delta_iter = 10
    # If baseline is single stimulus - need to test x_delta=0
    x_delta_range = np.array(range(0, int(N / 3), x_delta_iter))

    # High and low variance examples
    low_var = 5
    high_var = 15
    x = int(N / 3)

    prob_low_var_adaptation = np.zeros(len(x_delta_range))
    prob_high_var_adaptation = np.zeros(len(x_delta_range))
    samp_low_var_adaptation = np.zeros(len(x_delta_range))
    samp_high_var_adaptation = np.zeros(len(x_delta_range))
    for i, x_delta in enumerate(x_delta_range):
        print('x_delta=%d' % x_delta)

        prob_low_var_adaptation[i] = adaptation_simulation(
            design, baseline, ProbabilisticPopulationCode, N, network_params,
            sim_params, x, x + x_delta, low_var, low_var,
            os.path.join(data_dir, 'prob',
                         'low_var'), 'low_var.xdelta-%d' % x_delta)
        prob_high_var_adaptation[i] = adaptation_simulation(
            design, baseline, ProbabilisticPopulationCode, N, network_params,
            sim_params, x, x + x_delta, high_var, high_var,
            os.path.join(data_dir, 'prob',
                         'high_var'), 'high_var.xdelta-%d' % x_delta)

        samp_low_var_adaptation[i] = adaptation_simulation(
            design, baseline, SamplingPopulationCode, N, network_params,
            sim_params, x, x + x_delta, low_var, low_var,
            os.path.join(data_dir, 'samp',
                         'low_var'), 'low_var.xdelta-%d' % x_delta)
        samp_high_var_adaptation[i] = adaptation_simulation(
            design, baseline, SamplingPopulationCode, N, network_params,
            sim_params, x, x + x_delta, high_var, high_var,
            os.path.join(data_dir, 'samp',
                         'high_var'), 'high_var.xdelta-%d' % x_delta)

    fig = plt.figure()
    plt.title('Probabilistic Population Code')
    plt.plot(x_delta_range, prob_low_var_adaptation, 'r', label='low var')
    plt.plot(x_delta_range, prob_high_var_adaptation, 'b', label='high var')
    plt.legend(loc='best')
    fname = '%s.baseline-%s.prob_pop.mean_adaptation' % (design, baseline)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    fig = plt.figure()
    plt.title('Sampling Population Code')
    plt.plot(x_delta_range, samp_low_var_adaptation, 'r', label='low var')
    plt.plot(x_delta_range, samp_high_var_adaptation, 'b', label='high var')
    plt.legend(loc='best')
    fname = '%s.baseline-%s.samp_pop.mean_adaptation' % (design, baseline)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 22
0
def adaptation_simulation(design, baseline, pop_class, N, network_params,
                          sim_params, stim1_mean, stim2_mean, stim1_var,
                          stim2_var, data_dir, edesc):
    # Compute stimulus start and end times
    stim1_start_time = 1 * second
    stim1_end_time = stim1_start_time + sim_params.stim_dur

    stim2_start_time = stim1_end_time + sim_params.isi
    stim2_end_time = stim2_start_time + sim_params.stim_dur

    pop_monitor, voxel_monitor, y_max = run_pop_code(
        pop_class, N, network_params, [
            Stimulus(stim1_mean, stim1_var, stim1_start_time, stim1_end_time),
            Stimulus(stim2_mean, stim2_var, stim2_start_time, stim2_end_time)
        ], sim_params.trial_duration)

    if baseline == 'repeated':
        baseline_pop_monitor, baseline_voxel_monitor, baseline_y_max = run_pop_code(
            pop_class, N, network_params, [
                Stimulus(stim1_mean, stim1_var, stim1_start_time,
                         stim1_end_time),
                Stimulus(stim1_mean, stim1_var, stim2_start_time,
                         stim2_end_time)
            ], sim_params.trial_duration)
        adaptation = (y_max - baseline_y_max) / baseline_y_max
    elif baseline == 'single':
        baseline_pop_monitor, baseline_voxel_monitor, baseline_y_max = run_pop_code(
            pop_class, N, network_params, [
                Stimulus(stim2_mean, stim2_var, stim1_start_time,
                         stim1_end_time)
            ], rapid_design_params.trial_duration)
        adaptation = (y_max - baseline_y_max) / baseline_y_max

    fig = plt.figure()
    plt.plot(voxel_monitor['y'][0], 'b', label='test')
    plt.plot(baseline_voxel_monitor['y'][0], 'r', label='baseline')
    plt.legend(loc='best')
    fname = '%s.baseline-%s.%s.%s.bold' % (design, baseline, edesc,
                                           pop_class.__name__)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    fig = plt.figure()
    plt.subplot(211)
    plt.title('test')
    plt.imshow(pop_monitor['e'][:], aspect='auto')
    plt.clim(0, 1)
    plt.colorbar()
    plt.subplot(212)
    plt.title('baseline')
    plt.imshow(baseline_pop_monitor['e'][:], aspect='auto')
    plt.clim(0, 1)
    plt.colorbar()
    fname = '%s.baseline-%s.%s.%s.e' % (design, baseline, edesc,
                                        pop_class.__name__)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    #    fig=plt.figure()
    #    plt.plot(pop_monitor['total_e'][0],'b',label='test')
    #    plt.plot(baseline_pop_monitor['total_e'][0],'r',label='baseline')
    #    plt.legend(loc='best')
    #    fname='%s.baseline-%s.%s.%s.total_e' % (design,baseline,edesc,pop_class.__name__)
    #    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    #    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    #    plt.close(fig)
    #
    #    fig=plt.figure()
    #    plt.plot(pop_monitor['total_r'][0],'b',label='test')
    #    plt.plot(baseline_pop_monitor['total_r'][0],'r',label='baseline')
    #    plt.legend(loc='best')
    #    fname='%s.baseline-%s.%s.%s.total_r' % (design,baseline,edesc,pop_class.__name__)
    #    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    #    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    #    plt.close(fig)

    fig = plt.figure()
    plt.plot(voxel_monitor['G_total'][0][0:100000], 'b', label='test')
    plt.plot(baseline_voxel_monitor['G_total'][0][0:100000],
             'r',
             label='baseline')
    plt.legend(loc='best')
    fname = '%s.baseline-%s.%s.%s.g_total' % (design, baseline, edesc,
                                              pop_class.__name__)
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    return adaptation
Exemplo n.º 23
0
def render_summary_report(base_report_dir, bayes_analysis, p_b_e_range,
                          p_e_e_range, p_e_i_range, p_i_e_range, p_i_i_range,
                          p_x_e_range, report_info):
    template_file = 'bayes_analysis.html'
    env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
    template = env.get_template(template_file)

    all_vals = []
    all_vals.extend(bayes_analysis.l1_dist)
    all_vals.extend(bayes_analysis.l1_pos_dist)
    all_vals.extend(bayes_analysis.l1_neg_dist)

    dpi = 80
    inch_width = 800 / dpi
    inch_height = 1800 / dpi
    max_perc = 0.0

    #bins=min(all_vals)+np.array(range(int((max(all_vals)-min(all_vals))/.005)+1))*.005
    #bins=-.2+np.array(range(int(.4/.0025)+1))*.0025
    #hist=plt.hist(bayes_analysis.l1_dist, bins=bins, normed=True)
    l1_val_hist, l1_val_bins = np.histogram(bayes_analysis.l1_dist, bins=100)
    l1_val_hist = l1_val_hist.astype(float)
    l1_bin_width = l1_val_bins[0]
    if len(l1_val_bins) > 1:
        l1_bin_width = l1_val_bins[1] - l1_val_bins[0]
    l1_val_perc = (l1_val_hist / len(all_vals))
    if max(l1_val_perc) > max_perc:
        max_perc = max(l1_val_perc)
    l1_pos_val_hist, l1_pos_val_bins = np.histogram(bayes_analysis.l1_pos_dist,
                                                    bins=l1_val_bins)
    l1_pos_val_hist = l1_pos_val_hist.astype(float)
    l1_pos_bin_width = l1_pos_val_bins[0]
    if len(l1_pos_val_bins) > 1:
        l1_pos_bin_width = l1_pos_val_bins[1] - l1_pos_val_bins[0]
    l1_pos_val_perc = (l1_pos_val_hist / len(bayes_analysis.l1_pos_dist))
    if max(l1_pos_val_perc) > max_perc:
        max_perc = max(l1_pos_val_perc)
    l1_neg_val_hist, l1_neg_val_bins = np.histogram(bayes_analysis.l1_neg_dist,
                                                    bins=l1_val_bins)
    l1_neg_val_hist = l1_neg_val_hist.astype(float)
    l1_neg_bin_width = l1_neg_val_bins[0]
    if len(l1_neg_val_bins) > 1:
        l1_neg_bin_width = l1_neg_val_bins[1] - l1_neg_val_bins[0]
    l1_neg_val_perc = (l1_neg_val_hist / len(bayes_analysis.l1_neg_dist))
    if max(l1_neg_val_perc) > max_perc:
        max_perc = max(l1_neg_val_perc)

    fig = plt.figure(figsize=(inch_width, inch_height), dpi=dpi)
    ax = plt.subplot(311)
    plt.bar(l1_val_bins[:-1], l1_val_perc, width=l1_bin_width)
    plt.xlim(l1_val_bins[0], l1_val_bins[-1])
    plt.ylim([0, max_perc])
    plt.ylabel('L1 Probability')
    ax = plt.subplot(312)
    #plt.hist(bayes_analysis.l1_pos_dist, bins=hist[1], normed=True)
    plt.bar(l1_pos_val_bins[:-1], l1_pos_val_perc, width=l1_pos_bin_width)
    plt.xlim(l1_pos_val_bins[0], l1_pos_val_bins[-1])
    plt.ylim([0, max_perc])
    plt.ylabel('L1 Positive - Probability')
    ax = plt.subplot(313)
    #plt.hist(bayes_analysis.l1_neg_dist, bins=hist[1], normed=True)
    plt.bar(l1_neg_val_bins[:-1], l1_neg_val_perc, width=l1_neg_bin_width)
    plt.xlim(l1_neg_val_bins[0], l1_neg_val_bins[-1])
    plt.ylim([0, max_perc])
    plt.ylabel('L1 Negative - Probability')
    plt.xlabel('BOLD - Contrast Slope')
    fname = os.path.join('img', 'l1_dist.png')
    save_to_png(fig, os.path.join(base_report_dir, fname))
    save_to_eps(fig, os.path.join(base_report_dir, 'img', 'l1_dist.eps'))
    report_info.l1_dist_url = fname

    report_info.l1_pos_report_info = create_bayesian_report(
        'Level 1 - Positive', report_info.num_groups,
        report_info.trial_duration, report_info.roc_auc, report_info.bc_slope,
        report_info.bc_intercept, report_info.bc_r_sqr,
        bayes_analysis.l1_pos_evidence, bayes_analysis.l1_pos_posterior,
        bayes_analysis.l1_pos_marginals, p_b_e_range, p_x_e_range, p_e_e_range,
        p_e_i_range, p_i_i_range, p_i_e_range, 'l1_pos', base_report_dir,
        report_info.edesc, .3)
    output_file = 'l1_pos_bayes_analysis.html'
    report_info.l1_pos_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_report_info)
    stream.dump(fname)

    report_info.l1_neg_report_info = create_bayesian_report(
        'Level 1 - Negative', report_info.num_groups,
        report_info.trial_duration, report_info.roc_auc, report_info.bc_slope,
        report_info.bc_intercept, report_info.bc_r_sqr,
        bayes_analysis.l1_neg_evidence, bayes_analysis.l1_neg_posterior,
        bayes_analysis.l1_neg_marginals, p_b_e_range, p_x_e_range, p_e_e_range,
        p_e_i_range, p_i_i_range, p_i_e_range, 'l1_neg', base_report_dir,
        report_info.edesc, .3)
    output_file = 'l1_neg_bayes_analysis.html'
    report_info.l1_neg_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_report_info)
    stream.dump(fname)

    report_info.l1_pos_l2_neg_report_info = create_bayesian_report(
        'Level 1 - Positive, Level 2 - Negative Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_pos_l2_neg_evidence,
        bayes_analysis.l1_pos_l2_neg_posterior,
        bayes_analysis.l1_pos_l2_neg_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_pos_l2_neg',
        base_report_dir, report_info.edesc, .7)
    output_file = 'l1_pos_l2_neg_bayes_analysis.html'
    report_info.l1_pos_l2_neg_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_l2_neg_report_info)
    stream.dump(fname)

    report_info.l1_neg_l2_neg_report_info = create_bayesian_report(
        'Level 1 - Negative, Level 2 - Negative Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_neg_l2_neg_evidence,
        bayes_analysis.l1_neg_l2_neg_posterior,
        bayes_analysis.l1_neg_l2_neg_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_neg_l2_neg',
        base_report_dir, report_info.edesc, .8)
    output_file = 'l1_neg_l2_neg_bayes_analysis.html'
    report_info.l1_neg_l2_neg_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_l2_neg_report_info)
    stream.dump(fname)

    report_info.l1_pos_l2_pos_report_info = create_bayesian_report(
        'Level 1- Positive, Level 2 - Positive Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_pos_l2_pos_evidence,
        bayes_analysis.l1_pos_l2_pos_posterior,
        bayes_analysis.l1_pos_l2_pos_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_pos_l2_pos',
        base_report_dir, report_info.edesc, .7)
    output_file = 'l1_pos_l2_pos_bayes_analysis.html'
    report_info.l1_pos_l2_pos_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_l2_pos_report_info)
    stream.dump(fname)

    report_info.l1_neg_l2_pos_report_info = create_bayesian_report(
        'Level 1- Negative, Level 2 - Positive Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_neg_l2_pos_evidence,
        bayes_analysis.l1_neg_l2_pos_posterior,
        bayes_analysis.l1_neg_l2_pos_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_neg_l2_pos',
        base_report_dir, report_info.edesc, .8)
    output_file = 'l1_neg_l2_pos_bayes_analysis.html'
    report_info.l1_neg_l2_pos_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_l2_pos_report_info)
    stream.dump(fname)

    report_info.l1_pos_l2_zero_report_info = create_bayesian_report(
        'Level 1 - Positive, Level 2 - Zero Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_pos_l2_zero_evidence,
        bayes_analysis.l1_pos_l2_zero_posterior,
        bayes_analysis.l1_pos_l2_zero_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_pos_l2_zero',
        base_report_dir, report_info.edesc, .7)
    output_file = 'l1_pos_l2_zero_bayes_analysis.html'
    report_info.l1_pos_l2_zero_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_l2_zero_report_info)
    stream.dump(fname)

    report_info.l1_neg_l2_zero_report_info = create_bayesian_report(
        'Level 1 - Negative, Level 2 - Zero Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_neg_l2_zero_evidence,
        bayes_analysis.l1_neg_l2_zero_posterior,
        bayes_analysis.l1_neg_l2_zero_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_neg_l2_zero',
        base_report_dir, report_info.edesc, .8)
    output_file = 'l1_neg_l2_zero_bayes_analysis.html'
    report_info.l1_neg_l2_zero_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_l2_zero_report_info)
    stream.dump(fname)

    template_file = 'wta_network.html'
    env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
    template = env.get_template(template_file)
    output_file = 'wta_network.html'
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info)
    stream.dump(fname)
Exemplo n.º 24
0
def render_summary_report(base_report_dir, bayes_analysis, p_b_e_range, p_e_e_range, p_e_i_range, p_i_e_range,
                          p_i_i_range, p_x_e_range, report_info):
    template_file = 'bayes_analysis.html'
    env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
    template = env.get_template(template_file)

    all_vals=[]
    all_vals.extend(bayes_analysis.l1_dist)
    all_vals.extend(bayes_analysis.l1_pos_dist)
    all_vals.extend(bayes_analysis.l1_neg_dist)

    dpi = 80
    inch_width = 800 / dpi
    inch_height = 1800 / dpi
    max_perc=0.0

    #bins=min(all_vals)+np.array(range(int((max(all_vals)-min(all_vals))/.005)+1))*.005
    #bins=-.2+np.array(range(int(.4/.0025)+1))*.0025
    #hist=plt.hist(bayes_analysis.l1_dist, bins=bins, normed=True)
    l1_val_hist, l1_val_bins = np.histogram(bayes_analysis.l1_dist, bins=100)
    l1_val_hist = l1_val_hist.astype(float)
    l1_bin_width=l1_val_bins[0]
    if len(l1_val_bins)>1:
        l1_bin_width = l1_val_bins[1] - l1_val_bins[0]
    l1_val_perc=(l1_val_hist/len(all_vals))
    if max(l1_val_perc)>max_perc:
        max_perc=max(l1_val_perc)
    l1_pos_val_hist, l1_pos_val_bins = np.histogram(bayes_analysis.l1_pos_dist, bins=l1_val_bins)
    l1_pos_val_hist = l1_pos_val_hist.astype(float)
    l1_pos_bin_width=l1_pos_val_bins[0]
    if len(l1_pos_val_bins)>1:
        l1_pos_bin_width = l1_pos_val_bins[1] - l1_pos_val_bins[0]
    l1_pos_val_perc=(l1_pos_val_hist/len(bayes_analysis.l1_pos_dist))
    if max(l1_pos_val_perc)>max_perc:
        max_perc=max(l1_pos_val_perc)
    l1_neg_val_hist, l1_neg_val_bins = np.histogram(bayes_analysis.l1_neg_dist, bins=l1_val_bins)
    l1_neg_val_hist = l1_neg_val_hist.astype(float)
    l1_neg_bin_width=l1_neg_val_bins[0]
    if len(l1_neg_val_bins)>1:
        l1_neg_bin_width = l1_neg_val_bins[1] - l1_neg_val_bins[0]
    l1_neg_val_perc=(l1_neg_val_hist/len(bayes_analysis.l1_neg_dist))
    if max(l1_neg_val_perc)>max_perc:
        max_perc=max(l1_neg_val_perc)


    fig = plt.figure(figsize=(inch_width, inch_height), dpi=dpi)
    ax=plt.subplot(311)
    plt.bar(l1_val_bins[:-1], l1_val_perc, width=l1_bin_width)
    plt.xlim(l1_val_bins[0],l1_val_bins[-1])
    plt.ylim([0,max_perc])
    plt.ylabel('L1 Probability')
    ax=plt.subplot(312)
    #plt.hist(bayes_analysis.l1_pos_dist, bins=hist[1], normed=True)
    plt.bar(l1_pos_val_bins[:-1], l1_pos_val_perc, width=l1_pos_bin_width)
    plt.xlim(l1_pos_val_bins[0],l1_pos_val_bins[-1])
    plt.ylim([0,max_perc])
    plt.ylabel('L1 Positive - Probability')
    ax=plt.subplot(313)
    #plt.hist(bayes_analysis.l1_neg_dist, bins=hist[1], normed=True)
    plt.bar(l1_neg_val_bins[:-1], l1_neg_val_perc, width=l1_neg_bin_width)
    plt.xlim(l1_neg_val_bins[0],l1_neg_val_bins[-1])
    plt.ylim([0,max_perc])
    plt.ylabel('L1 Negative - Probability')
    plt.xlabel('BOLD - Contrast Slope')
    fname=os.path.join('img','l1_dist.png')
    save_to_png(fig, os.path.join(base_report_dir, fname))
    save_to_eps(fig, os.path.join(base_report_dir, 'img','l1_dist.eps'))
    report_info.l1_dist_url=fname


    report_info.l1_pos_report_info = create_bayesian_report('Level 1 - Positive', report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept, report_info.bc_r_sqr,
        bayes_analysis.l1_pos_evidence, bayes_analysis.l1_pos_posterior, bayes_analysis.l1_pos_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_pos', base_report_dir, report_info.edesc, .3)
    output_file = 'l1_pos_bayes_analysis.html'
    report_info.l1_pos_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_report_info)
    stream.dump(fname)

    report_info.l1_neg_report_info = create_bayesian_report('Level 1 - Negative', report_info.num_groups, report_info.trial_duration,
        report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept, report_info.bc_r_sqr,
        bayes_analysis.l1_neg_evidence, bayes_analysis.l1_neg_posterior, bayes_analysis.l1_neg_marginals, p_b_e_range, p_x_e_range,
        p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range, 'l1_neg', base_report_dir, report_info.edesc, .3)
    output_file = 'l1_neg_bayes_analysis.html'
    report_info.l1_neg_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_report_info)
    stream.dump(fname)


    report_info.l1_pos_l2_neg_report_info = create_bayesian_report('Level 1 - Positive, Level 2 - Negative Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration, report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_pos_l2_neg_evidence, bayes_analysis.l1_pos_l2_neg_posterior,
        bayes_analysis.l1_pos_l2_neg_marginals, p_b_e_range, p_x_e_range, p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range,
        'l1_pos_l2_neg', base_report_dir, report_info.edesc, .7)
    output_file = 'l1_pos_l2_neg_bayes_analysis.html'
    report_info.l1_pos_l2_neg_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_l2_neg_report_info)
    stream.dump(fname)

    report_info.l1_neg_l2_neg_report_info = create_bayesian_report('Level 1 - Negative, Level 2 - Negative Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration, report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_neg_l2_neg_evidence, bayes_analysis.l1_neg_l2_neg_posterior,
        bayes_analysis.l1_neg_l2_neg_marginals, p_b_e_range, p_x_e_range, p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range,
        'l1_neg_l2_neg', base_report_dir, report_info.edesc, .8)
    output_file = 'l1_neg_l2_neg_bayes_analysis.html'
    report_info.l1_neg_l2_neg_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_l2_neg_report_info)
    stream.dump(fname)

    report_info.l1_pos_l2_pos_report_info = create_bayesian_report('Level 1- Positive, Level 2 - Positive Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration, report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_pos_l2_pos_evidence, bayes_analysis.l1_pos_l2_pos_posterior,
        bayes_analysis.l1_pos_l2_pos_marginals, p_b_e_range, p_x_e_range, p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range,
        'l1_pos_l2_pos', base_report_dir, report_info.edesc, .7)
    output_file = 'l1_pos_l2_pos_bayes_analysis.html'
    report_info.l1_pos_l2_pos_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_l2_pos_report_info)
    stream.dump(fname)

    report_info.l1_neg_l2_pos_report_info = create_bayesian_report('Level 1- Negative, Level 2 - Positive Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration, report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_neg_l2_pos_evidence, bayes_analysis.l1_neg_l2_pos_posterior,
        bayes_analysis.l1_neg_l2_pos_marginals, p_b_e_range, p_x_e_range, p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range,
        'l1_neg_l2_pos', base_report_dir, report_info.edesc, .8)
    output_file = 'l1_neg_l2_pos_bayes_analysis.html'
    report_info.l1_neg_l2_pos_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_l2_pos_report_info)
    stream.dump(fname)

    report_info.l1_pos_l2_zero_report_info = create_bayesian_report('Level 1 - Positive, Level 2 - Zero Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration, report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_pos_l2_zero_evidence, bayes_analysis.l1_pos_l2_zero_posterior,
        bayes_analysis.l1_pos_l2_zero_marginals, p_b_e_range, p_x_e_range, p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range,
        'l1_pos_l2_zero', base_report_dir, report_info.edesc, .7)
    output_file = 'l1_pos_l2_zero_bayes_analysis.html'
    report_info.l1_pos_l2_zero_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_pos_l2_zero_report_info)
    stream.dump(fname)

    report_info.l1_neg_l2_zero_report_info = create_bayesian_report('Level 1 - Negative, Level 2 - Zero Bold-Contrast Slope',
        report_info.num_groups, report_info.trial_duration, report_info.roc_auc, report_info.bc_slope, report_info.bc_intercept,
        report_info.bc_r_sqr, bayes_analysis.l1_neg_l2_zero_evidence, bayes_analysis.l1_neg_l2_zero_posterior,
        bayes_analysis.l1_neg_l2_zero_marginals, p_b_e_range, p_x_e_range, p_e_e_range, p_e_i_range, p_i_i_range, p_i_e_range,
        'l1_neg_l2_zero', base_report_dir, report_info.edesc, .8)
    output_file = 'l1_neg_l2_zero_bayes_analysis.html'
    report_info.l1_neg_l2_zero_url = output_file
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info.l1_neg_l2_zero_report_info)
    stream.dump(fname)


    template_file = 'wta_network.html'
    env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
    template = env.get_template(template_file)
    output_file = 'wta_network.html'
    fname = os.path.join(base_report_dir, output_file)
    stream = template.stream(rinfo=report_info)
    stream.dump(fname)
Exemplo n.º 25
0
def adaptation_simulation(design, baseline, pop_class, N, network_params, sim_params, stim1_mean, stim2_mean, stim1_var,
                          stim2_var, data_dir, edesc):
    # Compute stimulus start and end times
    stim1_start_time=1*second
    stim1_end_time=stim1_start_time+sim_params.stim_dur

    stim2_start_time=stim1_end_time+sim_params.isi
    stim2_end_time=stim2_start_time+sim_params.stim_dur

    pop_monitor,voxel_monitor,y_max=run_pop_code(pop_class, N, network_params,
        [Stimulus(stim1_mean, stim1_var, stim1_start_time, stim1_end_time),
         Stimulus(stim2_mean, stim2_var, stim2_start_time, stim2_end_time)],
        sim_params.trial_duration)

    if baseline=='repeated':
        baseline_pop_monitor,baseline_voxel_monitor,baseline_y_max=run_pop_code(pop_class, N, network_params,
            [Stimulus(stim1_mean,stim1_var,stim1_start_time,stim1_end_time),
             Stimulus(stim1_mean,stim1_var,stim2_start_time,stim2_end_time)],
            sim_params.trial_duration)
        adaptation=(y_max-baseline_y_max)/baseline_y_max
    elif baseline=='single':
        baseline_pop_monitor,baseline_voxel_monitor,baseline_y_max=run_pop_code(pop_class, N, network_params,
            [Stimulus(stim2_mean, stim2_var, stim1_start_time, stim1_end_time)],
            rapid_design_params.trial_duration)
        adaptation=(y_max-baseline_y_max)/baseline_y_max

    fig=plt.figure()
    plt.plot(voxel_monitor['y'][0], 'b', label='test')
    plt.plot(baseline_voxel_monitor['y'][0], 'r', label='baseline')
    plt.legend(loc='best')
    fname='%s.baseline-%s.%s.%s.bold' % (design,baseline,edesc,pop_class.__name__)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

    fig=plt.figure()
    plt.subplot(211)
    plt.title('test')
    plt.imshow(pop_monitor['e'][:],aspect='auto')
    plt.clim(0,1)
    plt.colorbar()
    plt.subplot(212)
    plt.title('baseline')
    plt.imshow(baseline_pop_monitor['e'][:],aspect='auto')
    plt.clim(0,1)
    plt.colorbar()
    fname='%s.baseline-%s.%s.%s.e' % (design,baseline,edesc,pop_class.__name__)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

#    fig=plt.figure()
#    plt.plot(pop_monitor['total_e'][0],'b',label='test')
#    plt.plot(baseline_pop_monitor['total_e'][0],'r',label='baseline')
#    plt.legend(loc='best')
#    fname='%s.baseline-%s.%s.%s.total_e' % (design,baseline,edesc,pop_class.__name__)
#    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
#    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
#    plt.close(fig)
#
#    fig=plt.figure()
#    plt.plot(pop_monitor['total_r'][0],'b',label='test')
#    plt.plot(baseline_pop_monitor['total_r'][0],'r',label='baseline')
#    plt.legend(loc='best')
#    fname='%s.baseline-%s.%s.%s.total_r' % (design,baseline,edesc,pop_class.__name__)
#    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
#    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
#    plt.close(fig)

    fig=plt.figure()
    plt.plot(voxel_monitor['G_total'][0][0:100000],'b',label='test')
    plt.plot(baseline_voxel_monitor['G_total'][0][0:100000],'r',label='baseline')
    plt.legend(loc='best')
    fname='%s.baseline-%s.%s.%s.g_total' % (design,baseline,edesc,pop_class.__name__)
    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    plt.close(fig)

    return adaptation
Exemplo n.º 26
0
def create_wta_network_report(file_prefix,
                              contrast_range,
                              num_trials,
                              reports_dir,
                              edesc,
                              regenerate_network_plots=True,
                              regenerate_trial_plots=True):

    make_report_dirs(reports_dir)

    report_info = Struct()
    report_info.edesc = edesc
    report_info.trials = []

    (data_dir, data_file_prefix) = os.path.split(file_prefix)

    total_trials = num_trials * len(contrast_range)
    trial_contrast = np.zeros([total_trials, 1])
    trial_max_bold = np.zeros(total_trials)
    trial_max_input = np.zeros([total_trials, 1])
    trial_max_rate = np.zeros([total_trials, 1])
    trial_rt = np.zeros([total_trials, 1])

    report_info.contrast_accuracy = np.zeros([len(contrast_range), 1])

    max_bold = []
    for j, contrast in enumerate(contrast_range):
        contrast_max_bold = []
        report_info.contrast_accuracy[j] = 0.0
        for i in range(num_trials):
            file_name = '%s.contrast.%0.4f.trial.%d.h5' % (file_prefix,
                                                           contrast, i)
            print('opening %s' % file_name)
            data = FileInfo(file_name)

            if not i:
                report_info.wta_params = data.wta_params
                report_info.voxel_params = data.voxel_params
                report_info.num_groups = data.num_groups
                report_info.trial_duration = data.trial_duration
                report_info.background_rate = data.background_rate
                report_info.stim_start_time = data.stim_start_time
                report_info.stim_end_time = data.stim_end_time
                report_info.network_group_size = data.network_group_size
                report_info.background_input_size = data.background_input_size
                report_info.task_input_size = data.task_input_size

            trial_idx = j * num_trials + i
            trial = create_trial_report(
                data,
                reports_dir,
                contrast,
                i,
                regenerate_plots=regenerate_trial_plots)
            trial_contrast[trial_idx] = trial.input_contrast
            if not math.isnan(trial.max_bold):
                trial_max_bold[trial_idx] = trial.max_bold
            else:
                if j > 1 and max_bold[j - 1] < 1.0 and max_bold[j - 2] < 1.0:
                    trial_max_bold[trial_idx] = max_bold[j - 1] + (
                        max_bold[j - 1] - max_bold[j - 2])
                elif j > 0 and max_bold[j - 1] < 1.0:
                    trial_max_bold[trial_idx] = max_bold[j - 1] * 2.0
                else:
                    trial_max_bold[trial_idx] = 1.0

            report_info.contrast_accuracy[j] += trial.correct

            trial_max_input[trial_idx] = trial.max_input
            trial_max_rate[trial_idx] = trial.max_rate
            trial_rt[trial_idx] = trial.rt
            report_info.trials.append(trial)

            contrast_max_bold.append(trial_max_bold[trial_idx])
        report_info.contrast_accuracy[j] /= float(num_trials)
        mean_contrast_bold = np.mean(np.array(contrast_max_bold))
        max_bold.append(mean_contrast_bold)

    clf = LinearRegression()
    clf.fit(trial_max_input, trial_max_rate)
    a = clf.coef_[0]
    b = clf.intercept_
    report_info.io_slope = a
    report_info.io_intercept = b
    report_info.io_r_sqr = clf.score(trial_max_input, trial_max_rate)

    furl = 'img/input_output_rate.png'
    fname = os.path.join(reports_dir, furl)
    report_info.input_output_rate_url = furl
    if regenerate_network_plots or not os.path.exists(fname):
        fig = plt.figure()
        plt.plot(trial_max_input, trial_max_rate, 'x')
        x_min = np.min(trial_max_input)
        x_max = np.max(trial_max_input)
        plt.plot([x_min, x_max], [x_min, x_max], '--')
        plt.plot([x_min, x_max], [a * x_min + b, a * x_max + b], '--')
        plt.xlabel('Max Input Rate')
        plt.ylabel('Max Population Rate')
        save_to_png(fig, fname)
        save_to_eps(fig, os.path.join(reports_dir,
                                      'img/input_output_rate.eps'))
        plt.close()

    report_info.bold = create_bold_report(
        reports_dir,
        trial_contrast,
        trial_max_bold,
        trial_max_rate,
        trial_rt,
        regenerate_plot=regenerate_network_plots)

    report_info.roc = create_roc_report(
        file_prefix,
        report_info.num_groups,
        contrast_range,
        num_trials,
        reports_dir,
        regenerate_plot=regenerate_network_plots)

    #create report
    template_file = 'wta_network_instance.html'
    env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
    template = env.get_template(template_file)

    output_file = 'wta_network.%s.html' % data_file_prefix
    fname = os.path.join(reports_dir, output_file)
    stream = template.stream(rinfo=report_info)
    stream.dump(fname)

    return report_info
Exemplo n.º 27
0
def test_simulation(design):
    N = 150
    network_params = default_params
    sim_params = rapid_design_params
    network_params.tau_ar = 100 * ms
    if design == 'long':
        network_params.tau_a = 5 * second
        sim_params = long_design_params
    var = 10
    x1 = 50
    x2 = 100
    stim1_start_time = 1 * second
    stim1_end_time = stim1_start_time + sim_params.stim_dur
    stim2_start_time = stim1_end_time + sim_params.isi
    stim2_end_time = stim2_start_time + sim_params.stim_dur

    same_pop_monitor, same_voxel_monitor, same_y_max = run_pop_code(
        ProbabilisticPopulationCode, N, network_params, [
            Stimulus(x1, var, stim1_start_time, stim1_end_time),
            Stimulus(x1, var, stim2_start_time, stim2_end_time)
        ], sim_params.trial_duration)
    diff_pop_monitor, diff_voxel_monitor, diff_y_max = run_pop_code(
        ProbabilisticPopulationCode, N, network_params, [
            Stimulus(x1, var, stim1_start_time, stim1_end_time),
            Stimulus(x2, var, stim2_start_time, stim2_end_time)
        ], sim_params.trial_duration)
    #    single_pop_monitor,single_voxel_monitor,single_y_max=run_pop_code(ProbabilisticPopulationCode, N, network_params,
    #        [Stimulus(x1,var,stim1_start_time,stim1_end_time)],
    #        sim_params.trial_duration)

    data_dir = '../../data/adaptation/adaptation_test'
    fig = plt.figure()
    #plt.subplot(311)
    plt.subplot(211)
    plt.title('Same')
    plt.imshow(same_pop_monitor['r'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    #plt.subplot(312)
    plt.subplot(212)
    plt.title('Different')
    plt.imshow(diff_pop_monitor['r'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    #    plt.subplot(313)
    #    plt.title('Single')
    #    plt.imshow(single_pop_monitor['r'][:],aspect='auto')
    #    plt.xlabel('time')
    #    plt.ylabel('neuron')
    #    plt.colorbar()
    fname = '%s.firing_rate' % design
    #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    fig = plt.figure()
    #plt.subplot(311)
    plt.subplot(211)
    plt.title('Same')
    plt.imshow(same_pop_monitor['e'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, 1)
    #plt.subplot(312)
    plt.subplot(212)
    plt.title('Different')
    plt.imshow(diff_pop_monitor['e'][:], aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0, 1)
    #    plt.subplot(313)
    #    plt.title('Single')
    #    plt.imshow(single_pop_monitor['e'][:],aspect='auto')
    #    plt.xlabel('time')
    #    plt.ylabel('neuron')
    #    plt.colorbar()
    #    plt.clim(0,1)
    fname = '%s.efficacy' % design
    #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    fig = plt.figure()
    plt.title('BOLD')
    plt.plot(same_voxel_monitor['y'][0], label='same')
    plt.plot(diff_voxel_monitor['y'][0], label='different')
    #plt.plot(single_voxel_monitor['y'][0],label='single')
    plt.legend(loc='best')
    fname = '%s.bold' % design
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)

    #    fig=plt.figure()
    #    plt.plot(same_pop_monitor['total_e'][0],label='same')
    #    plt.plot(diff_pop_monitor['total_e'][0],label='different')
    #    #plt.plot(single_pop_monitor['total_e'][0],label='single')
    #    plt.legend(loc='best')
    #    fname='%s.total_e' % design
    #    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    #    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    #    plt.close(fig)
    #
    #    fig=plt.figure()
    #    plt.plot(same_pop_monitor['total_r'][0],label='same')
    #    plt.plot(diff_pop_monitor['total_r'][0],label='different')
    #    #plt.plot(single_pop_monitor['total_r'][0],label='single')
    #    plt.legend(loc='best')
    #    fname='%s.total_r' % design
    #    save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    #    save_to_eps(fig, os.path.join(data_dir,'%s.eps' % fname))
    #    plt.close(fig)

    fig = plt.figure()
    plt.plot(same_voxel_monitor['G_total'][0][0:20000], label='same')
    plt.plot(diff_voxel_monitor['G_total'][0][0:20000], label='different')
    #plt.plot(single_voxel_monitor['G_total'][0][0:100000],label='single')
    plt.legend(loc='best')
    fname = '%s.g_total' % design
    #save_to_png(fig, os.path.join(data_dir,'%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 28
0
def run_repeated_test():
    N = 150
    # Set trial duration, inter-stimulus-interval, and stimulus duration depending on design
    network_params = default_params
    sim_params = rapid_design_params

    # Compute stimulus start and end times
    stim1_start_time = 1 * second
    stim1_end_time = stim1_start_time + sim_params.stim_dur

    stim2_start_time = stim1_end_time + sim_params.isi
    stim2_end_time = stim2_start_time + sim_params.stim_dur

    x_delta_iter = 5
    # If baseline is single stimulus - need to test x_delta=0
    x_delta_range = np.array(range(0, int(N / 3), x_delta_iter))

    # High and low variance examples
    low_var = 5
    x = int(N / 3)

    prob_combined_y_max = np.zeros(len(x_delta_range))
    prob_repeated_y_max = np.zeros(len(x_delta_range))
    samp_combined_y_max = np.zeros(len(x_delta_range))
    samp_repeated_y_max = np.zeros(len(x_delta_range))
    for i, x_delta in enumerate(x_delta_range):
        print('x_delta=%d' % x_delta)

        pop_monitor, voxel_monitor, prob_repeated_y_max[i] = run_pop_code(
            ProbabilisticPopulationCode, N, network_params, [
                Stimulus(x, low_var, stim1_start_time, stim1_end_time),
                Stimulus(x + x_delta, low_var, stim2_start_time,
                         stim2_end_time)
            ], sim_params.trial_duration)
        pop_monitor, voxel_monitor, prob_first_y_max = run_pop_code(
            ProbabilisticPopulationCode, N, network_params,
            [Stimulus(x, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        pop_monitor, voxel_monitor, prob_second_y_max = run_pop_code(
            ProbabilisticPopulationCode, N, network_params,
            [Stimulus(x + x_delta, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        prob_combined_y_max[i] = prob_first_y_max + prob_second_y_max

        pop_monitor, voxel_monitor, samp_repeated_y_max[i] = run_pop_code(
            SamplingPopulationCode, N, network_params, [
                Stimulus(x, low_var, stim1_start_time, stim1_end_time),
                Stimulus(x + x_delta, low_var, stim2_start_time,
                         stim2_end_time)
            ], sim_params.trial_duration)
        pop_monitor, voxel_monitor, samp_first_y_max = run_pop_code(
            SamplingPopulationCode, N, network_params,
            [Stimulus(x, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        pop_monitor, voxel_monitor, samp_second_y_max = run_pop_code(
            SamplingPopulationCode, N, network_params,
            [Stimulus(x + x_delta, low_var, stim1_start_time, stim1_end_time)],
            sim_params.trial_duration)
        samp_combined_y_max[i] = samp_first_y_max + samp_second_y_max

    data_dir = '../../data/adaptation/repeated_test/'

    fig = plt.figure()
    plt.plot(x_delta_range,
             prob_combined_y_max - prob_repeated_y_max,
             'r',
             label='prob')
    plt.plot(x_delta_range,
             samp_combined_y_max - samp_repeated_y_max,
             'b',
             label='samp')
    plt.legend(loc='best')
    fname = 'repeated_test'
    save_to_png(fig, os.path.join(data_dir, '%s.png' % fname))
    save_to_eps(fig, os.path.join(data_dir, '%s.eps' % fname))
    plt.close(fig)
Exemplo n.º 29
0
def demo(N, network_params, trial_duration, x1, x2, low_var, high_var, isi, stim_dur):
    stim1_start_time=1*second
    stim1_end_time=stim1_start_time+stim_dur

    stim2_start_time=stim1_end_time+isi
    stim2_end_time=stim2_start_time+stim_dur

    low_var_prob_pop_monitor,low_var_prob_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params,
        [x1,x2],[low_var,low_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration)

    high_var_prob_pop_monitor,high_var_prob_voxel_monitor=run_pop_code(ProbabilisticPopulationCode, N, network_params,
        [x1,x2],[high_var,high_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],
        trial_duration)

    low_var_samp_pop_monitor,low_var_samp_voxel_monitor=run_pop_code(SamplingPopulationCode, N, network_params, [x1,x2],
        [low_var,low_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration)

    high_var_samp_pop_monitor,high_var_samp_voxel_monitor=run_pop_code(SamplingPopulationCode, N, network_params, [x1,x2],
        [high_var,high_var], [stim1_start_time,stim2_start_time], [stim1_end_time,stim2_end_time],trial_duration)

    data_dir='../../data/adaptation/demo'

    fig=plt.figure()
    plt.subplot(411)
    plt.title('Probabilistic population, low variance - rate')
    plt.imshow(low_var_prob_pop_monitor['r'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,.2)
    plt.subplot(412)
    plt.title('Probabilistic population, high variance - rate')
    plt.imshow(high_var_prob_pop_monitor['r'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,.2)
    plt.subplot(413)
    plt.title('Sampling population, low variance - rate')
    plt.imshow(low_var_samp_pop_monitor['r'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,.2)
    plt.subplot(414)
    plt.title('Sampling population, high variance - rate')
    plt.imshow(high_var_samp_pop_monitor['r'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,.2)
    fname='firing_rate.%s'
    save_to_png(fig, os.path.join(data_dir,fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir,fname % 'eps'))
    plt.close(fig)

    fig=plt.figure()
    plt.subplot(411)
    plt.title('Probabilistic population, low variance - efficacy')
    plt.imshow(low_var_prob_pop_monitor['e'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,1)
    plt.subplot(412)
    plt.title('Probabilistic population, high variance - efficacy')
    plt.imshow(high_var_prob_pop_monitor['e'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,1)
    plt.subplot(413)
    plt.title('Sampling population, low variance - efficacy')
    plt.imshow(low_var_samp_pop_monitor['e'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,1)
    plt.subplot(414)
    plt.title('Sampling population, high variance - efficacy')
    plt.imshow(high_var_samp_pop_monitor['e'][:],aspect='auto')
    plt.xlabel('time')
    plt.ylabel('neuron')
    plt.colorbar()
    plt.clim(0,1)
    fname='efficacy.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)

    fig=plt.figure()
    plt.title('BOLD')
    plt.plot(low_var_prob_voxel_monitor['y'][0],label='prob,low var')
    plt.plot(high_var_prob_voxel_monitor['y'][0],label='prob,high var')
    plt.plot(low_var_samp_voxel_monitor['y'][0],label='samp,low var')
    plt.plot(high_var_samp_voxel_monitor['y'][0],label='samp,high var')
    plt.legend(loc='best')
    fname='bold.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)

    stim1_mid_time=stim1_start_time+(stim1_end_time-stim1_start_time)/2
    idx1=int(stim1_mid_time/defaultclock.dt)
    stim2_mid_time=stim2_start_time+(stim2_end_time-stim2_start_time)/2
    idx2=int(stim2_mid_time/defaultclock.dt)

    fig=plt.figure()
    plt.title('Probabilistic Population snapshot')
    plt.plot(low_var_prob_pop_monitor['r'][:,idx1],'r', label='low var, stim 1')
    plt.plot(low_var_prob_pop_monitor['r'][:,idx2],'r--', label='low var stim 2')
    plt.plot(high_var_prob_pop_monitor['r'][:,idx1],'b', label='high var, stim 1')
    plt.plot(high_var_prob_pop_monitor['r'][:,idx2],'b--', label='high var stim 2')
    plt.legend(loc='best')
    fname='prob_pop.firing_rate.snapshot.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)

    fig=plt.figure()
    plt.title('Sampling Population snapshot')
    plt.plot(low_var_samp_pop_monitor['r'][:,idx1],'r', label='low var, stim 1')
    plt.plot(low_var_samp_pop_monitor['r'][:,idx2],'r--', label='low var, stim 2')
    plt.plot(high_var_samp_pop_monitor['r'][:,idx1],'b', label='high var, stim 1')
    plt.plot(high_var_samp_pop_monitor['r'][:,idx2],'b--', label='high var, stim 2')
    plt.legend(loc='best')
    fname='samp_pop.firing_rate.snapshot.%s'
    save_to_png(fig, os.path.join(data_dir, fname % 'png'))
    save_to_eps(fig, os.path.join(data_dir, fname % 'eps'))
    plt.close(fig)
Exemplo n.º 30
0
def render_marginal_report(param_name, param_range, param_prior,
                           param_likelihood, param_posterior, file_prefix,
                           reports_dir, ylim):
    if len(param_range) > 1:
        param_step = param_range[1] - param_range[0]

        fig = plt.figure()
        param_prior[param_prior == 0] = 1e-7
        plt.bar(
            np.array(param_range) - .5 * param_step, param_prior, param_step)
        plt.xlabel(param_name)
        plt.ylabel('p(%s|M)' % param_name)
        plt.ylim([0, ylim])
        prior_furl = 'img/bayes_%s_marginal_prior_%s.png' % (file_prefix,
                                                             param_name)
        fname = os.path.join(reports_dir, prior_furl)
        save_to_png(fig, fname)
        save_to_eps(
            fig,
            os.path.join(
                reports_dir, 'img/bayes_%s_marginal_prior_%s.eps' %
                (file_prefix, param_name)))
        plt.close()

        fig = plt.figure()
        param_likelihood[param_likelihood == 0] = 1e-7
        plt.bar(
            np.array(param_range) - .5 * param_step, param_likelihood,
            param_step)
        plt.xlabel(param_name)
        plt.ylabel('p(WTA|%s,M)' % param_name)
        plt.ylim([0, ylim])
        likelihood_furl = 'img/bayes_%s_marginal_likelihood_%s.png' % (
            file_prefix, param_name)
        fname = os.path.join(reports_dir, likelihood_furl)
        save_to_png(fig, fname)
        save_to_eps(
            fig,
            os.path.join(
                reports_dir, 'img/bayes_%s_marginal_likelihood_%s.eps' %
                (file_prefix, param_name)))
        plt.close()

        fig = plt.figure()
        param_posterior[param_posterior == 0] = 1e-7
        plt.bar(
            np.array(param_range) - .5 * param_step, param_posterior,
            param_step)
        plt.xlabel(param_name)
        plt.ylabel('p(%s|WTA,M)' % param_name)
        plt.ylim([0, ylim])
        posterior_furl = 'img/bayes_%s_marginal_posterior_%s.png' % (
            file_prefix, param_name)
        fname = os.path.join(reports_dir, posterior_furl)
        save_to_png(fig, fname)
        save_to_eps(
            fig,
            os.path.join(
                reports_dir, 'img/bayes_%s_marginal_posterior_%s.eps' %
                (file_prefix, param_name)))
        plt.close()

        return prior_furl, likelihood_furl, posterior_furl
    return None, None, None