Пример #1
0
def btwnfigs(anim, day, ep, t0, t1, someplt1, label1, lims1, someplt2, label2, lims2, someplt3, label3, lims3, r, x, y, scxMin, scxMax, scyMin, scyMax):
    print "btwnfigs   %(ep)d  %(1)d %(2)d" % {"ep" : ep, "1" : t0, "2" : t1}
    fig = _plt.figure(figsize=(13, 10))
    fig.add_subplot(2, 2, 1)
    _plt.scatter(r[::10, x], r[::10, y], s=5, color="grey")
    _plt.scatter(r[t0:t1:2, x], r[t0:t1:2, y], s=9, color="black")
    _plt.plot(r[t0, x], r[t0, y], ms=40, color="blue", marker=".")
    _plt.plot(r[t1, x], r[t1, y], ms=40, color="red", marker=".")
    _plt.xlim(scxMin, scxMax)
    _plt.ylim(scyMin, scyMax)
    fig.add_subplot(2, 2, 2)

    _plt.plot(range(t0, t1), someplt1[t0:t1], color="black", lw=4)
    _plt.xlim(t0, t1)
    _plt.xticks(_N.arange(t0, t1, (t1-t0)/5))
    _plt.ylabel(label1)
    _plt.ylim(lims1[0], lims1[1])
    _plt.grid()
    fig.add_subplot(2, 2, 3)
    _plt.plot(range(t0, t1), someplt2[t0:t1], color="black", lw=4)
    _plt.xlim(t0, t1)
    _plt.ylim(lims2[0], lims2[1])
    _plt.ylabel(label2)
    _plt.xticks(_N.arange(t0, t1, (t1-t0)/5))
    _plt.grid()
    fig.add_subplot(2, 2, 4)
    _plt.plot(range(t0, t1), someplt3[t0:t1], color="black", lw=4)
    _plt.xlim(t0, t1)
    _plt.ylim(lims3[0], lims3[1])
    _plt.ylabel(label3)
    _plt.xticks(_N.arange(t0, t1, (t1-t0)/5))
    _plt.grid()
    

    fig.subplots_adjust(left=0.1, bottom=0.1, top=0.95, right=0.99)

    sday = ("0%d" % day) if (day < 10) else ("%d" % day)
    #print _edd.datFN("btwn_%(dy)d%(ep)d_%(1)d_%(2)d" % {"dy" : day, "ep" : (ep+1), "1" : t0, "2" : t1}, create=True)
    #_edd.datFN("lindist.dat", dir="linearize/%(an)s%(dy)s0%(ep)d" % {"dy" : sday, "ep" : (ep+1), "an" : anim2}, create=True)
    _plt.savefig(_edd.datFN("btwn_%(dy)d%(ep)d_%(1)d_%(2)d" % {"dy" : day, "ep" : (ep+1), "1" : t0, "2" : t1}, dir="linearize/%(an)s%(dy)s0%(ep)d" % {"dy" : sday, "ep" : (ep+1), "an" : anim2}, create=True))
    #_plt.savefig("btwn_%(an)s%(dy)d%(ep)d_%(1)d_%(2)d" % {"dy" : day, "ep" : (ep+1), "1" : t0, "2" : t1, "an" : anim})
    _plt.close()
Пример #2
0
def cmpGTtoFIT(basefn, datfn, itvfn, M, epc, xticks=None, yticks=None):
    dmp = open(_ed.resFN("posteriors.dump", dir=basefn), "rb")
    gt  = _N.loadtxt(_ed.datFN("%s_prms.dat" % datfn))
    _intvs  = _N.loadtxt(_ed.datFN("%s.dat" % itvfn))
    intvs = _N.array(gt.shape[0] * _intvs, dtype=_N.int)
    pckl = pickle.load(dmp)
    dmp.close()

    N     = 300
    x     = _N.linspace(0, 3, N)


    smpls = pckl["cp%d" % epc]
    mds   = pckl["md"]
    l0s   = smpls[0]   #  GIBBS ITER  x  M
    fs    = smpls[1]
    q2s   = smpls[2]

    frm   = 200
    Nsmp  = l0s.shape[0] - frm

    SMPS  = 1000

    rfsmps= _N.empty((SMPS, N, M))  #  samples

    rs    = _N.random.rand(SMPS, 3, M)
    for m in xrange(M):
        for ss in xrange(SMPS):
            i_l0 = int((Nsmp-frm)*rs[ss, 0, m])  #  one of the iters
            i_f  = int((Nsmp-frm)*rs[ss, 1, m])
            i_q2 = int((Nsmp-frm)*rs[ss, 2, m])
            l0   = l0s[frm+i_l0, m]
            f    = fs[frm+i_f, m]
            q2   = q2s[frm+i_q2, m]

            rfsmps[ss, :, m] = (l0 / _N.sqrt(2*_N.pi*q2)) * _N.exp(-0.5*(x - f)*(x-f)/q2)

            #_plt.plot(x, rfsmps[ss], color="black")

    Arfsmps = _N.sum(rfsmps, axis=2)
    srtd = _N.sort(Arfsmps, axis=0)

    fig  = _plt.figure(figsize=(5, 4))
    ax   = fig.add_subplot(1, 1, 1)
    #_plt.fill_between(x, srtd[50, :], srtd[950, :], alpha=0.3)
    _plt.fill_between(x, srtd[50, :], srtd[950, :], color="#CCCCFF")

    fr_s = _N.zeros(N)
    fr_e = _N.zeros(N)
    Mgt  = gt.shape[1]/3
    print Mgt
    for m in xrange(Mgt):
        l0_s = gt[intvs[epc], 2+3*m]
        l0_e = gt[intvs[epc+1]-1, 2+3*m]
        f_s = gt[intvs[epc], 3*m]
        f_e = gt[intvs[epc+1]-1, 3*m]
        q2_s = gt[intvs[epc], 1+3*m]
        q2_e = gt[intvs[epc+1]-1, 1+3*m]

        fr_s += (l0_s / _N.sqrt(2*_N.pi*q2_s)) * _N.exp(-0.5*(x - f_s)*(x-f_s)/q2_s)
        fr_e += (l0_e / _N.sqrt(2*_N.pi*q2_e)) * _N.exp(-0.5*(x - f_e)*(x-f_e)/q2_e)
    _plt.plot(x, 0.5*(fr_s+fr_e), lw=3, color="black")

    fr_m = _N.zeros(N)
    for m in xrange(M):
        l0_m = mds[epc, 3*m]
        f_m = mds[epc, 1+3*m]
        q2_m = mds[epc, 2+3*m]
        fr_m += (l0_m / _N.sqrt(2*_N.pi*q2_m)) * _N.exp(-0.5*(x - f_m)*(x-f_m)/q2_m)
    _plt.plot(x, fr_m, lw=3, color="blue")

    mF.setTicksAndLims(xlabel="position", ylabel="Hz", xticks=xticks, yticks=yticks, tickFS=22, labelFS=24)

    mF.arbitaryAxes(ax, axesVis=[True, True, False, False])
    fig.subplots_adjust(left=0.2, bottom=0.2, right=0.95, top=0.95)

    _plt.savefig(_ed.resFN("cmpGT2FIT%d.eps" % epc, dir=basefn))
Пример #3
0
        for epc in range(4, 5):
            ep=epc+1;

            _pts=mLp["linpos"][0,ex][0,ep] 
            if (_pts.shape[1] > 0):     #  might be empty epoch
                pts = _pts["statematrix"][0][0]["time"][0,0].T[0]
                a = mLp["linpos"][0,ex][0,ep]["statematrix"][0,0]["segmentIndex"]
                r = mRp["rawpos"][0,ex][0,ep]["data"][0,0]

                fillin_unobsvd(r)

                scxMin, scxMax, scyMin, scyMax = get_boundaries(r)

            sday = ("0%d" % day) if (day < 10) else ("%d" % day)

            fn = _edd.datFN("cp_lr.dat", dir="linearize/%(an)s%(dy)s0%(ep)d" % {"dy" : sday, "ep" : (ep+1), "an" : anim2})
            cp_lr = _N.loadtxt(fn, dtype=_N.int)
            fn = _edd.datFN("cp_inout.dat", dir="linearize/%(an)s%(dy)s0%(ep)d" % {"dy" : sday, "ep" : (ep+1), "an" : anim2})
            cp_inout = _N.loadtxt(fn, dtype=_N.int)

            lr, inout = thaw_LR_inout(27901, cp_lr, cp_inout)

            fn = _edd.datFN("lindist.dat", dir="linearize/%(an)s%(dy)s0%(ep)d" % {"dy" : sday, "ep" : (ep+1), "an" : anim2})
            lindist = _N.loadtxt(fn)

            N  = len(lindist)
            lin_lr_inout = _N.empty(N)
            build_lin_lr_inout(N, lin_lr_inout, lindist, lr, inout, gkRWD)

            t0 = 0
            winsz = 1000
Пример #4
0
def done():
    """
    come here after 6 landmarks chosen
    """

    global r, seg_ts, segs, Nsgs, inout, a_inout, lindist, lin_lr, lin_inout, lin_lr_inout, lr, raw_lindist
    global scxMin, scxMax, scyMin, scyMax
    global an, day, ep

    hdir = _N.empty(2)
    vdir = _N.empty(2)
    linp = _N.empty(2)
    """
    L5       L0       L3
    ||       ||       ||
    ||       ||       ||
    5        1        3
    ||       ||       ||
    ||       ||       ||
    L4===4===L1===2===L2
    """
    scxMin, scxMax, scyMin, scyMax = get_boundaries(r)
    segs_from_landmarks(segs, landmarks, length)
    e = inout_dir(segs, Nsgs)
    a_s, b_s, c_s = slopes_of_segs(segs)

    _plt.plot([segs[0, 0, 0], segs[0, 1, 0]], [segs[0, 0, 1], segs[0, 1, 1]],
              lw=3,
              color="black")
    _plt.plot([segs[1, 0, 0], segs[1, 1, 0]], [segs[1, 0, 1], segs[1, 1, 1]],
              lw=3,
              color="black")
    _plt.plot([segs[2, 0, 0], segs[2, 1, 0]], [segs[2, 0, 1], segs[2, 1, 1]],
              lw=3,
              color="black")
    _plt.plot([segs[3, 0, 0], segs[3, 1, 0]], [segs[3, 0, 1], segs[3, 1, 1]],
              lw=3,
              color="black")
    _plt.plot([segs[4, 0, 0], segs[4, 1, 0]], [segs[4, 0, 1], segs[4, 1, 1]],
              lw=3,
              color="black")

    segsr = segs.reshape((10, 2))

    clrs = ["blue", "orange", "red", "green", "yellow", "black", "brown"]
    fillin_unobsvd(r)

    N = r.shape[0]
    seg_ts = _N.empty(N, dtype=_N.int)
    lindist = _N.empty(N)
    lin_lr = _N.empty(N)
    lin_inout = _N.empty(N)
    lin_lr_inout = _N.empty(N)
    lr = _N.ones(N, dtype=_N.int) * -3

    inout = _N.empty(N, dtype=_N.int)
    a_inout = _N.empty(N)
    gk = gauKer(30)
    gk /= _N.sum(gk)
    fx = _N.convolve(0.5 * (r[:, 1] + r[:, 3]), gk, mode="same")
    fy = _N.convolve(0.5 * (r[:, 2] + r[:, 4]), gk, mode="same")
    xp = fx
    yp = fy
    xpyp = _N.empty((N, 2))
    xpyp[:, 0] = xp
    xpyp[:, 1] = yp

    _xpyp = _N.repeat(xpyp, Nsgs * 2, axis=0)
    rxpyp = _xpyp.reshape((N, Nsgs * 2, 2))

    dv = segsr - rxpyp
    dists = _N.sum(dv * dv, axis=2)  # closest point on maze from field points
    rdists = dists.reshape((N, Nsgs, 2))
    print rdists.shape

    online = _N.empty(Nsgs, dtype=bool)
    mins = _N.empty(Nsgs)

    for n in xrange(N):
        x0 = xpyp[n, 0]
        y0 = xpyp[n, 1]
        #  xcs, ycs: pt on all line segs closest to x0, y0 (may b byond endpts)
        xcs = (b_s *
               (b_s * x0 - a_s * y0) - a_s * c_s) / (a_s * a_s + b_s * b_s)
        ycs = (-a_s *
               (b_s * x0 - a_s * y0) - b_s * c_s) / (a_s * a_s + b_s * b_s)

        find_clsest(n, x0, y0, segs, rdists, seg_ts, Nsgs, online, offset, xcs,
                    ycs, mins, linp)

    # fig = _plt.figure()
    # _plt.plot(seg_ts)
    # clean_seg_ts(seg_ts)

    # _plt.plot(seg_ts)

    raw_lindist = _N.zeros(N)
    lindist_x0y0(N, xpyp, segs, rdists, seg_ts, Nsgs, online, offset, a_s, b_s,
                 c_s, mins, linp, raw_lindist)

    smooth_lindist(raw_lindist, lindist)

    # fig = _plt.figure(figsize=(10, 4))
    # _plt.plot(lindist)
    # gk = gauKer(8)   #  don't want to make this too large.  if we just pass  through the choice point, we can miss it.
    # gk /= _N.sum(gk)
    # flindist = _N.convolve(lindist, gk, mode="same")
    # lindist  = flindist

    # rm_lindist_jumps(N, lindist, seg_ts)
    fig = _plt.figure(figsize=(10, 4))
    _plt.plot(lindist)

    spd_thr = 0.35
    a_inout_x0y0(N, a_inout, inout, r, seg_ts, spd_thr, e)
    #_plt.plot([x0, x0], [y0, y0], ms=10, marker=".", color=clr)

    make_lin_inout(N, lindist, inout, lin_inout)
    make_lin_lr(N, lr, lindist, seg_ts, r)
    build_lin_lr_inout(N, lin_lr_inout, lindist, lr, inout, gkRWD)

    #  inout
    cp_lr, cp_inout = cpify_LR_inout(lr, inout)

    sday = ("0%d" % day) if (day < 10) else ("%d" % day)
    fn = _edd.datFN("lindist.dat",
                    dir="linearize/%(an)s%(dy)s0%(ep)d" % {
                        "dy": sday,
                        "ep": (ep + 1),
                        "an": anim2
                    },
                    create=True)
    _N.savetxt(fn, lindist, fmt="%.3f")
    fn = _edd.datFN("cp_lr.dat",
                    dir="linearize/%(an)s%(dy)s0%(ep)d" % {
                        "dy": sday,
                        "ep": (ep + 1),
                        "an": anim2
                    })
    _U.savetxtWCom(
        fn,
        cp_lr,
        fmt="%d %d",
        com=
        ("# N=%d.  1st column time, 2nd column  - inout value from this time until time in next row"
         % N))
    fn = _edd.datFN("cp_inout.dat",
                    dir="linearize/%(an)s%(dy)s0%(ep)d" % {
                        "dy": sday,
                        "ep": (ep + 1),
                        "an": anim2
                    })
    _U.savetxtWCom(
        fn,
        cp_inout,
        fmt="%d %d",
        com=
        ("# N=%d.  1st column time, 2nd column  - inout value from this time until time in next row"
         % N))
    fn = _edd.datFN("lin_lr_inout.dat",
                    dir="linearize/%(an)s%(dy)s0%(ep)d" % {
                        "dy": sday,
                        "ep": (ep + 1),
                        "an": anim2
                    })
    _N.savetxt(fn, lin_lr_inout, fmt="%.3f")
    """
    """
    t0 = 0
    winsz = 1000
    t1 = 0
    iw = -1
    while t1 < N:
        iw += 1
        t0 = iw * winsz
        t1 = (iw + 1) * winsz if (iw + 1) * winsz < N else N - 1
        #btwnfigs(anim2, day, ep, t0, t1, inout, [-1.1, 1.1], seg_ts+1, [0.9, 5.1], r, 1, 2, scxMin, scxMax, scyMin, scyMax)
        btwnfigs(anim2, day, ep, t0, t1, inout, "INOUT", [-1.1, 1.1], lr, "LR",
                 [-1.1, 1.1], lin_lr_inout, "lin_lr_inout", [-6.1, 6.1], r, 1,
                 2, scxMin, scxMax, scyMin, scyMax)