Skip to content

Commit

Permalink
Merge pull request #23 from neuroneural/glag2gc
Browse files Browse the repository at this point in the history
added conversion function from graph lag format to compressd gunfolds…
  • Loading branch information
sajadabvi authored Feb 21, 2024
2 parents 8ed7d65 + 996f18d commit 308da18
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions gunfolds/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,26 @@ def encode_list_sccs(glist, scc_members=None):
# if there is an edge between SCCs in the produced graph and none in the measured for nonsingleton SCCs - no go
s += ':- directed(X,Y,U), scc(X,K), scc(Y,L), K != L, sccsize(L,Z), Z > 1, not dag(K,L,N), u(U,N).'
return s

def Glag2CG(results):
"""Converts lag graph format to gunfolds graph format,
and A and B matrices representing directed and bidirected edges weights.
Args:
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:
tuple: (graph_dict, A_matrix, B_matrix)
"""

graph_array = results['graph']
bidirected_edges = np.where(graph_array == 'o-o', 1, 0).astype(int)
directed_edges = np.where(graph_array == '-->', 1, 0).astype(int)

graph_dict = adjs2graph(np.transpose(directed_edges[:, :, 1]), np.transpose((bidirected_edges[:, :, 0])))
A_matrix = results['val_matrix'][:, :, 1]
B_matrix = results['val_matrix'][:, :, 0]

return graph_dict, A_matrix, B_matrix

0 comments on commit 308da18

Please sign in to comment.