Esempio n. 1
0
def plot_size_tuning(arr, colors=None):
    usize = np.array((0, 5, 8, 13, 22, 36))
    ucontrast = np.array((0, 6, 12, 25, 50, 100))
    arr_sz = gen_size_tuning(arr)
    arr_sz = arr_sz / arr_sz.max(1).max(1)[:, np.newaxis, np.newaxis]
    lb, ub = ut.bootstrap(arr_sz, np.mean, pct=(2.5, 97.5))
    to_plot = arr_sz.mean(0)
    ut.plot_bootstrapped_errorbars_hillel(usize,
                                          arr_sz[:, :, 1::].transpose(
                                              (0, 2, 1)),
                                          colors=colors)
    plt.ylim(to_plot.min() - 0.1, to_plot.max() + 0.1)
    #     plt.title('%d%% contrast' % ucontrast[ic])
    plt.xlabel('size ($^o$)')
    #     plt.subplot(1,2,1)

    plt.tight_layout()
Esempio n. 2
0
def plot_size_tuning_by_contrast(arr):
    usize = np.array((0, 5, 8, 13, 22, 36))
    ucontrast = np.array((0, 6, 12, 25, 50, 100))
    arr_sz = gen_size_tuning(arr)
    arr_sz = arr_sz / arr_sz.max(1).max(1)[:, np.newaxis, np.newaxis]
    lb, ub = ut.bootstrap(arr_sz, np.mean, pct=(2.5, 97.5))
    to_plot = arr_sz.mean(0)
    for ic in range(1, 6):
        plt.subplot(1, 5, ic)
        ut.plot_bootstrapped_errorbars_hillel(usize,
                                              arr_sz[:, :, ic].transpose(
                                                  (0, 2, 1)),
                                              colors=['k', 'r'],
                                              markersize=5)
        #         plt.scatter((0,),to_plot[:,0,0].mean(0))
        #         plt.scatter((0,),to_plot[:,0,1].mean(0))
        plt.ylim(0.5 * to_plot.min(), 1.2 * to_plot.max())
        plt.title('%d%% contrast' % ucontrast[ic])
        plt.xlabel('size ($^o$)')
    plt.subplot(1, 5, 1)
    plt.ylabel('event rate / max event rate')
    plt.tight_layout()
Esempio n. 3
0
def plot_interp_size_tuning(ams=None,
                            data=None,
                            theta=None,
                            these_contrasts=[1, 3, 5],
                            ninterp=101,
                            usize=np.array((5, 8, 13, 22, 36, 60)),
                            ucontrast=np.array((0, 6, 12, 25, 50, 100)) / 100,
                            colors=None,
                            error_type='bs',
                            deriv=False,
                            deriv_axis=1,
                            sub=False,
                            two_n=False):
    usize_interp = np.linspace(0, usize[-1], ninterp)
    this_ncontrast = len(these_contrasts)
    this_usize = usize_interp
    this_ucontrast = ucontrast

    if ams is None:
        #assert(not data is None and not theta is None)
        assert (not data is None)
        ams = ayaz_model(data,
                         usize=usize,
                         ucontrast=ucontrast,
                         theta=theta,
                         sub=sub,
                         two_n=two_n)
    this_ucontrast = np.array([ams.ucontrast[i] for i in these_contrasts])
    this_theta = ams.theta
    fn = ams.fn

    usize0 = np.concatenate(((0, ), usize))
    this_data = sim_utils.gen_size_tuning(ams.data)

    if deriv:
        if deriv_axis == 1:
            this_data = sca.compute_slope_avg(usize0,
                                              this_data,
                                              axis=deriv_axis)
        elif deriv_axis == 2:
            this_data = sca.compute_slope_avg(ucontrast,
                                              this_data,
                                              axis=deriv_axis)
        this_modeled = np.zeros((ninterp, this_ncontrast))
        for icontrast in range(this_ncontrast):
            if deriv_axis == 1:
                srf = lambda d: ams.fn(np.array(
                    (this_ucontrast[icontrast], )), np.array((d, )))[0, 0]
                sslope = np.array([grad(srf)(ss) for ss in this_usize])
                this_modeled[:, icontrast] = sslope
            elif deriv_axis == 2:
                for isize, ss in enumerate(this_usize):
                    crf = lambda c: ams.fn(np.array((c, )), np.array(
                        (ss, )))[0, 0]
                    sslope = grad(crf)(this_ucontrast[icontrast])
                    this_modeled[isize, icontrast] = sslope
    else:
        this_modeled = ams.fn(this_ucontrast, this_usize)

    if True:
        if error_type == 'bs':
            ut.plot_bootstrapped_errorbars_hillel(
                usize0,
                this_data[:, :, these_contrasts].transpose((0, 2, 1)),
                linewidth=0,
                colors=colors)
        elif error_type == 'pct':
            ut.plot_pct_errorbars_hillel(usize0,
                                         this_data[:, :,
                                                   these_contrasts].transpose(
                                                       (0, 2, 1)),
                                         linewidth=0,
                                         colors=colors,
                                         pct=(16, 84))
        for icontrast in range(this_ncontrast):
            plt.plot(usize_interp,
                     this_modeled[:, icontrast],
                     c=colors[icontrast])
        #plt.xticks(cinds,(100*ucontrast).astype('int'))
    ut.erase_top_right()
    plt.xlabel('size ($^o$)')
    plt.ylabel('event rate/mean')
    if not deriv:
        plt.gca().set_ylim(bottom=0)
    plt.tight_layout()
Esempio n. 4
0
def plot_interp_contrast_tuning(ams=None,
                                data=None,
                                theta=None,
                                these_sizes=[0, 2, 4],
                                ninterp=101,
                                usize=np.array((5, 8, 13, 22, 36, 60)),
                                ucontrast=np.array(
                                    (0, 6, 12, 25, 50, 100)) / 100,
                                colors=None,
                                deriv=False,
                                deriv_axis=2):
    ucontrast_interp = np.linspace(0, 1, ninterp)
    this_nsize = len(these_sizes)
    this_ucontrast = ucontrast_interp

    if ams is None:
        #assert(not data is None and not theta is None)
        assert (not data is None)
        ams = ayaz_model(data, usize=usize, ucontrast=ucontrast, theta=theta)
    this_usize = np.array([ams.usize[i] for i in these_sizes])
    this_theta = ams.theta
    fn = ams.fn

    this_data = ams.data
    ind0 = 2
    cinds = np.concatenate(
        ((5 + np.log2(ucontrast_interp[ind0]), ), np.arange(1, 6)))
    if deriv:
        if deriv_axis == 1:
            this_data = sca.compute_slope_avg(usize,
                                              this_data,
                                              axis=deriv_axis)
        elif deriv_axis == 2:
            this_data = sca.compute_slope_avg(ucontrast,
                                              this_data,
                                              axis=deriv_axis)
        this_modeled = np.zeros((this_nsize, ninterp))
        for isize in range(this_nsize):
            if deriv_axis == 2:
                crf = lambda c: ams.fn(np.array(
                    (c, )), np.array((this_usize[isize], )))[0, 0]
                cslope = np.array([grad(crf)(cc) for cc in this_ucontrast])
                this_modeled[isize] = cslope
                #print(cslope)
            elif deriv_axis == 1:
                for icontrast, cc in enumerate(this_ucontrast):
                    srf = lambda d: ams.fn(np.array((cc, )), np.array(
                        (d, )))[0, 0]
                    sslope = grad(srf)(this_usize[isize])
                    this_modeled[isize, icontrast] = sslope
    else:
        #this_modeled = nub_utils.ayaz_like_theta(this_ucontrast,this_usize,this_theta,fn=fn)
        this_modeled = ams.fn(this_ucontrast, this_usize)
    ut.plot_bootstrapped_errorbars_hillel(cinds,
                                          this_data[:,
                                                    these_sizes, :].transpose(
                                                        (0, 1, 2)),
                                          linewidth=0,
                                          colors=colors)
    for isize in range(this_nsize):
        plt.plot(5 + np.log2(ucontrast_interp[ind0:]),
                 this_modeled[isize, ind0:],
                 c=colors[isize])
    plt.xticks(cinds, (100 * ucontrast).astype('int'))
    ut.erase_top_right()
    plt.xlabel('contrast (%)')
    plt.ylabel('event rate/mean')
    if not deriv:
        plt.gca().set_ylim(bottom=0)
    plt.tight_layout()