Example #1
0
def showTrajectory(dec, t0, t1, ep, setname, dir):
    fig = _plt.figure(figsize=(14, 7))
    ax  = fig.add_subplot(1, 1, 1)
    _plt.imshow(dec.pX_Nm[t0:t1].T, aspect=(0.5*(t1-t0)/50.), cmap=_plt.get_cmap("Reds"))
    _plt.plot(_N.linspace(t0-t0, t1-t0, t1-t0), (dec.xA+dec.pos[t0:t1])/dec.dxp, color="grey", lw=3, ls="--")
    #_plt.plot(_N.linspace(float(t0)/1000., float(t1)/1000., t1-t0), (dec.xA+dec.pos[t0:t1])/dec.dxp, color="red", lw=2)
    #print (float(t0)/1000)
    #print (float(t1)/1000)
    _plt.xlim(0, t1-t0)
    _plt.ylim(-(dec.nTets*4), 50)
    #_plt.xticks(_N.arange(0, t1-t0, 2000), _N.arange(t0, t1, 2000, dtype=_N.float)/1000)
    dt = int((((int(t1/1000.)*1000) - (int(t0/1000.)*1000))/4.)/1000.)*1000

    stT0 = t0 - int(t0/1000.)*1000
    enT1 = t1 - int(t1/1000.)*1000
    #_plt.xticks(_N.arange(0, t1-t0, dt), _N.arange(t0, t1, dt, dtype=_N.float)/1000)
    _plt.xticks(_N.arange(stT0, t1-t0, dt), _N.arange(int(t0/1000.)*1000, int(t1/1000.)*1000, dt, dtype=_N.int)/1000)
    #_plt.locator_params(nbins=6, axis="x")
    _plt.yticks(_N.linspace(0, 50, 5), [-6, -3, 0, 3, 6])
    mF.arbitaryAxes(ax, axesVis=[False, False, False, False], x_tick_positions="bottom", y_tick_positions="left")
    mF.setLabelTicks(_plt, xlabel="Time (sec.)", ylabel="Position", xtickFntSz=30, ytickFntSz=30, xlabFntSz=32, ylabFntSz=32)

    x = []
    y = []
    for nt in xrange(dec.nTets):
        x.append([])
        y.append([])

    for t in xrange(t0, t1):
        for nt in xrange(dec.nTets):
            if dec.marks[t, nt] is not None:
                x[nt].append(t-t0)
                y[nt].append(-1.5 - 3*nt)

    for nt in xrange(dec.nTets):
        _plt.plot(x[nt], y[nt], ls="", marker="|", ms=15, color="black")

    fig.subplots_adjust(bottom=0.15, left=0.15)
    _plt.savefig(resFN("decode_%(uts)s_%(mth)s_win=%(e)d.eps" % {"e" : (ep/2), "mth" : dec.decmth, "uts" : dec.utets_str, "dir" : dir}, dir=setname, create=True))
    _plt.close()
Example #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))
Example #3
0
def showTrajectory(dec, t0, t1, ep, setname, dir):
    fig = _plt.figure(figsize=(14, 7))
    ax = fig.add_subplot(1, 1, 1)
    _plt.imshow(dec.pX_Nm[t0:t1].T,
                aspect=(0.5 * (t1 - t0) / 50.),
                cmap=_plt.get_cmap("Reds"))
    _plt.plot(_N.linspace(t0 - t0, t1 - t0, t1 - t0),
              (dec.xA + dec.pos[t0:t1]) / dec.dxp,
              color="grey",
              lw=3,
              ls="--")
    #_plt.plot(_N.linspace(float(t0)/1000., float(t1)/1000., t1-t0), (dec.xA+dec.pos[t0:t1])/dec.dxp, color="red", lw=2)
    #print (float(t0)/1000)
    #print (float(t1)/1000)
    _plt.xlim(0, t1 - t0)
    _plt.ylim(-(dec.nTets * 4), 50)
    #_plt.xticks(_N.arange(0, t1-t0, 2000), _N.arange(t0, t1, 2000, dtype=_N.float)/1000)
    dt = int((((int(t1 / 1000.) * 1000) -
               (int(t0 / 1000.) * 1000)) / 4.) / 1000.) * 1000

    stT0 = t0 - int(t0 / 1000.) * 1000
    enT1 = t1 - int(t1 / 1000.) * 1000
    #_plt.xticks(_N.arange(0, t1-t0, dt), _N.arange(t0, t1, dt, dtype=_N.float)/1000)
    _plt.xticks(
        _N.arange(stT0, t1 - t0, dt),
        _N.arange(
            int(t0 / 1000.) * 1000, int(t1 / 1000.) * 1000, dt, dtype=_N.int) /
        1000)
    #_plt.locator_params(nbins=6, axis="x")
    _plt.yticks(_N.linspace(0, 50, 5), [-6, -3, 0, 3, 6])
    mF.arbitaryAxes(ax,
                    axesVis=[False, False, False, False],
                    x_tick_positions="bottom",
                    y_tick_positions="left")
    mF.setLabelTicks(_plt,
                     xlabel="Time (sec.)",
                     ylabel="Position",
                     xtickFntSz=30,
                     ytickFntSz=30,
                     xlabFntSz=32,
                     ylabFntSz=32)

    x = []
    y = []
    for nt in range(dec.nTets):
        x.append([])
        y.append([])

    for t in range(t0, t1):
        for nt in range(dec.nTets):
            if dec.marks[t, nt] is not None:
                x[nt].append(t - t0)
                y[nt].append(-1.5 - 3 * nt)

    for nt in range(dec.nTets):
        _plt.plot(x[nt], y[nt], ls="", marker="|", ms=15, color="black")

    fig.subplots_adjust(bottom=0.15, left=0.15)
    _plt.savefig(
        resFN("decode_%(uts)s_%(mth)s_win=%(e)d.eps" % {
            "e": (ep / 2),
            "mth": dec.decmth,
            "uts": dec.utets_str,
            "dir": dir
        },
              dir=setname,
              create=True))
    _plt.close()