# Plot the log likelihoods plt.figure() plt.plot(lls) plt.xlabel('iteration') plt.ylabel('training likelihood') # Predict forward in time T_given = 1800 T_predict = 200 given_data = data[:T_given] given_inputs = inputs[:T_given] preds = \ model.sample_predictions( given_data, inputs=given_inputs, Tpred=T_predict, inputs_pred=inputs[T_given:T_given + T_predict]) # Plot the predictions plt.figure() plt.plot(np.arange(T), data, 'b-', label="true") plt.plot(T_given + np.arange(T_predict), preds, 'r--', label="prediction") ylim = plt.ylim() plt.plot([T_given, T_given], ylim, '-k') plt.xlabel('time index') plt.xlim(max(0, T_given - 200), T) plt.ylabel('prediction') plt.ylim(ylim) plt.legend() plt.show()
vlbs = [update(model) for _ in progprint_xrange(50)] # Sample from the mean field posterior model.resample_from_mf() # Plot the log likelihoods plt.figure() plt.plot(vlbs) plt.xlabel('iteration') plt.ylabel('variational lower bound') # Predict forward in time given_data = data[:T_given] preds = \ model.sample_predictions(given_data, Tpred=T_predict) # Plot the predictions plt.figure() plt.plot(np.arange(T), data, 'b-', label="true") plt.plot(T_given + np.arange(T_predict), preds, 'r--', label="prediction") ylim = plt.ylim() plt.plot([T_given, T_given], ylim, '-k') plt.xlabel('time index') plt.xlim(max(0, T_given - 200), T) plt.ylabel('prediction') plt.ylim(ylim) plt.legend() plt.show()
model = DefaultLDS(n=2,p=data.shape[1]).add_data(data) for _ in progprint_xrange(100): model.resample_model() vlbs = [update(model) for _ in progprint_xrange(50)] plt.figure(figsize=(3,4)) plt.plot(vlbs) plt.xlabel('iteration') plt.ylabel('variational lower bound') ################ # predicting # ################ Npredict = 100 prediction_seed = data[:1700] predictions = model.sample_predictions(prediction_seed, Npredict) plt.figure() plt.plot(data, 'b-') plt.plot(prediction_seed.shape[0] + np.arange(Npredict), predictions, 'r--') plt.xlabel('time index') plt.ylabel('prediction') plt.show()
model.resample_model() return model.log_likelihood() model = DefaultLDS(n=2, p=data.shape[1]).add_data(data) vlbs = [update(model) for _ in progprint_xrange(100)] plt.figure(figsize=(3, 4)) plt.plot(vlbs) plt.xlabel('iteration') plt.ylabel('variational lower bound') ################ # predicting # ################ Npredict = 100 prediction_seed = data[:1700] predictions = model.sample_predictions(prediction_seed, Npredict, obs_noise=False) plt.figure() plt.plot(data, 'b-') plt.plot(prediction_seed.shape[0] + np.arange(Npredict), predictions, 'r--') plt.xlabel('time index') plt.ylabel('prediction') plt.show()
model.EM_step() return model.log_likelihood() model = DefaultLDS(n=2,p=data.shape[1]).add_data(data) likes = [update(model) for _ in progprint_xrange(50)] plt.figure(figsize=(3,4)) plt.plot(likes) plt.xlabel('iteration') plt.ylabel('training likelihood') ################ # predicting # ################ Npredict = 100 prediction_seed = data[:1700] predictions = model.sample_predictions( prediction_seed, Npredict, obs_noise=False) plt.figure() plt.plot(data, 'b-') plt.plot(prediction_seed.shape[0] + np.arange(Npredict), predictions, 'r--') plt.xlabel('time index') plt.ylabel('prediction') plt.show()