graphkit#
_normed_OCE#
- gunfolds.utils.graphkit._normed_OCE(g1, g2)[source]#
Return omission and comission errors for directed and bidirected edges.
Omission error is normalized by the number of edges present in the ground truth. Commision error is normalized by the number of possible edges minus the number of edges present in the ground truth.
- Parameters:
g1 (dictionary (
gunfolds
graph)) – the graph to checkg2 (dictionary (
gunfolds
graph)) – the ground truth graph
- Returns:
normalized omission and comission errors for directed and bidirected edges.
- Return type:
dictionary
_normed_undirected_OCE#
- gunfolds.utils.graphkit._normed_undirected_OCE(g1, g2)[source]#
Return omission and comission errors for undirected edges.
Omission error is normalized by the number of edges present in the ground truth. Commision error is normalized by the number of possible edges minus the number of edges present in the ground truth.
- Parameters:
g1 (dictionary (
gunfolds
graph)) – the graph to checkg2 (dictionary (
gunfolds
graph)) – the ground truth graph
- Returns:
omission and comission errors for normalized undirected edges
- Return type:
dictionary
_OCE#
- gunfolds.utils.graphkit._OCE(g1, g2)[source]#
Omission/commision error of
g1
referenced tog2
- Parameters:
g1 (dictionary (
gunfolds
graph)) – the graph to checkg2 (dictionary (
gunfolds
graph)) – the ground truth graph
- Returns:
Omission/commision error for directed and bidirected edges
- Return type:
dictionary
_undirected_OCE#
- gunfolds.utils.graphkit._undirected_OCE(g1, g2)[source]#
Returns omission/commision error of
g1
referenced tog2
if both are undirected graphs.- Parameters:
g1 (dictionary (
gunfolds
graph)) – the graph to checkg2 (dictionary (
gunfolds
graph)) – the ground truth graph
- Returns:
omission and comission errors for undirected edges
- Return type:
dictionary
addanedge#
addAring#
addedges#
bedgelist#
bidirected_no_fork#
bp_mean_degree_graph#
- gunfolds.utils.graphkit.bp_mean_degree_graph(node_num, degree, seed=None)[source]#
Generates a random bipartite graph with
node_num
, nodes and mean outgoing degree (degree
)- Parameters:
node_num (integer) – number of nodes
degree (float) – degree
seed (integer) – random seed
- Returns:
a random bipartite graph with
node_num
, nodes and mean outgoing degree ofdegree
- Return type:
dictionary(
gunfolds
graph)
bp_pow_degree_graph#
- gunfolds.utils.graphkit.bp_pow_degree_graph(node_num, degree, prob=0.7)[source]#
Generates a bipartite graph by powerlaw sequence of
degree
constructed using the Havel-Hakimi algorithm.- Parameters:
node_num (integer) – number of nodes
degree (integer) – degree
prob (float) – probability
- Returns:
a bipartite graph constructed using the Havel-Hakimi algorithm.
- Return type:
dictionary(
gunfolds
graph)
cerror#
clean_leaf_nodes#
complement#
degree_ring#
delanedge#
deledges#
density#
digonly#
edgelist#
ensure_gcd1#
ensure_graph_gcd1#
- gunfolds.utils.graphkit.ensure_graph_gcd1(g, ignore_singletons=True)[source]#
This function takes any graph, breaks it into SCCs and make sure each SCC has a gcd of 1
- Parameters:
g (dictionary (
gunfolds
graph)) –gunfolds
graphignore_singletons (boolean) – ignores singleton SCCs when adding a self-loop to make gcd=1
- Returns:
a graph with
gcd=1
- Return type:
dictionary (
gunfolds
graph)
fullyconnected#
gcd1_bp_mean_degree_graph#
gcd4scc#
gtranspose#
inbedgelist#
inedgelist#
isdedgesubset#
- gunfolds.utils.graphkit.isdedgesubset(g2star, g2)[source]#
Checks if
g2star
directed edges are a subset of those ofg2
- Parameters:
g2star (dictionary (
gunfolds
graph)) –gunfolds
graph to be checkedg2 (dictionary (
gunfolds
graph)) –gunfolds
graph
- Returns:
True, if
g2star
directed edges are a subset of those ofg2
and vice versa- Return type:
boolean
isedgesubset#
- gunfolds.utils.graphkit.isedgesubset(g2star, g2)[source]#
Checks if all
g2star
edges are a subset of those ofg2
- Parameters:
g2star (dictionary (
gunfolds
graph)) –gunfolds
graph to be checkedg2 (dictionary (
gunfolds
graph)) –gunfolds
graph
- Returns:
True, if all
g2star
edges are a subset of those ofg2
and vice versa- Return type:
boolean
mean_degree_graph#
- gunfolds.utils.graphkit.mean_degree_graph(node_num, degree)[source]#
Generates a random graph with
node_num
, nodes and mean outgoing degree ofdegree
.- Parameters:
node_num (integer) – number of nodes
degree (integer) – degree
- Returns:
a random graph with mean outgoing degree of the given graph
- Return type:
dictionary(
gunfolds
graph)
merge_graphs#
- gunfolds.utils.graphkit.merge_graphs(glist)[source]#
Merge a list of graphs at
u=1
into a single new graphg
- Parameters:
glist (list of dictionaries (
gunfolds
graphs)) – a list of graphs that are undersampled versions of the same system- Returns:
a new graph by merging a list of graphs at
u=1
- Return type:
dictionary (
gunfolds
graph)
merge_list#
no_children#
no_parents#
OCE#
- gunfolds.utils.graphkit.OCE(g1, g2, normalized=False, undirected=False)[source]#
Return omission and comission errors for graphs.
- Parameters:
g1 (dictionary (
gunfolds
graph)) – the graph to checkg2 (dictionary (
gunfolds
graph)) – the ground truth graphnormalized (boolean) – If True, returns normalized error and vice versa
undirected (boolean) – If True, returns undirected error and vice versa
- Returns:
omission and comission errors for graphs
- Return type:
dictionary
oerror#
pow_degree_graph#
- gunfolds.utils.graphkit.pow_degree_graph(node_num, degree)[source]#
Generates a graph by powerlaw sequence of
degree
constructed using the Havel-Hakimi algorithm.- Parameters:
node_num (integer) – number of nodes
degree (integer) – degree
- Returns:
a graph constructed using the Havel-Hakimi algorithm.
- Return type:
dictionary(
gunfolds
graph)
randH#
- gunfolds.utils.graphkit.randH(n, d1, d2)[source]#
Generate a random H with
n
nodes- Parameters:
n (integer) – number of nodes
d1 (integer) – number of additional edges to the ring
d2 (integer) – (ask) number of random permutations
- Returns:
a random graph with
n
nodes- Return type:
dictionary (
gunfolds
graph)
randomDAG#
randomTRIL#
- gunfolds.utils.graphkit.randomTRIL(N, degree=5, connected=False)[source]#
Generate a random triangular matrix
https://stackoverflow.com/a/56514463
- Parameters:
N (integer) – size of the matrix
degree (integer) – degree
connected (boolean) – (Ask)
- Returns:
a random triangular adjacency matrix
- Return type:
numpy array
remove_loop#
remove_tril_singletons#
- gunfolds.utils.graphkit.remove_tril_singletons(T)[source]#
Ensure that the DAG resulting from this matrix will not have singleton nodes not connected to anything.
- Parameters:
T (numpy array) – lower triangular matrix representing a DAG
- Returns:
adjacency matrix where no singleton nodes are connected to anything
- Return type:
numpy array
ring#
ring_sccs#
- gunfolds.utils.graphkit.ring_sccs(num, num_sccs, dens=0.5, degree=3, max_cross_connections=3)[source]#
Generate a random graph with
num_sccs
SCCs, n-nodes each- Parameters:
num (integer) – number of nodes in each sec
num_sccs (integer) – number of secs
dens (float) – density of each sac
degree (integer) – degree of the connecting DAG
max_cross_connections (integer) – maximum number of connections per each edge in DAG
- Returns:
a random graph with
num_sccs
SCCs, n-nodes each- Return type:
dictionary (
gunfolds
graph)
ringarcs#
ringmore#
scale_free#
- gunfolds.utils.graphkit.scale_free(n, alpha=0.7, beta=0.25, delta_in=0.2, delta_out=0.2)[source]#
(Copied from scale_free function in networkx should i need to add any citation)
- Parameters:
n (integer) – number of nodes
alpha (float) – probability for adding a new node connected to an existing node
beta (float) – probability for adding an edge between two existing nodes.
delta_in (float) – bias for choosing nodes from in-degree
delta_out (float) – bias for choosing nodes from out-degree distribution.
- Returns:
- Return type:
scc_unreachable#
- gunfolds.utils.graphkit.scc_unreachable(g)[source]#
Checks if there exists a strongly connected component in the given graph
g
that is unreachable.- Parameters:
g (dictionary (
gunfolds
graph)) –gunfolds
graph- Returns:
True, if there exists SCC that is unreachable. False, otherwise.
- Return type:
boolean
selfloop#
shift_labels#
shift_list_labels#
subgraph#
- gunfolds.utils.graphkit.subgraph(g, nodes)[source]#
Returns a subgraph of
g
that consists ofnodes
and their interconnections.- Parameters:
g (dictionary (
gunfolds
graph)) –gunfolds
graphnodes (list) – integer valued nodes to include
- Returns:
a subgraph of
g
that consists ofnodes
and their interconnections.- Return type:
dictionary(
gunfolds
graph)
superclique#
udensity#
undedgelist#
- gunfolds.utils.graphkit.undedgelist(g, exclude_bi=False)[source]#
Returns a list of tuples for undirected edges of
g
with nodes sorted in ascending order.- Parameters:
g (dictionary (
gunfolds
graph)) –gunfolds
graphexclude_bi (boolean) – if True, only converts directed edges to undirected edges. If False, converts directed and bidirected edges to undirected edges
- Returns:
a list of tuples for undirected edges of
g
with nodes sorted in ascending order- Return type:
list
upairs#
update_graph#
- gunfolds.utils.graphkit.update_graph(g, g2)[source]#
Update
g
with connections (or nodes) fromg2
. Both must be atu=1
- Parameters:
g (dictionary (
gunfolds
graph)) – graph to be updatedg2 (dictionary (
gunfolds
graph)) – reference graph
- Returns:
updated
g
with respect tog2
- Return type:
dictionary (
gunfolds
graph)