Ejemplo n.º 1
0
Archivo: id.py Proyecto: argenos/pgm
    def __init__(self, name, nodes=None, edges=None):
        print 'Influence Diagram'
        self.title = name
        self.net = nx.DiGraph(title=name)
        self._moralgraph = nx.Graph(title=name + '_moral')

        if nodes is None:
            self.nodes = []
        else:
            self.nodes = [n.node for n in nodes]
            self.net.add_nodes_from(self.nodes)

        self.chance, self.decision, self.utility = node_types(self.net)

        if edges is None:
            self.edges = []
        else:
            self.edges = [(e[0].name, e[1].name) for e in edges]
            self.net.add_edges_from(self.edges)

        self.windows = {}
        self.order = {}
        self.temporal_order()
Ejemplo n.º 2
0
Archivo: id.py Proyecto: argenos/pgm
    def __init__(self, graph):
        """
        Domain graph of influence diagram.
        Remove information links, adds moral links, removes directions and utility nodes.
        :param graph:
        :return:
        """
        """
        :param graph:
        :return:
        """
        self.graph = graph.copy()
        # draw_graph(self.graph, '1_graph')

        self.chance, self.decision, self.utility = node_types(self.graph)

        # Remove information links
        for n in self.decision:
            for p in self.graph.predecessors(n):
                self.graph.remove_edge(p, n)
        # draw_graph(self.graph, "2_no_info_links")

        # Add moral links
        moral_edges = []
        for n in self.graph.nodes_iter():
            moral_edges.extend(list(combinations(self.graph.predecessors(n), 2)))
        self.graph.add_edges_from(moral_edges)
        # k[::-1] reverses a tuple
        # draw_graph(self.graph, '3_moral_links')

        # Convert to undirected graph
        self.ugraph = self.graph.to_undirected()
        # draw_graph(self.ugraph, '4_undirected')
        # print self.ugraph.node
        # Remove utility nodes
        self.ugraph.remove_nodes_from(self.utility)