示例#1
1
def svmPlotExtrema():
    from matustools.matusplotlib import plotGifGrid
    from Pixel import initPath
    plt.close()
    out=[[],[],[],[]]
    for nf in [[0,''],[1,''],[1,'3'],[1,'2']]:
        dat=svmPlotExtrRep(nf[0],suf=nf[1],plot=True)
        for vp in range(4):
            out[vp].extend([dat[vp][1],dat[vp][5]])
    path,inpath,figpath=initPath(1,0)
    plotGifGrid(out,fn=figpath+'svmExtrema'+FMT,bcgclr=0.5,F=34,P=32,
                duration=0.2,plottime=True,snapshot=True)
示例#2
0
def svmComparison():
    from Pixel import initPath
    figure(size=3,aspect=0.35)
    svm=svmPlotExtrRep(0,plot=False)
    for vp in range(1,5):
        est=np.zeros((2,3))
        ax=subplot(1,4,vp)
        for ev in [0,1]:
            path,inpath,figpath=initPath(vp,ev)
            coeff=np.load(inpath+'X/coeff.npy')
            pc=_getPC(coeff,0)
            if pc.mean()>=0.4: pc=1-pc
            t=np.linspace(-0.4,0.4,pc.shape[0])
            p=np.linspace(-5,5,pc.shape[1])
            D= pc.T[:,31:33,:].mean(1)
            D/=D.sum();
            # below we set the initial guess 
            x0=np.array((0,-12,0.1))
            xopt=fmin(func=_fun,x0=x0,args=(D,t,p,False))
            est[ev,:]=xopt
            plt.plot(xopt[0]-xopt[1]*t,t,['g','m'][ev],lw=1,alpha=1)

        #plt.plot(est[:,0].mean()-est[:,1].mean()*t,t,'r',lw=1,alpha=0.4)
        dat=svm[vp-1][1][15:17,:,:].mean(0)
        t=np.linspace(-0.4,0.4,dat.shape[1])
        p=np.linspace(-5,5,dat.shape[0])
        print dat.shape
        plt.xlim([p[0],p[-1]]);plt.ylim([t[0],t[-1]]);
        plt.pcolor(p,t,dat.T,cmap='gray');
        ax.set_axisbelow(False);plt.grid(True);
        ax.set_yticks([-0.4,-0.2,0,0.2,0.4])
        if vp>1: ax.set_yticklabels([])
        plt.text(-3.9,0.21,'S'+str(vp),color='w',fontsize=16)
    leg=plt.legend(['ES','CS1'],loc=4,frameon=True)
    box=leg.get_frame()
    box.set_linewidth(0.)
    box.set_facecolor([0.9]*3)
    plt.subplot(1,4,1);plt.text(8,-0.57,FIG[2][1][0],fontsize=8)
    plt.ylabel('Time to Saccade in Sec.')
    plt.savefig(figpath+'svmComparison',dpi=DPI,bbox_inches='tight')
示例#3
0
def svmPlotExtrRep(event=0,plot=True,suf=''):
    from Pixel import initPath
    if plot: plt.close()
    P=32;F=34
    dat=[]
    for vp in range(1,5):
        path,inpath,figpath=initPath(vp,event)
        fn= inpath+'svm%s/hc/hcWorker'%suf
        dat.append([])
        for g in range(2):
            for k in range(4):
                try:temp=np.load(fn+'%d.npy'%(k*2+g))
                except IOError:
                    print 'File missing: ',vp,event,suf
                    temp=np.zeros(P*P*F,dtype=np.bool8)
                temp=np.reshape(temp,[P,P,F])
                dat[-1].append(np.bool8(g-1**g *temp))
    lbl=[]
    for i in range(4):lbl.append([FIG[7][0]+str(i+1),20,18+i*40,FIG[7][1]])
    lbl.append([FIG[7][2],20,-10,70]);lbl.append([FIG[7][3],20,-10,245])
    if plot: plotGifGrid(dat,fn=figpath+'svm%sExtremaE%d'%(suf,event)+FMT,
                         F=34,P=32,text=lbl,bcgclr=0.5)
    return dat