Пример #1
0
def kernelplot_Mod(d, results, infodict, ax1, ax2, ax3, legend='lower right'):
    """Plot historykernels"""
    M = results['model_w_hist']
    bootstrap = results['bootstrap']

    C = statistics.Kernel_and_Slope_Collector(d.h, d.hf0, range(1, d.hf0))
    K = C(M)
    print 'K', K
    print d.hf0
    print 'd.h.shape[0]', d.h.shape[0]

    print 'adding modulation kernels'
    hr = K[:d.h.shape[0]]
    hz = K[d.h.shape[0]:2 * d.h.shape[0]]
    hr_pupil = K[2 * d.h.shape[0]:3 * d.h.shape[0]]
    hz_pupil = K[3 * d.h.shape[0]:-2]
    hr_pupil *= K[-2]
    hz_pupil *= K[-2]

    if bootstrap is None:
        kernellen = (bootstrap.shape[1] - 2) / 2
        print kernellen
        al = bootstrap[:, -2]
        al.shape = (-1, 1)
        bootstrap[:, :-2] *= al  # Like that?
        print K[-2], pl.prctile(bootstrap[:, -2]), pl.mean(bootstrap[:, -2])

        hci = statistics.history_kernel_ci(bootstrap[:, kernellen:-2],
                                           bootstrap[:, :kernellen], hz, hr)
    else:
        hci = None

    kl = graphics.history_kernels(hz,
                                  hr,
                                  hci,
                                  ax1,
                                  "left/right",
                                  ground_truth=d.ground_truth)
    kl += graphics.history_kernels(hz,
                                   hr,
                                   hci,
                                   ax2,
                                   "correct/incorrect",
                                   ground_truth=d.ground_truth)

    labely, labelh = same_y(ax1, ax2)

    graphics.label_axes(title="(D) stimulus and response kernels",
                        xlabel="lag",
                        ylabel="equivalent stimulus strength",
                        legend=legend,
                        ax=ax1)
    graphics.label_axes(title="(E) correct and incorrect kernels",
                        xlabel="lag",
                        ylabel="equivalent stimulus strength",
                        legend=legend,
                        ax=ax2)
    # pl.setp ( (ax1,ax2), ylim=(-6,6) )

    return kl
Пример #2
0
def permutationplot(d, results, infodict, ax, noaic=False):
    """permutation test"""
    l_obs = results['model_w_hist'].loglikelihood
    Caic = results['model_nohist'].loglikelihood + len(
        results['model_w_hist'].w) - len(results['model_nohist'].w)
    out = [l_obs]
    print "l_obs=", l_obs
    print "Caic= ", Caic
    if not results['permutation_wh'] is None:
        hist, C95 = statistics.historytest(results['permutation_wh'][:, 0])
        print "C95=  ", C95
        out.append(C95)
        out.append(Caic)
        out.append(np.mean(results['permutation_wh'][:, 0] < l_obs))
    else:
        hist = None
        C95 = None
        out.append(None)
        out.append(Caic)
        out.append(None)
    if noaic:
        Caic = None
    graphics.montecarlo_test(l_obs, hist, C95, Caic, ax, "likelihood")
    graphics.label_axes(title="(C) Permutation test",
                        xlabel="log-likelihood",
                        ax=ax)
    return out
Пример #3
0
def kernelplot(d, results, infodict, ax1, ax2, legend='lower right'):
    """Plot historykernels"""
    M = results['model_w_hist']
    bootstrap = results['bootstrap']

    # hr = d.gethistorykernel ( M.w[d.hf0:d.hf0+d.hlen], al )
    # hz = d.gethistorykernel ( M.w[d.hf0+d.hlen:],      al )
    C = statistics.Kernel_and_Slope_Collector(d.h, d.hf0, range(1, d.hf0))
    print d.hf0
    K = C(M)
    hr = K[:d.h.shape[0]]
    hz = K[d.h.shape[0]:-2]
    hz *= K[-2]
    hr *= K[-2]
    print "h_r[1]", hr[0]
    print "h_z[1]", hz[0]

    if not bootstrap is None:
        kernellen = (bootstrap.shape[1] - 2) / 2
        print kernellen
        al = bootstrap[:, -2]
        al.shape = (-1, 1)
        bootstrap[:, :-2] *= al  # Like that?
        print K[-2], pl.prctile(bootstrap[:, -2]), pl.mean(bootstrap[:, -2])

        hci = statistics.history_kernel_ci(bootstrap[:, kernellen:-2],
                                           bootstrap[:, :kernellen], hz, hr)
    else:
        hci = None

    kl = graphics.history_kernels(hz,
                                  hr,
                                  hci,
                                  ax1,
                                  "left/right",
                                  ground_truth=d.ground_truth)
    kl += graphics.history_kernels(hz,
                                   hr,
                                   hci,
                                   ax2,
                                   "correct/incorrect",
                                   ground_truth=d.ground_truth)

    labely, labelh = same_y(ax1, ax2)

    graphics.label_axes(title="(D) stimulus and response kernels",
                        xlabel="lag",
                        ylabel="equivalent stimulus strength",
                        legend=legend,
                        ax=ax1)
    graphics.label_axes(title="(E) correct and incorrect kernels",
                        xlabel="lag",
                        ylabel="equivalent stimulus strength",
                        legend=legend,
                        ax=ax2)
    # pl.setp ( (ax1,ax2), ylim=(-6,6) )

    return kl
Пример #4
0
def pmfplot(d, results, infodict, ax, errors=True):
    """Generate the pmf plot"""
    for i, c in enumerate(infodict['conditions']):
        c = int(c)
        d_ = d.getsummary(c)
        x = pl.mgrid[infodict['xmin']:infodict['xmax']:100j]
        if len(d.th_features) > 0:
            # d_[:,0] = u_v ( d_[:,0], results['model_w_hist'].nu )
            # x = u_v ( x, results['model_w_hist'].nu )
            d_[:, 0] = u_v(d_[:, 0], results['model_nohist'].nu)
            x = u_v(x, results['model_nohist'].nu)

        if errors:
            graphics.plot_data_summary(d_, ax, infodict['colors'][i],
                                       infodict['labels'][i])
        else:
            # AEU: change the marker to make datapoints small. What goes wrong in the plot here?
            ax.plot(d_[:, 0],
                    d_[:, 1] / d_[:, 2],
                    '.',
                    color=infodict['colors'][i],
                    label=infodict['labels'][i])

        # wfit  = results['model_w_hist'].w[infodict['indices'][c]]
        wfit = results['model_nohist'].w[infodict['indices'][i]]
        w0fit = results['model_w_hist'].w0[infodict['indices'][i]]
        pfit = results['model_w_hist'].pi
        p0fit = results['model_nohist'].pi

        if not d.ground_truth is None:
            wgfit = d.ground_truth['w'][infodict['indices'][i]]
            pgfit = d.ground_truth['pi']
            gt = graphics.plot_pmf(pgfit, wgfit, x, ax,
                                   (np.array([255, 240, 240], 'd') / 255 +
                                    infodict['colors'][i]) / 2.)
            pl.setp(gt, linestyle='--')

        # graphics.plot_pmf ( pfit, w0fit, x, ax, [.9,.9,.9], alpha=0.1 )
        graphics.plot_pmf(p0fit, wfit, x, ax, infodict['colors'][i])
    graphics.label_axes(title="(A) psychometric function",
                        xlabel=r"transduced stimulus $u_\nu(s\tilde{z})$",
                        ylabel=r"probability for $r=1$",
                        nxticks=5,
                        ax=ax)
Пример #5
0
def slopeplot(d, results, infodict, ax):
    """slope results of the permutation test"""

    ax = graphics.prepare_axes(ax, haveon=('bottom', ))

    h = np.histogram(results['permutation_wh'][:, 1])
    graphics.montecarlo_test(results['model_w_hist'].w[1],
                             h,
                             pl.prctile(results['permutation_wh'][:, 1], 95),
                             ax=ax,
                             labeling='slope')
    # ax.bar ( b[:-1], h, pl.diff(b), edgecolor=graphics.histogram_color, facecolor=graphics.histogram_color )
    # yrange = ax.get_ylim ()
    # ax.axvline ( results['model_w_hist'].w[1], ymin=yrange[0], ymax=yrange[1] )
    # ax.set_ylim ( yrange )
    # # ax.set_xlim ( .3,3 )
    # # ax.set_xticks ( [.5,1,1.5,2,2.5,3] )

    graphics.label_axes(title="(F) slope effects", xlabel=r"slope", ax=ax)
Пример #6
0
def nonlinearityplot(d, results, infodict, ax):
    """Plot with the nonlinearity"""
    xmin, xmax = infodict['xmin'], infodict['xmax']
    M = results['model_w_hist']
    for c in infodict['conditions']:
        d_ = d.getsummary(c)

        graphics.plot_nonlinearity_summary(d_,
                                           M.w,
                                           M.pi,
                                           ax,
                                           color=infodict['colors'][c],
                                           label=infodict['labels'][c])
    graphics.plot_nonlinearity(M.nu, np.mgrid[xmin:xmax:100j], ax, 'k')
    if not d.ground_truth is None:
        nl = graphics.plot_nonlinearity(d.ground_truth['nu'],
                                        np.mgrid[xmin:xmax:100j], ax,
                                        np.array([255, 230, 230], 'd') / 255)
        pl.setp(nl, linestyle='--')
    graphics.label_axes(title="(B) nonlinearity",
                        xlabel=r"raw stimulus $s\tilde{z}$",
                        ylabel=r"transduced stimulus $u_\nu(s\tilde{z})$",
                        nxticks=5,
                        ax=ax)