Example #1
0
def has_no_cycle(graph: 'Graph'):
    nx_graph, _ = graph_structure_as_nx_graph(graph)
    cycled = list(simple_cycles(nx_graph))
    if len(cycled) > 0:
        raise ValueError(f'{ERROR_PREFIX} Graph has cycles')

    return True
Example #2
0
 def get_nodes_degrees(self):
     """ Nodes degree as the number of edges the node has:
      k = k(in) + k(out)"""
     graph, _ = graph_structure_as_nx_graph(self._graph)
     index_degree_pairs = graph.degree
     node_degrees = [node_degree[1] for node_degree in index_degree_pairs]
     return node_degrees
Example #3
0
def has_no_isolated_components(graph: 'Graph'):
    nx_graph, _ = graph_structure_as_nx_graph(graph)
    ud_nx_graph = nx.Graph()
    ud_nx_graph.add_nodes_from(nx_graph)
    ud_nx_graph.add_edges_from(nx_graph.edges)
    if not nx.is_connected(ud_nx_graph):
        raise ValueError(f'{ERROR_PREFIX} Graph has isolated components')
    return True
Example #4
0
def has_no_isolated_nodes(graph: 'Graph'):
    nx_graph, _ = graph_structure_as_nx_graph(graph)
    isolated = list(isolates(nx_graph))
    if len(isolated) > 0 and graph.length != 1:
        raise ValueError(f'{ERROR_PREFIX} Graph has isolated nodes')
    return True
Example #5
0
def _has_no_duplicates(graph):
    _, labels = graph_structure_as_nx_graph(graph)
    list_of_nodes = [str(node) for node in labels.values()]
    if len(list_of_nodes) != len(set(list_of_nodes)):
        raise ValueError('Custom graph has duplicates')
    return True
Example #6
0
 def evaluate(self, data: pd.DataFrame):
     nodes = data.columns.to_list()
     _, labels = graph_structure_as_nx_graph(self)
     return len(nodes)
Example #7
0
def custom_metric(custom_model: CustomModel):
    _, labels = graph_structure_as_nx_graph(custom_model)

    return [-len(labels) + custom_model.evaluate()]