Exemplo n.º 1
0
 def _sample_adjacency_matrix_without_loose_ends(self, adjacency_matrix, node):
     req_num_parents = self.num_parents_per_node[str(node)]
     current_num_parents = np.sum(adjacency_matrix[:, node], dtype=np.int)
     num_parents_left = req_num_parents - current_num_parents
     sampled_parents = \
         random.sample(list(parent_combinations_old(adjacency_matrix, node, n_parents=num_parents_left)), 1)[0]
     for parent in sampled_parents:
         adjacency_matrix[parent, node] = 1
         adjacency_matrix = self._sample_adjacency_matrix_without_loose_ends(adjacency_matrix, parent)
     return adjacency_matrix
Exemplo n.º 2
0
    def _generate_adjacency_matrix(self, adjacency_matrix, node):
        if self._check_validity_of_adjacency_matrix(adjacency_matrix):
            # If graph from search space then yield.
            yield adjacency_matrix
        else:
            req_num_parents = self.num_parents_per_node[str(node)]
            current_num_parents = np.sum(adjacency_matrix[:, node], dtype=np.int)
            num_parents_left = req_num_parents - current_num_parents

            for parents in parent_combinations_old(adjacency_matrix, node, n_parents=num_parents_left):
                # Make copy of adjacency matrix so that when it returns to this stack
                # it can continue with the unmodified adjacency matrix
                adjacency_matrix_copy = copy.copy(adjacency_matrix)
                for parent in parents:
                    adjacency_matrix_copy[parent, node] = 1
                    for graph in self._generate_adjacency_matrix(adjacency_matrix=adjacency_matrix_copy, node=parent):
                        yield graph