예제 #1
0
    def plotfunc(self, pylab, frame):
        turn_all_axes_off(pylab)

        frame = int(np.floor(frame / self.upsample))
        if frame >= len(self.beliefs):
            frame = len(self.beliefs) - 1

        belief = self.beliefs[frame]
        self.pomdp.display_state_dist(pylab, belief)

        agent_state = self.agent_states[frame]
        keys = sorted(agent_state.keys())
        values = [agent_state[k] for k in keys]
        state_string = ' '.join(map(str, values))

        #   pylab.figtext(0.1, 0.95 , state_string,
        #     fontproperties=FontProperties(size=25))

        max_len = 16
        size0 = 24 * 1.5
        if len(state_string) > max_len:
            use_len = size0 * max_len * 1.0 / len(state_string)
        else:
            use_len = size0

        shape = self.pomdp.get_grid_shape()
        dx = 0
        dy = shape[1] + 0.5
        pylab.text(dx, dy , state_string,
                   fontproperties=FontProperties(size=use_len))

        pylab.axis(self.get_data_bounds())

        pylab.tight_layout()
예제 #2
0
def report_maze_policy(r, mdp, policy):
    f = r.figure()
    with f.plot('policy') as pylab:
        mdp.display_policy(pylab, policy)
        turn_all_axes_off(pylab)


    state_dist = run_trajectories(mdp, start=mdp.get_start_dist(), policy=policy,
                                  nsteps=1000, ntraj=100,
                                  goal=mdp.get_goal())

    if state_dist:
        with f.plot('state_dist') as pylab:
            mdp.display_state_dist(pylab, state_dist)
            turn_all_axes_off(pylab)
예제 #3
0
def report_maze_policy(r, mdp, policy):
    f = r.figure()
    with f.plot('policy') as pylab:
        mdp.display_policy(pylab, policy)
        turn_all_axes_off(pylab)

    state_dist = run_trajectories(mdp,
                                  start=mdp.get_start_dist(),
                                  policy=policy,
                                  nsteps=1000,
                                  ntraj=100,
                                  goal=mdp.get_goal())

    if state_dist:
        with f.plot('state_dist') as pylab:
            mdp.display_state_dist(pylab, state_dist)
            turn_all_axes_off(pylab)
def plot_2d_graph(pylab, G, plan2point, plan2color, edges2color=None, s=120):
    if edges2color is None:
        edges2color = lambda n1, n2: [0, 0, 0] #@UnusedVariable
        
    cm = matplotlib.cm.get_cmap('RdYlBu')
        
    for pi, pj, ec in get_edges_points_and_color(G, plan2point, edges2color):
        coords = np.vstack((pi, pj)).T
        pylab.plot(coords[0], coords[1], linestyle='-', color=ec, zorder=1)
        
    n = len(G)
    P = np.array(map(plan2point, G)).T
    assert_allclose(P.shape, (2, n))
    color = map(plan2color, G)
    pylab.scatter(P[0], P[1], s=s, c=color, cmap=cm, zorder=3)
    pylab.axis('equal')            
    turn_all_axes_off(pylab)
    pylab.colorbar()
예제 #5
0
def plot_2d_graph(pylab, G, plan2point, plan2color, edges2color=None, s=120):
    if edges2color is None:
        edges2color = lambda n1, n2: [0, 0, 0]  #@UnusedVariable

    cm = matplotlib.cm.get_cmap('RdYlBu')

    for pi, pj, ec in get_edges_points_and_color(G, plan2point, edges2color):
        coords = np.vstack((pi, pj)).T
        pylab.plot(coords[0], coords[1], linestyle='-', color=ec, zorder=1)

    n = len(G)
    P = np.array(map(plan2point, G)).T
    assert_allclose(P.shape, (2, n))
    color = map(plan2color, G)
    pylab.scatter(P[0], P[1], s=s, c=color, cmap=cm, zorder=3)
    pylab.axis('equal')
    turn_all_axes_off(pylab)
    pylab.colorbar()
예제 #6
0
def plot_style_servo_field_xy(pylab, area_graphs):
    centroid = [0, 0]
    pylab.plot(centroid[0], centroid[1], 'go')
    
    
    # M = 2.0
    M = area_graphs
    
    b = 0.03

    if False:
        pylab.plot([-M + b, -M + b], [-M + b, -M + 1 + b], 'k-')
        pylab.plot([-M + b + 1, -M + b], [-M + b, -M + b], 'k-')
        
    pylab.axis('equal')
    
    if False:
        N = M - b * 2
        pylab.plot([-N, N, N, -N, -N], [-N, -N, N, N, -N], 'k--')
    pylab.axis((-M, +M, -M, +M))
    
    turn_all_axes_off(pylab)
예제 #7
0
    def plotfunc(self, pylab, frame):
        turn_all_axes_off(pylab)

        frame = int(np.floor(frame / self.upsample))
        if frame >= len(self.beliefs):
            frame = len(self.beliefs) - 1

        belief = self.beliefs[frame]
        self.pomdp.display_state_dist(pylab, belief)

        agent_state = self.agent_states[frame]
        keys = sorted(agent_state.keys())
        values = [agent_state[k] for k in keys]
        state_string = ' '.join(map(str, values))

        #   pylab.figtext(0.1, 0.95 , state_string,
        #     fontproperties=FontProperties(size=25))

        max_len = 16
        size0 = 24 * 1.5
        if len(state_string) > max_len:
            use_len = size0 * max_len * 1.0 / len(state_string)
        else:
            use_len = size0

        shape = self.pomdp.get_grid_shape()
        dx = 0
        dy = shape[1] + 0.5
        pylab.text(dx,
                   dy,
                   state_string,
                   fontproperties=FontProperties(size=use_len))

        pylab.axis(self.get_data_bounds())

        pylab.tight_layout()
    def plan_report(self, report, result, tc):
        """
            We pass the testcase structure, so we can use the ground
            truth (if available) to make a nicer visualization.
        """
        from matplotlib.cm import get_cmap
        f = report.figure(cols=3)
        plan2length = lambda x: len(x)
        cmap_start = get_cmap('bones')
        cmap_goal = get_cmap('jet')

        def distance_to(tree, y, node):
            image = tree.plan2image(node)
            return self.metric_goal.distance(image, y)

        from functools import partial
        start_dist_y0 = partial(distance_to, self.start_tree, self.y0)
        goal_dist_y0 = partial(distance_to, self.goal_tree, self.y0)
        start_dist_y1 = partial(distance_to, self.start_tree, self.y1)
        goal_dist_y1 = partial(distance_to, self.goal_tree, self.y1)

        if result.success:
            # Plot the distance as a function of step
            steps = plan_steps(result.plan)  # (), (0,) (0, 1), etc.
            distance_to_y0 = map(start_dist_y0, steps)
            distance_to_y1 = map(start_dist_y1, steps)
            with f.plot('distances_along_path') as pylab:
                lenghts = map(len, steps)
                pylab.plot(lenghts, distance_to_y0, 'r-', label='to $y_0$')
                pylab.plot(lenghts, distance_to_y1, 'b-', label='to $y_1$')
                pylab.xlabel('subplan length')
                pylab.legend()

        with f.plot('start_tree') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab,
                plan2color=plan2length,
                cmap=cmap_start,
                show_plan=tc.true_plan)
            pylab.title('plan length')
            turn_all_axes_off(pylab)
            pylab.colorbar()

        with f.plot('goal_tree') as pylab:
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=plan2length, cmap=cmap_goal)
            pylab.title('plan length')
            turn_all_axes_off(pylab)
            pylab.colorbar()

        true_plan = tc.true_plan
        ss = guess_state_space(self.id_dds, self._dds)
        u0 = self.get_dds().indices_to_commands(true_plan)
        origin = ss.state_from_commands(u0)

        with f.plot('joint') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=plan2length, cmap=cmap_start)
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=plan2length, cmap=cmap_goal, origin=origin)
            turn_all_axes_off(pylab)
            pylab.colorbar()

        with f.plot('start_tree_y0') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y0, cmap=cmap_start)
            pylab.title('distance to $y_0$')
            turn_all_axes_off(pylab)
            pylab.colorbar()

        with f.plot('goal_tree_y0') as pylab:
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y0, cmap=cmap_goal, origin=origin)
            pylab.title('distance to y_0')
            turn_all_axes_off(pylab)
            pylab.colorbar()

        with f.plot('joint_y0') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y0, cmap=cmap_start)
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y0, cmap=cmap_goal, origin=origin)
            turn_all_axes_off(pylab)
            pylab.colorbar()

        with f.plot('start_tree_y1') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y1, cmap=cmap_start)
            pylab.title('distance to $y_1$')
            turn_all_axes_off(pylab)
            pylab.colorbar()

        with f.plot('goal_tree_y1') as pylab:
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y1, cmap=cmap_goal)
            pylab.title('distance to y_1')
            turn_all_axes_off(pylab)
            pylab.colorbar()

        with f.plot('joint_y1') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y1, cmap=cmap_start)
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y1, cmap=cmap_goal, origin=origin)
            turn_all_axes_off(pylab)
            pylab.colorbar()
예제 #9
0
 def common_settings(pylab):
     pylab.axis('equal')
     pylab.axis((-M, M, -M, M))
     turn_all_axes_off(pylab)
예제 #10
0
 def common_settings(pylab):
     pylab.axis('equal')
     pylab.axis((-M, M, -M, M))
     turn_all_axes_off(pylab)
    def plan_report(self, report, result, tc):
        """
            We pass the testcase structure, so we can use the ground
            truth (if available) to make a nicer visualization.
        """
        f = report.figure(cols=3)
        plan2length = lambda x: len(x)
        cmap_start = get_cmap('bones') 
        cmap_goal = get_cmap('jet')
        
        def distance_to(tree, y, node):
            image = tree.plan2image(node)
            return self.metric_goal.distance(image, y)
             
        from functools import partial
        start_dist_y0 = partial(distance_to, self.start_tree, self.y0)
        goal_dist_y0 = partial(distance_to, self.goal_tree, self.y0)
        start_dist_y1 = partial(distance_to, self.start_tree, self.y1)
        goal_dist_y1 = partial(distance_to, self.goal_tree, self.y1)
        
        if result.success:
            # Plot the distance as a function of step
            steps = plan_steps(result.plan) # (), (0,) (0, 1), etc.
            distance_to_y0 = map(start_dist_y0, steps) 
            distance_to_y1 = map(start_dist_y1, steps)
            with f.plot('distances_along_path') as pylab:
                lenghts = map(len, steps) 
                pylab.plot(lenghts, distance_to_y0, 'r-', label='to $y_0$')
                pylab.plot(lenghts, distance_to_y1, 'b-', label='to $y_1$')
                pylab.xlabel('subplan length')
                pylab.legend()
                
        
        with f.plot('start_tree') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=plan2length, cmap=cmap_start,
                show_plan=tc.true_plan)
            pylab.title('plan length')
            turn_all_axes_off(pylab)
            pylab.colorbar()
            
        with f.plot('goal_tree') as pylab:
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=plan2length, cmap=cmap_goal)
            pylab.title('plan length')
            turn_all_axes_off(pylab)
            pylab.colorbar()
            
        true_plan = tc.true_plan
        ss = guess_state_space(self.id_dds, self._dds)
        u0 = self.get_dds().indices_to_commands(true_plan)
        origin = ss.state_from_commands(u0)

        with f.plot('joint') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=plan2length, cmap=cmap_start)
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=plan2length, cmap=cmap_goal, origin=origin)
            turn_all_axes_off(pylab)
            pylab.colorbar()
            
        with f.plot('start_tree_y0') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y0, cmap=cmap_start)
            pylab.title('distance to $y_0$')
            turn_all_axes_off(pylab)
            pylab.colorbar()
            
        with f.plot('goal_tree_y0') as pylab:
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y0, cmap=cmap_goal, origin=origin)
            pylab.title('distance to y_0')
            turn_all_axes_off(pylab)
            pylab.colorbar()
            
        with f.plot('joint_y0') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y0, cmap=cmap_start)
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y0, cmap=cmap_goal, origin=origin)
            turn_all_axes_off(pylab)
            pylab.colorbar()
        
        with f.plot('start_tree_y1') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y1, cmap=cmap_start)
            pylab.title('distance to $y_1$')
            turn_all_axes_off(pylab)
            pylab.colorbar()
            
        with f.plot('goal_tree_y1') as pylab:
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y1, cmap=cmap_goal)
            pylab.title('distance to y_1')
            turn_all_axes_off(pylab)
            pylab.colorbar()
            
        with f.plot('joint_y1') as pylab:
            self.start_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=start_dist_y1, cmap=cmap_start)
            self.goal_tree.plot_graph_using_guessed_statespace(
                pylab, plan2color=goal_dist_y1, cmap=cmap_goal, origin=origin)
            turn_all_axes_off(pylab)
            pylab.colorbar()