def plot_dog_track(xs, dog, measurement_var, process_var): N = len(xs) bp.plot_track(dog) bp.plot_measurements(xs, label='Sensor') bp.set_labels('variance = {}, process variance = {}'.format( measurement_var, process_var), 'time', 'pos') plt.ylim([0, N]) bp.show_legend() plt.show()
def plot_gh_results(weights, estimates, predictions, actual, time_step=0): n = len(weights) if time_step > 0: rng = range(1, n+1) else: rng = range(n, n+1) xs = range(n+1) book_plots.plot_measurements(xs[1:], weights, color='k', lines=False) book_plots.plot_filter(xs, estimates, marker='o', label='Estimates') book_plots.plot_track(xs[1:], predictions, c='r', marker='v', label='Predictions') plt.plot([xs[0], xs[-1]], actual, c='k', lw=1, label='Actual') plt.legend(loc=4) book_plots.set_labels(x='day', y='weight (lbs)') plt.xlim([-1, n+1]) plt.ylim([156.0, 173])
def plot_gh_results(weights, estimates, predictions, time_step=0): n = len(weights) if time_step > 0: rng = range(1, n+1) else: rng = range(n, n+1) xs = range(n+1) pred, = book_plots.plot_track(xs[1:], predictions, c='r', marker='v') scale, = book_plots.plot_measurements(xs[1:], weights, color='k', lines=False) est, = book_plots.plot_filter(xs, estimates, marker='o') plt.legend([scale, est, pred], ['Measurement', 'Estimates', 'Predictions'], loc=4) book_plots.set_labels(x='day', y='weight (lbs)') plt.xlim([-1, n+1]) plt.ylim([156.0, 173])
def plot_gh_results(weights, estimates, predictions, time_step=0): plt.figure(figsize=(9, 4)) n = len(weights) if time_step > 0: rng = range(1, n + 1) else: rng = range(n, n + 1) act, = book_plots.plot_track([0, n], [160, 160 + n], c='k') plt.gcf().canvas.draw() for i in rng: xs = list(range(i + 1)) pred, = book_plots.plot_track(xs[1:], predictions[:i], c='r', marker='v') plt.xlim([-1, n + 1]) plt.ylim([156.0, 173]) plt.gcf().canvas.draw() time.sleep(time_step) scale, = book_plots.plot_measurements(xs[1:], weights[:i], color='k', lines=False) plt.xlim([-1, n + 1]) plt.ylim([156.0, 173]) plt.gcf().canvas.draw() time.sleep(time_step) est, = book_plots.plot_filter(xs[:i + 1], estimates[:i + 1], marker='o') plt.xlim([-1, n + 1]) plt.ylim([156.0, 173]) plt.gcf().canvas.draw() time.sleep(time_step) plt.legend( [act, scale, est, pred], ['Actual Weight', 'Measurement', 'Estimates', 'Predictions'], loc=4) book_plots.set_labels(x='day', y='weight (lbs)') plt.xlim([-1, n + 1]) plt.ylim([156.0, 173])
def plot_gh_results(weights, estimates, predictions, time_step=0): n = len(weights) if time_step > 0: rng = range(1, n+1) else: rng = range(n, n+1) plt.xlim([-1, n+1]) plt.ylim([156.0, 173]) act, = book_plots.plot_track([0, n], [160, 160+n], c='k') plt.gcf().canvas.draw() for i in rng: xs = list(range(i+1)) #plt.cla() pred, = book_plots.plot_track(xs[1:], predictions[:i], c='r', marker='v') plt.xlim([-1, n+1]) plt.ylim([156.0, 173]) plt.gcf().canvas.draw() time.sleep(time_step) scale, = book_plots.plot_measurements(xs[1:], weights[:i], color='k', lines=False) plt.xlim([-1, n+1]) plt.ylim([156.0, 173]) plt.gcf().canvas.draw() time.sleep(time_step) est, = book_plots.plot_filter(xs[:i+1], estimates[:i+1], marker='o') plt.xlim([-1, n+1]) plt.ylim([156.0, 173]) plt.gcf().canvas.draw() time.sleep(time_step) plt.legend([act, scale, est, pred], ['Actual Weight', 'Measurement', 'Estimates', 'Predictions'], loc=4) book_plots.set_labels(x='day', y='weight (lbs)')
x = gaussian(0., 1000.) # initial state process_model = gaussian(1., process_var) N = 12 zs = distancia(distance_std, N) ps = [] estimates = [] priors = np.zeros((N, 2)) for i, z in enumerate(zs): prior = predict(x, process_model) priors[i] = prior x = update(prior, gaussian(z, distance_std**2)) # save for latter plotting estimates.append(x.mean) ps.append(x.var) # plot the filter output and the variance book_plots.plot_measurements(zs) book_plots.plot_filter(estimates, var=np.array(ps)) book_plots.plot_predictions(priors[:, 0]) book_plots.show_legend() book_plots.set_labels(x='Tempo (s)', y='Posições') plt.show() plt.figure() plt.plot(ps) plt.title('Variância') print('Variance converges to {:.3f}'.format(ps[-1]))