示例#1
0
    def plot_graph_using_guessed_statespace(
            self,
            pylab,  #@UnusedVariable
            plan2color=None,
            plan2label=None,
            cmap=None,
            origin=None,
            show_plan=None):
        ss = guess_state_space(self.id_dds, self.dds)

        def plan2xy(plan):
            commands = self.dds.indices_to_commands(plan)
            state = ss.state_from_commands(commands, start=origin)
            xy = ss.xy_from_state(state)
            return 5 * xy

        if show_plan is not None:
            points = []
            for i in range(len(show_plan)):
                partial = show_plan[:i]
                points.append(plan2xy(partial))
            points = np.array(points).T
            pylab.plot(points[0], points[1], 'r-')

        if plan2color is None:
            plan2color = lambda plan: [0, 0, 0]  #@UnusedVariable
        if plan2label is None:
            plan2label = lambda plan: ''  #@UnusedVariable

        nodes = list(self.G.nodes())

        pos = dict((n, plan2xy(n)) for n in nodes)
        all_positions = map(tuple, pos.values())
        node_color = map(plan2color, nodes)
        labels = dict((n, plan2label(n)) for n in self.G)

        if False:
            if len(all_positions) != len(set(all_positions)):
                print('Warning, overlapping nodes')
                y = collections.Counter(all_positions)
                for p, num in y.items():
                    if num > 1:
                        print('- %d for %s' % (num, p))
                        for node, node_pos in pos.items():
                            if tuple(node_pos) == p:
                                print('  - %s ' % str(node))

        nx.draw_networkx(self.G,
                         with_labels=True,
                         pos=pos,
                         labels=labels,
                         node_color=node_color,
                         cmap=cmap)
    def plot_graph_using_guessed_statespace(self, pylab, #@UnusedVariable
            plan2color=None, plan2label=None, cmap=None, origin=None, show_plan=None):
        ss = guess_state_space(self.id_dds, self.dds) 
        
        def plan2xy(plan):
            commands = self.dds.indices_to_commands(plan)
            state = ss.state_from_commands(commands, start=origin)
            xy = ss.xy_from_state(state)
            return 5 * xy
       
        if show_plan is not None:
            points = []
            for i in range(len(show_plan)):
                partial = show_plan[:i]
                points.append(plan2xy(partial))
            points = np.array(points).T
            pylab.plot(points[0], points[1], 'r-')
       
        if plan2color is None:
            plan2color = lambda plan: [0, 0, 0] #@UnusedVariable
        if plan2label is None:
            plan2label = lambda plan: '' #@UnusedVariable
        
        nodes = list(self.G.nodes())
         
        pos = dict((n, plan2xy(n)) for n in nodes)
        all_positions = map(tuple, pos.values())
        node_color = map(plan2color, nodes) 
        labels = dict((n, plan2label(n)) for n in self.G)
        
        if False:
            if len(all_positions) != len(set(all_positions)):
                print('Warning, overlapping nodes')
                y = collections.Counter(all_positions)
                for p, num in y.items():
                    if num > 1:
                        print('- %d for %s' % (num, p))
                        for node, node_pos in pos.items():
                            if tuple(node_pos) == p:
                                print('  - %s ' % str(node))

        nx.draw_networkx(self.G, with_labels=True, pos=pos, labels=labels,
                        node_color=node_color, cmap=cmap)
示例#3
0
    def draw_graph(self, r):
        def label_plan_length(n):
            return len(n)

        open_nodes = set(self.open_nodes)

        def label_child_open(n):
            # number of children in the open list
            children = self.G[n]
            return len(set(children) & open_nodes)

        ss = guess_state_space(self.id_dds, self.dds)

        def point_func(plan):
            commands = self.dds.indices_to_commands(plan)
            state = ss.state_from_commands(commands)
            xy = ss.xy_from_state(state)
            return 5 * xy

        f = r.figure(cols=2)
        nolabel = lambda _: ''
        with f.data_file('planlength', MIME_PNG) as filename:
            draw_node_graph(
                filename=filename,
                G=self.G,
                pos_func=point_func,
                #label_func=label_plan_length,
                label_func=nolabel,
                color_func=label_plan_length)

        with f.data_file('nchildopen', MIME_PNG) as filename:
            draw_node_graph(
                filename=filename,
                G=self.G,
                pos_func=point_func,
                #                        label_func=label_child_open,
                label_func=nolabel,
                color_func=label_child_open)

        with f.data_file('info', MIME_PNG) as filename:
            draw_node_graph(
                filename=filename,
                G=self.G,
                pos_func=point_func,
                #label_func=lambda x: '%.2f' % self.visibility(x),
                label_func=nolabel,
                color_func=self.visibility)

        with f.plot('visible') as pylab:
            v = map(self.visibility, self.G)
            pylab.hist(v, 100)

        with r.subsection('embedding') as s:
            self.draw_embeddings(s)

        all_plans = list(self.G.nodes())
        random.shuffle(all_plans)
        random_plans = all_plans[:3]
        for pi, ref_plan in enumerate(random_plans):
            color_func = lambda p2: self.plan_distance(
                ref_plan, p2, diffeoaction_distance_L2_infow)
            name = 'random%d' % pi
            with f.data_file(name, MIME_PNG) as filename:
                draw_node_graph(
                    filename=filename,
                    G=self.G,
                    pos_func=point_func,
                    #label_func=lambda x: '%.2f' % self.visibility(x),
                    label_func=nolabel,
                    color_func=color_func)
    def draw_graph(self, r):
        
        def label_plan_length(n):
            return  len(n)
        
        open_nodes = set(self.open_nodes)
        
        def label_child_open(n):
            # number of children in the open list
            children = self.G[n]
            return len(set(children) & open_nodes)
    
        ss = guess_state_space(self.id_dds, self.dds)
        
        def point_func(plan):
            commands = self.dds.indices_to_commands(plan)
            state = ss.state_from_commands(commands)
            xy = ss.xy_from_state(state)
            return 5 * xy
                    
        f = r.figure(cols=2)
        nolabel = lambda _: ''
        with f.data_file('planlength', MIME_PNG) as filename:
            draw_node_graph(filename=filename,
                            G=self.G,
                            pos_func=point_func,
                            #label_func=label_plan_length,
                            label_func=nolabel,
                            color_func=label_plan_length)
         
        with f.data_file('nchildopen', MIME_PNG) as filename:
            draw_node_graph(filename=filename,
                        G=self.G,
                        pos_func=point_func,
#                        label_func=label_child_open,
                        label_func=nolabel,
                        color_func=label_child_open)
    
        with f.data_file('info', MIME_PNG) as filename:
            draw_node_graph(filename=filename,
                        G=self.G,
                        pos_func=point_func,
                        #label_func=lambda x: '%.2f' % self.visibility(x),
                        label_func=nolabel,
                        color_func=self.visibility)
            
            
        with f.plot('visible') as pylab:
            v = map(self.visibility, self.G)
            pylab.hist(v, 100)

        with r.subsection('embedding') as s:
            self.draw_embeddings(s)
        
        all_plans = list(self.G.nodes())
        random.shuffle(all_plans)
        random_plans = all_plans[:3]
        for pi, ref_plan in enumerate(random_plans):
            color_func = lambda p2: self.plan_distance(ref_plan, p2)
                                            #diffeoaction_distance_L2_infow)
            name = 'random%d' % pi
            with f.data_file(name, MIME_PNG) as filename:
                draw_node_graph(filename=filename,
                        G=self.G,
                        pos_func=point_func,
                        #label_func=lambda x: '%.2f' % self.visibility(x),
                        label_func=nolabel,
                        color_func=color_func)