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()
Exemple #2
0
def plot_track(ps,
               actual,
               zs,
               cov,
               std_scale=1,
               plot_P=True,
               y_lim=None,
               dt=1.,
               xlabel='time',
               ylabel='position',
               title='Kalman Filter'):

    with interactive_plot():
        count = len(zs)
        zs = np.asarray(zs)

        cov = np.asarray(cov)
        std = std_scale * np.sqrt(cov[:, 0, 0])
        std_top = np.minimum(actual + std, [count + 10])
        std_btm = np.maximum(actual - std, [-50])

        std_top = actual + std
        std_btm = actual - std

        bp.plot_track(actual, c='k')
        bp.plot_measurements(range(1, count + 1), zs)
        bp.plot_filter(range(1, count + 1), ps)

        plt.plot(std_top, linestyle=':', color='k', lw=1, alpha=0.4)
        plt.plot(std_btm, linestyle=':', color='k', lw=1, alpha=0.4)
        plt.fill_between(range(len(std_top)),
                         std_top,
                         std_btm,
                         facecolor='yellow',
                         alpha=0.2,
                         interpolate=True)
        plt.legend(loc=4)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        if y_lim is not None:
            plt.ylim(y_lim)
        else:
            plt.ylim((-50, count + 10))

        plt.xlim((0, count))
        plt.title(title)
        plt.show()

    if plot_P:
        ax = plt.subplot(121)
        ax.set_title("$\sigma^2_x$ (pos variance)")
        plot_covariance(cov, (0, 0))
        ax = plt.subplot(122)
        ax.set_title("$\sigma^2_\dot{x}$ (vel variance)")
        plot_covariance(cov, (1, 1))
        plt.show()
Exemple #3
0
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, 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)

        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, pred],
                   ['Actual Weight', 'Measurement', 'Predictions'],
                   loc=4)
    book_plots.set_labels(x='day', y='weight (lbs)')
Exemple #5
0
def plot_track(ps, actual, zs, cov, std_scale=1,
               plot_P=True, y_lim=None, dt=1.,
               xlabel='time', ylabel='position',
               title='Kalman Filter'):

    with interactive_plot():
        count = len(zs)
        zs = np.asarray(zs)

        cov = np.asarray(cov)
        std = std_scale*np.sqrt(cov[:,0,0])
        std_top = np.minimum(actual+std, [count + 10])
        std_btm = np.maximum(actual-std, [-50])

        std_top = actual + std
        std_btm = actual - std

        bp.plot_track(actual,c='k')
        bp.plot_measurements(range(1, count + 1), zs)
        bp.plot_filter(range(1, count + 1), ps)

        plt.plot(std_top, linestyle=':', color='k', lw=1, alpha=0.4)
        plt.plot(std_btm, linestyle=':', color='k', lw=1, alpha=0.4)
        plt.fill_between(range(len(std_top)), std_top, std_btm,
                         facecolor='yellow', alpha=0.2, interpolate=True)
        plt.legend(loc=4)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        if y_lim is not None:
            plt.ylim(y_lim)
        else:
            plt.ylim((-50, count + 10))

        plt.xlim((0,count))
        plt.title(title)
        plt.show()

    if plot_P:
        ax = plt.subplot(121)
        ax.set_title("$\sigma^2_x$ (pos variance)")
        plot_covariance(cov, (0, 0))
        ax = plt.subplot(122)
        ax.set_title("$\sigma^2_\dot{x}$ (vel variance)")
        plot_covariance(cov, (1, 1))
        plt.show()
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)

        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, pred], ['Actual Weight', 'Measurement', 'Predictions'], loc=4)
    book_plots.set_labels(x='day', y='weight (lbs)')
Exemple #7
0
def plot_radar(xs, track, time):
    plt.figure()
    bp.plot_track(time, track[:, 0])
    bp.plot_filter(time, xs[:, 0])
    plt.legend(loc=4)
    plt.xlabel('time (sec)')
    plt.ylabel('position (m)')

    plt.figure()
    bp.plot_track(time, track[:, 1])
    bp.plot_filter(time, xs[:, 1])
    plt.legend(loc=4)
    plt.xlabel('time (sec)')
    plt.ylabel('velocity (m/s)')

    plt.figure()
    bp.plot_track(time, track[:, 2])
    bp.plot_filter(time, xs[:, 2])
    plt.ylabel('altitude (m)')
    plt.legend(loc=4)
    plt.xlabel('time (sec)')
    plt.ylim((900, 1600))
    plt.show()