def _plotResultsF(Snaps, mdb, outdir): Xorg = Snaps['Xorg'] mn = np.nanmin(Xorg.flatten()) mx = np.nanmax(Xorg.flatten()) tl.plt.clf() tl.plt.subplot(511) tl.plt.plot(Xorg, ) # 'black') tl.plt.xlim([0, len(Xorg)]) tl.plt.ylim([mn, mx]) tl.plt.ylabel('Original') tl.plt.xticks([]) tl.plt.subplot(512) tl.plt.plot(Xorg, 'lightgrey') tl.resetCol() if (SMTH): tl.plt.plot(tl.smoothWMAo(Snaps['Vf_full'], int(Snaps['pstep']))) else: tl.plt.plot(Snaps['Vf_full']) tl.plt.xlim([0, len(Xorg)]) tl.plt.ylim([mn, mx]) tl.plt.ylabel('Forecast') tl.plt.xticks([]) tl.plt.subplot(513) tl.plt.plot(Snaps['Es_full'], 'lightgrey') tl.plt.plot(Snaps['Ef_full'], 'yellowgreen') tl.plt.xlim([0, len(Xorg)]) tl.plt.ylabel('RMSE (cast)') tl.plt.xticks([]) emx = np.nanmax(Snaps['Es_full'].flatten()) tl.plt.ylim([0, emx]) tl.plt.subplot(514) #tl.plt.plot(Snaps['Rf_full']) tl.plt.imshow(_createImap(mdb, Snaps['Rf_full']), cmap='gray', interpolation='nearest', aspect='auto') tl.plt.xlim([0, len(Xorg)]) #; tl.plt.yticks([]) tl.plt.yticks(range(0, mdb.get_c()), range(1, mdb.get_c() + 1)) tl.plt.ylabel('R-ID (cast)') tl.plt.xticks([]) tl.plt.subplot(515) tl.plt.semilogy(Snaps['T_full'], '.', color='yellowgreen') tl.plt.xlim([0, len(Xorg)]) tl.plt.ylabel('Speed') #tl.savefig("%sout_Vf"%(outdir),'pdf') tl.savefig("%sout_Vf" % (outdir), 'png') tl.plt.close()
def _plotSS_t_G(idx, Snaps, outdir, SnapsHs): tc = idx tf_st = tc + Snaps['lstep'] tf_ed = tf_st + Snaps['pstep'] n = Snaps['n'] Xorg = Snaps['Xorg'] mn = np.nanmin(Xorg.flatten()) mx = np.nanmax(Xorg.flatten()) if (DBG): tl.msg([tc, tf_st, tf_ed]) tl.plt.clf() tl.plt.subplot(511) tl.plt.plot(Xorg[0:idx, :]) #, 'black') tl.plt.plot(range(idx, n), Xorg[idx:n, :], 'lightgrey') tl.plt.xlim([0, len(Xorg)]) tl.plt.ylim([mn, mx]) tl.plt.ylabel('Original') tl.plt.xticks([]) _plot_lines([tc], mn, mx, 0.5, 'b') _plot_lines([tf_st, tf_ed], mn, mx, 0.5, 'r') tl.plt.subplot(512) tl.plt.plot(Xorg[0:idx, :], 'lightgrey') tl.resetCol() tl.plt.plot(Snaps['Ve_full'][0:idx]) #, 'royalblue') tl.plt.xlim([0, len(Xorg)]) tl.plt.ylim([mn, mx]) tl.plt.ylabel('Estimation') tl.plt.xticks([]) _plot_lines([tc], mn, mx, 0.5, 'b') _plot_lines([tf_st, tf_ed], mn, mx, 0.5, 'r') tl.plt.subplot(513) tl.plt.plot(Xorg[0:tf_ed, :], 'lightgrey') tl.resetCol() if (SMTH): tl.plt.plot( tl.smoothWMAo(Snaps['Vf_full'][0:tf_ed], int(Snaps['pstep']))) else: tl.plt.plot(Snaps['Vf_full'][0:tf_ed]) tl.plt.xlim([0, len(Xorg)]) tl.plt.ylim([mn, mx]) tl.plt.ylabel('Forecast') tl.plt.xticks([]) _plot_lines([tc], mn, mx, 0.5, 'b') _plot_lines([tf_st, tf_ed], mn, mx, 0.5, 'r') tl.plt.subplot(514) tl.plt.plot(Snaps['Ef_full'][0:idx], 'yellowgreen') tl.plt.plot(Snaps['Es_full'][0:idx], 'lightgrey') tl.plt.xlim([0, len(Xorg)]) tl.plt.ylabel('RMSE') tl.plt.xticks([]) emx = np.nanmax(Snaps['Es_full'].flatten()) _plot_lines([tc], 0, emx, 0.5, 'b') _plot_lines([tf_st, tf_ed], 0, emx, 0.5, 'r') tl.plt.ylim([0, emx]) tl.plt.subplot(515) tmx = -tl.INF tmn = tl.INF for i in range(0, MSCALE_H): tl.plt.semilogy(SnapsHs[i]['T_full'][0:idx], '.', label='h=%d' % (i)) mn = np.nanmin(SnapsHs[i]['T_full']) mx = np.nanmax(SnapsHs[i]['T_full']) if (tmx < mx): tmx = mx if (tmn > mn): tmn = mn tl.plt.xlim([0, len(Xorg)]) _plot_lines([tc], tmn, tmx, 0.5, 'b') _plot_lines([tf_st, tf_ed], tmn, tmx, 0.5, 'r') tl.plt.ylim([tmn, tmx]) tl.plt.ylabel('Speed') if (outdir != ''): tl.savefig("%sresult_G" % (outdir), 'pdf') tl.savefig("%sresult_G" % (outdir), 'png')
def _plotSS_t_L(idx, Snaps, mdb): #------------------------------------------------------# tb_st = Snaps['Te'][idx, 0] tb_ed = Snaps['Te'][idx, 1] tp_st = Snaps['Te'][idx, 2] tp_ed = Snaps['Te'][idx, 3] tc_st = Snaps['Te'][idx, 4] tc_ed = Snaps['Te'][idx, 5] tf_st = Snaps['Te'][idx, 6] tf_ed = Snaps['Te'][idx, 7] #------------------------------------------------------# if (DBG): tl.msg([tb_st, tb_ed, tp_st, tp_ed, tc_st, tc_ed, tf_st, tf_ed]) Xe_t = Snaps['Xe'][idx] Ve_t = Snaps['Ve'][idx] Re_t = Snaps['Re'][idx] Xorg = Snaps['Xorg'] nduration = Snaps['n'] lstep = Snaps['lstep'] mn = np.nanmin(Xorg.flatten()) mx = np.nanmax(Xorg.flatten()) #-----------------------------------# tl.plt.clf() tl.plt.subplot(611) tl.plt.plot(Xorg) #, 'black') _plot_lines([tb_st, tb_ed, tp_st, tp_ed, tc_st, tc_ed], mn, mx, 0.5, 'b') _plot_lines([tf_st, tf_ed], mn, mx, 0.5, 'r') tl.plt.xlim([0, nduration]) tl.plt.ylim([mn, mx]) tl.plt.ylabel('Original') tl.plt.xticks([]) tl.plt.subplot(612) tl.plt.plot(Xorg, 'lightgrey', color=[0.8, 0.8, 0.8]) tl.resetCol() if (SMTH): tl.plt.plot( range(0, tf_ed), tl.smoothWMAo(Snaps['Vf_full'][0:tf_ed], int(Snaps['pstep']))) else: tl.plt.plot(range(0, tf_ed), Snaps['Vf_full'][0:tf_ed]) _plot_lines([tf_st, tf_ed], mn, mx, 0.5, 'r') tl.plt.xlim([0, nduration]) tl.plt.ylim([mn, mx]) tl.plt.ylabel('Forecast') tl.plt.xticks([]) tl.plt.subplot(613) _plot_lines([tb_st, tb_ed, tp_st, tp_ed, tc_st, tc_ed], -1, 100, 0.5, 'b') tl.plt.imshow(_createImap(mdb, Snaps['Re_full'][0:tc_ed]), cmap='gray', interpolation='nearest', aspect='auto') tl.plt.xlim([0, nduration]) #; tl.plt.yticks([]) tl.plt.yticks(range(0, mdb.get_c()), range(1, mdb.get_c() + 1)) tl.plt.xticks([]) tl.plt.ylabel('R-ID') #tl.plt.subplot(12,1,6) #_plot_lines([tf_st, tf_ed], -1, 100, 0.5, 'r') #tl.plt.imshow(_createImap(mdb, Snaps['Rf_full'][0:tf_ed]), cmap='gray', interpolation='nearest', aspect='auto') #tl.plt.xlim([0,nduration]) #; tl.plt.yticks([]) #tl.plt.yticks(range(0,mdb.get_c()), range(1,mdb.get_c()+1)) #-----------------------------------# ss_st = int(max(0, tc_ed - lstep * 4)) ss_ed = int(min(tf_ed + lstep / 2, nduration)) #ss_st=int(max(0,tb_st-lstep*0)); ss_ed=int(min(tf_ed+lstep, nduration)) #tl.plt.subplot(223) if (PLOT_R): tl.plt.subplot(234) else: tl.plt.subplot(223) #tl.plt.plot(range(ss_st,ss_ed), Snaps['Xorg'][ss_st:ss_ed]) #, 'black') #,:]) tl.plt.plot(range(ss_st, ss_ed), Snaps['Xorg'][ss_st:ss_ed], 'lightgrey') tl.resetCol() tl.plt.plot(range(ss_st, tc_ed), Snaps['Xorg'][ss_st:tc_ed]) #, 'black') #,:]) _plot_lines([tb_st, tb_ed, tp_st, tp_ed, tc_st], mn, mx, 0.5, 'b') _plot_lines([tc_ed, tf_st, tf_ed], mn, mx, 0.5, 'r') tl.plt.xlim(ss_st, ss_ed) tl.plt.ylim([mn, mx]) tl.plt.title('Org tc:%d, Vc [%d:%d]' % (tc_ed, tc_st, tc_ed)) if (PLOT_R): tl.plt.subplot(235) else: tl.plt.subplot(224) tl.plt.plot(range(ss_st, ss_ed), Snaps['Xorg'][ss_st:ss_ed], 'lightgrey') tl.resetCol() tl.plt.plot(range(tb_st, tf_ed), Ve_t) #, 'tomato') _plot_lines([tb_st, tb_ed, tp_st, tp_ed, tc_st], mn, mx, 0.5, 'b') _plot_lines([tc_ed, tf_st, tf_ed], mn, mx, 0.5, 'r') tl.plt.xlim(ss_st, ss_ed) tl.plt.ylim([mn, mx]) tl.plt.title('Cast Vf [%d:%d]' % (tf_st, tf_ed)) if (PLOT_R): tl.plt.subplot(236) tl.plt.plot(range(tb_st, tf_ed), Re_t) tl.plt.xlim(ss_st, ss_ed)
def _plot(nlds, disp=False, nf=-1, fn=''): if (nf == -1): nf = int(nlds.n) (Sta, Obs) = nlds.gen(nf) (StaL, ObsL) = nlds.gen_lin(nf) err_o = tl.RMSE(nlds.data, 0 * nlds.data) err = tl.RMSE(Obs[0:len(nlds.data), :], nlds.data) errL = tl.RMSE(ObsL[0:len(nlds.data), :], nlds.data) data = nlds.data mn = np.nanmin(data.flatten()) mx = np.nanmax(data.flatten()) mnx = abs(mx - mn) mx += 0.1 * mnx mn -= 0.1 * mnx #fig=tl.figure(10) tl.plt.clf() # tl.plt.subplot(221) tl.resetCol() tl.plt.plot(data, '-', lw=1) tl.plt.xlim([0, nf]) tl.plt.ylim([mn, mx]) tl.plt.title("Original data") # tl.plt.subplot(222) tl.resetCol() tl.plt.plot(data, '--', lw=1) tl.resetCol() tl.plt.plot(Obs, '-', lw=1) tl.plt.xlim([0, nf]) tl.plt.ylim([mn, mx]) tl.plt.title("Original vs. Estimation: err %.2f (%.2f)" % (err, err / err_o)) # tl.plt.subplot(223) tl.plt.plot(Sta, '-', lw=1) tl.plt.xlim([0, nf]) tl.plt.title("s(t) --- Sta (hidden) k:%d" % (nlds.k)) # tl.plt.subplot(224) for i in range(0, len(Obs[0])): tl.plt.fill_between(range(0, len(Obs)), Obs[:, i] + 2 * err, Obs[:, i] - 2 * err, facecolor=[0.8, 0.8, 0.8], alpha=1.0, linewidth=0.0) tl.plt.plot(Obs, '-', lw=1) tl.plt.xlim([0, nf]) tl.plt.ylim([mn, mx]) tl.plt.title("v(t) --- Obs (est)") # tl.plt.tight_layout(pad=1.0, w_pad=1.0, h_pad=1.0) if (False): tl.plt.subplot(322) tl.resetCol() tl.plt.plot(data, '--', lw=1) tl.resetCol() tl.plt.plot(ObsL, '-', lw=1) tl.plt.xlim([0, nf]) tl.plt.ylim([mn, mx]) tl.plt.title("Original vs. LDS: errL %.2f (%.2f)" % (errL, errL / err_o)) # tl.plt.subplot(324) tl.plt.plot(StaL, '-', lw=1) tl.plt.xlim([0, nf]) tl.plt.title("s(t) --- Sta (LDS) k:%d" % (nlds.k)) # tl.plt.subplot(326) for i in range(0, len(Obs[0])): tl.plt.fill_between(range(0, len(ObsL)), ObsL[:, i] + 2 * errL, ObsL[:, i] - 2 * errL, facecolor=[0.8, 0.8, 0.8], alpha=1.0, linewidth=0.0) tl.plt.plot(ObsL, '-', lw=1) tl.plt.xlim([0, nf]) tl.plt.ylim([mn, mx]) tl.plt.title("v(t) --- Obs (LDS)") # if (fn != ''): tl.savefig(fn + '_plot', 'pdf') tl.plt.draw() tl.plt.show(block=disp) if (disp != True): tl.plt.close() # save data (optional) if (FULLSAVE): tl.save_txt(data, fn + '_seq_data.txt') tl.save_txt(Sta, fn + '_seq_Sta.txt') tl.save_txt(Obs, fn + '_seq_Obs.txt') tl.save_txt(ObsL, fn + '_seq_ObsL.txt')