internal#

adjs2graph#

gunfolds.conversions.adjs2graph(directed, bidirected)[source]#

Convert an adjacency matrix of directed and bidirected edges to a graph

Parameters:
  • directed (numpy matrix) – graph adjacency matrix for directed edges

  • bidirected (numpy matrix) – graph adjacency matrix for bidirected edges

Returns:

gunfolds format graph

Return type:

dictionary (gunfolds graphs)

bg2num#

gunfolds.conversions.bg2num(g)[source]#

Convert bidirected edges into a binary format

Parameters:

g (dictionary (gunfolds graphs)) – gunfolds graph

Returns:

unique number for each graph considering bidirected in binary format

Return type:

a tuple of binary integer

dict_format_converter#

gunfolds.conversions.dict_format_converter(H)[source]#

Convert a graph from the set style dictionary format to the integer style

Parameters:

H (dictionary) – set style dictionary format

Returns:

gunfolds graph

Return type:

dictionary (gunfolds graphs)

>>> test = {'1': {'1': {(0, 1)},
...   '2': {(0, 1), (2, 0)},
...   '3': {(0, 1), (2, 0)},
...   '4': {(2, 0)},
...   '5': {(0, 1)}},
...  '2': {'1': {(2, 0)}, '2': {(0, 1)}, '5': {(0, 1), (2, 0)}},
...  '3': {'1': {(0, 1), (2, 0)}, '2': {(0, 1)}, '5': {(0, 1)}},
...  '4': {'1': {(2, 0)},
...   '2': {(0, 1)},
...   '3': {(0, 1)},
...   '4': {(0, 1)},
...   '5': {(0, 1)}},
...  '5': {'1': {(0, 1)}, '2': {(0, 1), (2, 0)}, '5': {(0, 1)}}}
>>> dict_format_converter(test)
{1: {1: 1, 2: 3, 3: 3, 4: 2, 5: 1}, 2: {1: 2, 2: 1, 5: 3}, 3: {1: 3, 2: 1, 5: 1}, 4: {1: 2, 2: 1, 3: 1, 4: 1, 5: 1}, 5: {1: 1, 2: 3, 5: 1}}
>>>

edgepairs2g#

gunfolds.conversions.edgepairs2g(edgepairs)[source]#

Converts edge pairs to a gunfolds graph

Parameters:

edgepairs (list) – list of edge pairs

Returns:

gunfolds graph

Return type:

dictionary (gunfolds graph)

g2ian#

gunfolds.conversions.g2ian(g)[source]#

(Ask)

Parameters:

g (dictionary (gunfolds graphs)) – gunfolds graph

Returns:

gunfolds graph

Return type:

dictionary (gunfolds graphs)

g2num#

gunfolds.conversions.g2num(g)[source]#

Convert a graph into a long int

Parameters:

g (dictionary (gunfolds graphs)) – gunfolds graph

Returns:

unique number for each graph considering only directed edges

Return type:

long integer

g2vec#

gunfolds.conversions.g2vec(g)[source]#

Converts gunfolds graph to a vector

Parameters:

g (dictionary (gunfolds graphs)) – gunfolds graph

Returns:

a vector representing a gunfolds graph

Return type:

numpy vector

Glag2CG#

gunfolds.conversions.Glag2CG(results)[source]#

Converts lag graph format to gunfolds graph format, and A and B matrices representing directed and bidirected edges weights.

Parameters:

results (dict) – A dictionary containing: - ‘graph’: A 3D NumPy array of shape [N, N, 2] representing the graph structure. - ‘val_matrix’: A NumPy array of shape [N, N, 2] storing edge weights.

Returns:

(graph_dict, A_matrix, B_matrix)

Return type:

tuple

graph2adj#

gunfolds.conversions.graph2adj(G)[source]#

Convert the directed edges to an adjacency matrix

Parameters:

G (dictionary (gunfolds graphs)) – gunfolds format graph

Returns:

graph adjacency matrix for directed edges

Return type:

numpy matrix

graph2badj#

gunfolds.conversions.graph2badj(G)[source]#

Convert the bidirected edges to an adjacency matrix

Parameters:

G (dictionary (gunfolds graphs)) – gunfolds format graph

Returns:

graph adjacency matrix for bidirected edges

Return type:

numpy matrix

ian2g#

gunfolds.conversions.ian2g(g)[source]#

(Ask)

Parameters:

g (dictionary (gunfolds graphs)) – gunfolds graph

Returns:

(Ask)

Return type:

(Ask)

nodenum#

gunfolds.conversions.nodenum(edgepairs)[source]#

Returns the number of nodes in the graph

Parameters:

edgepairs (list) – list of edge pairs

Returns:

number of nodes in the graph

Return type:

integer

num2CG#

gunfolds.conversions.num2CG(num, n)[source]#

Converts a number whose binary representaion encodes edge presence/absence into a compressed graph representaion

Parameters:
  • num (integer) – unique graph representation in numbers

  • n (integer) – number of nodes

Returns:

gunfolds graph

Return type:

dictionary (gunfolds graphs)

nxbp2graph#

gunfolds.conversions.nxbp2graph(G)[source]#

Ask

Parameters:

G (dictionary (gunfolds graphs)) – gunfolds format graph

Returns:

Ask

Return type:

ug2num#

gunfolds.conversions.ug2num(g)[source]#

Convert non-empty edges into a tuple of (directed, bidriected) in binary format

Parameters:

g (dictionary (gunfolds graphs)) – gunfolds graph

Returns:

unique number for each graph considering directed and bidirected in binary format

Return type:

a tuple of binary integer

vec2adj#

gunfolds.conversions.vec2adj(v, n)[source]#

Converts a vector representation to adjacency matrix

Parameters:
  • v (numpy vector) – vector representation of gunfolds graph

  • n (integer) – number of nodes

Returns:

a tuple of Adjacency matrices

Return type:

a tuple of numpy matrices

vec2g#

gunfolds.conversions.vec2g(v, n)[source]#

Converts a vector representation to gunfolds graph

Parameters:
  • v (numpy vector) – vector representation of gunfolds graph

  • n (integer) – number of nodes

Returns:

gunfolds format graph

Return type:

dictionary (gunfolds graphs)