def plot_latent(model, y, plot_title=''):
# make prediction on some test inputs
N_test = 200
C = model.get_hypers()['C_emission'][0, 0]
x_test = np.linspace(-4, 6, N_test) / C
x_test = np.reshape(x_test, [N_test, 1])
zu = model.dyn_layer.zu
mu, vu = model.predict_f(zu)
# mu, Su = model.dyn_layer.mu, model.dyn_layer.Su
mf, vf = model.predict_f(x_test)
my, vy = model.predict_y(x_test)
# plot function
fig = plt.figure()
ax = fig.add_subplot(111)
# ax.plot(x_test[:,0], kink_true(x_test[:,0]), '-', color='k')
ax.plot(C*x_test[:,0], my[:,0], '-', color='r', label='y')
ax.fill_between(
C*x_test[:,0],
my[:,0] + 2*np.sqrt(vy[:, 0]),
my[:,0] - 2*np.sqrt(vy[:, 0]),
alpha=0.2, edgecolor='r', facecolor='r')
# ax.plot(zu, mu, 'ob')
# ax.errorbar(zu, mu, yerr=3*np.sqrt(vu), fmt='ob')
# ax.plot(x_test[:,0], mf[:,0], '-', color='b')
# ax.fill_between(
# x_test[:,0],
# mf[:,0] + 2*np.sqrt(vf[:,0]),
# mf[:,0] - 2*np.sqrt(vf[:,0]),
# alpha=0.2, edgecolor='b', facecolor='b')
ax.plot(
y[0:model.N-1],
y[1:model.N],
'r+', alpha=0.5)
mx, vx = model.get_posterior_x()
ax.set_xlabel(r'$x_{t-1}$')
ax.set_ylabel(r'$x_{t}$')
ax.set_xlim([-4, 6])
# ax.set_ylim([-7, 7])
plt.title(plot_title)
# plt.savefig('/tmp/kink_'+plot_title+'.pdf')
plt.savefig('/tmp/kink_'+plot_title+'.png')
评论列表
文章目录