Пример #1
0
    print

    print "Last 10 hidden states in the second-best MAP estimate:"
    for time_step in range(num_time_steps - 10, num_time_steps):
        if estimated_states2[time_step] is None:
            print 'Missing'
        else:
            print estimated_states2[time_step]
    print

    print "Number of differences between MAP estimate and true hidden " + \
          "states:", \
          robot.compute_number_of_differences(estimated_states,
                                              hidden_states)
    print "Number of differences between second-best MAP estimate and " + \
          "true hidden states:", \
          robot.compute_number_of_differences(estimated_states2,
                                              hidden_states)
    print "Number of differences between MAP and second-best MAP " + \
          "estimates:", \
          robot.compute_number_of_differences(estimated_states,
                                              estimated_states2)

    # display
    if use_graphics:
        app = graphics.playback_positions(hidden_states,
                                          observations,
                                          estimated_states)
        app.mainloop()

Пример #2
0
    print "Last 10 hidden states in the MAP estimate:"
    for time_step in range(num_time_steps - 10, num_time_steps):
        if estimated_states[time_step] is None:
            print 'Missing'
        else:
            print estimated_states[time_step]
    print


    difference = 0
    for time_step in range(num_time_steps):
        if estimated_states[time_step] != hidden_states[time_step]:
            difference += 1
    print "Number of differences between MAP estimate and true hidden " + \
          "states:", difference

    mse = robot.compute_average_distance_between(estimated_states,
                                                 hidden_states)

    print "Mean distance between MAP estimate and true hidden states:", mse

    # display
    if use_graphics:
        # Don't run the GUI for too long
        gui_limit_steps = 100
        app = graphics.playback_positions(hidden_states[:gui_limit_steps],
                                          observations[:gui_limit_steps],
                                          estimated_states[:gui_limit_steps],
                                          marginals[:gui_limit_steps])
        app.mainloop()
Пример #3
0
                               rover.observation_model,
                               observations)
    print('\n')
    
    print("Last 10 hidden states in the MAP estimate:")
    for time_step in range(num_time_steps - 10, num_time_steps):
        print(estimated_states[time_step], "for z",time_step)

    fb_error = Pe_fb(marginals,hidden_states)
    v_error = Pe_v(estimated_states,hidden_states)
    print(" Error due to forward-backward is",fb_error)
    print(" Error due to viterbi is",v_error)

    #check for invalid sequence
    # for time_step in range(1, num_time_steps):
    #     print(marginals[time_step].get_mode(), "for z",time_step)
        

    
    # if you haven't complete the algorithms, to use the visualization tool
    # let estimated_states = [None]*num_time_steps, marginals = [None]*num_time_steps
    # estimated_states = [None]*num_time_steps
    # marginals = [None]*num_time_steps
    if enable_graphics:
        app = graphics.playback_positions(hidden_states,
                                          observations,
                                          estimated_states,
                                          marginals)
        app.mainloop()
        
Пример #4
0
def main():
    # flags
    make_some_observations_missing = False
    use_graphics = True
    need_to_generate_data = True

    # parse command line arguments
    for arg in sys.argv[1:]:
        if arg == '--missing':
            make_some_observations_missing = True
        elif arg == '--nographics':
            use_graphics = False
        elif arg.startswith('--load='):
            filename = arg[7:]
            hidden_states, observations = robot.load_data(filename)
            need_to_generate_data = False
            num_time_steps = len(hidden_states)

    # if no data is loaded, then generate new data
    if need_to_generate_data:
        num_time_steps = 100
        hidden_states, observations = \
            generate_data(num_time_steps,
                          make_some_observations_missing)

    print('Running forward-backward...')
    marginals = forward_backward(observations)
    print("\n")

    timestep = 2
    print("Most likely parts of marginal at time %d:" % (timestep))
    if marginals[timestep] is not None:
        print(
            sorted(marginals[timestep].items(),
                   key=lambda x: x[1],
                   reverse=True)[:10])
    else:
        print('*No marginal computed*')
    print("\n")

    print('Running Viterbi...')
    estimated_states = Viterbi(observations)
    print("\n")

    print("Last 10 hidden states in the MAP estimate:")
    for time_step in range(num_time_steps - 10 - 1, num_time_steps):
        if estimated_states[time_step] is None:
            print('Missing')
        else:
            print(estimated_states[time_step])
    print("\n")

    print('Finding second-best MAP estimate...')
    estimated_states2 = second_best(observations)
    print("\n")

    print("Last 10 hidden states in the second-best MAP estimate:")
    for time_step in range(num_time_steps - 10 - 1, num_time_steps):
        if estimated_states2[time_step] is None:
            print('Missing')
        else:
            print(estimated_states2[time_step])
    print("\n")

    difference = 0
    difference_time_steps = []
    for time_step in range(num_time_steps):
        if estimated_states[time_step] != hidden_states[time_step]:
            difference += 1
            difference_time_steps.append(time_step)
    print(
        "Number of differences between MAP estimate and true hidden " +
        "states:", difference)
    if difference > 0:
        print("Differences are at the following time steps: " + ", ".join(
            ["%d" % time_step for time_step in difference_time_steps]))
    print("\n")

    difference = 0
    difference_time_steps = []
    for time_step in range(num_time_steps):
        if estimated_states2[time_step] != hidden_states[time_step]:
            difference += 1
            difference_time_steps.append(time_step)
    print(
        "Number of differences between second-best MAP estimate and " +
        "true hidden states:", difference)
    if difference > 0:
        print("Differences are at the following time steps: " + ", ".join(
            ["%d" % time_step for time_step in difference_time_steps]))
    print("\n")

    difference = 0
    difference_time_steps = []
    for time_step in range(num_time_steps):
        if estimated_states[time_step] != estimated_states2[time_step]:
            difference += 1
            difference_time_steps.append(time_step)
    print(
        "Number of differences between MAP and second-best MAP " +
        "estimates:", difference)
    if difference > 0:
        print("Differences are at the following time steps: " + ", ".join(
            ["%d" % time_step for time_step in difference_time_steps]))
    print("\n")

    # display
    if use_graphics:
        app = graphics.playback_positions(hidden_states, observations,
                                          estimated_states, marginals)
        app.mainloop()