text stringlengths 1 93.6k |
|---|
G.add_edges_from(edgelist) # add edges to graph
|
return G
|
def filter_Graph(G,filter_set):
|
"""
|
This allows us to apply a set of filters encoded as closures/first-order functions that take a graph as input and return a graph as output.
|
"""
|
graph = G.copy()
|
for f in filter_set:
|
graph = f(graph)
|
return graph
|
def partialConditionalSubgraphs(G,edge_set,condition_list):
|
try:
|
condition_list[0]
|
except TypeError:
|
raise TypeError("""
|
Subsampling from a graph requires passing in a list of conditions encoded
|
as first-class functions that accept networkX graphs as an input and return boolean values.""")
|
edge_powerset = powerset(edge_set)
|
for edges in powerset(edge_set):
|
G_test = G.copy()
|
G_test.remove_edges_from(edges)
|
if all([c(G_test) for c in condition_list]):
|
yield G_test
|
def conditionalSubgraphs(G,condition_list):
|
"""
|
Returns a graph generator/iterator such that any conditions specified in condition_list
|
are met by some subgraph of G.
|
This is intended to be used in conjunction with completeDiGraph or any graph which subgraphs
|
are expected to be taken.
|
Variables:
|
G is a graph from which subgraphs will be taken.
|
condition_list is a list of first order functions that will be applied to filter the subgraphs of G.
|
Functions in condition_list should return a single boolean value for every graph passed into them.
|
"""
|
try:
|
condition_list[0]
|
except TypeError:
|
raise TypeError("""
|
Subsampling from a graph requires passing in a list of conditions encoded
|
as first-class functions that accept networkX graphs as an input and return boolean values.""")
|
# edge_powerset = powerset(G.edges())
|
for edges in powerset(G.edges()):
|
G_test = G.copy()
|
G_test.remove_edges_from(edges)
|
if all([c(G_test) for c in condition_list]):
|
yield G_test
|
def create_path_complete_condition(transmit_node_pairs):
|
"""
|
This creates a closure that takes a graph as its input and returns a boolean value indicating whether the pairs of nodes in transmit_node_pairs are able to communicate from each tuple in transmit_node_pairs such that there is a path from transmit_node_pairs[i][0] to transmit_node_pairs[i][1]
|
"""
|
def path_complete_condition(G):
|
return all([nx.has_path(G,x,y) for x,y in transmit_node_pairs])
|
return path_complete_condition
|
def create_no_input_node_condition(node_list):
|
def no_input_node_condition(G):
|
return all([G.in_degree(y)==0 for y in node_list])
|
return no_input_node_condition
|
def create_is_dag_condition(node_list):
|
def is_dag_condition(G):
|
return nx.is_directed_acyclic_graph(G)
|
return is_dag_condition
|
def create_no_self_loop_condition():
|
"""
|
returns
|
"""
|
def no_self_loop_condition(G):
|
return not(any([(y,y) in G.edges() for y in G.nodes()]))
|
return no_self_loop_filter
|
def create_explicit_parent_condition(parentage_tuple_list):
|
"""
|
This states for a child node, what its explicit parents are.
|
"""
|
def explicit_parent_condition(G):
|
return all(
|
[sorted(G.in_edges(y[0])) == sorted([(x,y[0]) for x in y[1]])
|
for y in parentage_tuple_list])
|
return explicit_parent_condition
|
def create_explicit_child_condition(parentage_tuple_list):
|
"""
|
This states for a parent node, what its explicit children are.
|
"""
|
def explicit_child_condition(G):
|
return all(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.