Graph Measure extraction example¶
This example will show you how to save the graph measurement results as CSV file.
In [1]:
Copied!
import numpy as np
from photonai_graph.GraphUtilities import get_random_connectivity_data
from photonai_graph.GraphMeasureTransform import GraphMeasureTransform
from photonai_graph.GraphConstruction.graph_constructor_threshold import GraphConstructorThreshold
import numpy as np
from photonai_graph.GraphUtilities import get_random_connectivity_data
from photonai_graph.GraphMeasureTransform import GraphMeasureTransform
from photonai_graph.GraphConstruction.graph_constructor_threshold import GraphConstructorThreshold
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 4 1 import numpy as np 3 from photonai_graph.GraphUtilities import get_random_connectivity_data ----> 4 from photonai_graph.GraphMeasureTransform import GraphMeasureTransform 5 from photonai_graph.GraphConstruction.graph_constructor_threshold import GraphConstructorThreshold ModuleNotFoundError: No module named 'photonai_graph.GraphMeasureTransform'
Generate random matrices to simulate connectivity matrices
In [2]:
Copied!
X = get_random_connectivity_data(number_of_nodes=50, number_of_individuals=200)
X = get_random_connectivity_data(number_of_nodes=50, number_of_individuals=200)
Instantiate a constructor to threshold the graphs
In [3]:
Copied!
g_constructor = GraphConstructorThreshold(threshold=0.95)
g_constructor = GraphConstructorThreshold(threshold=0.95)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[3], line 1 ----> 1 g_constructor = GraphConstructorThreshold(threshold=0.95) NameError: name 'GraphConstructorThreshold' is not defined
Instantiate the measure_transformer
In [4]:
Copied!
g_measure_transformer = GraphMeasureTransform(graph_functions={"global_efficiency": {},
"local_efficiency": {},
"average_clustering": {},
"degree_centrality": {},
"betweenness_centrality": {},
"overall_reciprocity": {}})
X_trans = g_constructor.transform(X)
g_measure_transformer.extract_measures(X_trans, path="test_measures.csv", ids=np.arange(200))
g_measure_transformer = GraphMeasureTransform(graph_functions={"global_efficiency": {},
"local_efficiency": {},
"average_clustering": {},
"degree_centrality": {},
"betweenness_centrality": {},
"overall_reciprocity": {}})
X_trans = g_constructor.transform(X)
g_measure_transformer.extract_measures(X_trans, path="test_measures.csv", ids=np.arange(200))
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 1 ----> 1 g_measure_transformer = GraphMeasureTransform(graph_functions={"global_efficiency": {}, 2 "local_efficiency": {}, 3 "average_clustering": {}, 4 "degree_centrality": {}, 5 "betweenness_centrality": {}, 6 "overall_reciprocity": {}}) 8 X_trans = g_constructor.transform(X) 10 g_measure_transformer.extract_measures(X_trans, path="test_measures.csv", ids=np.arange(200)) NameError: name 'GraphMeasureTransform' is not defined
This will generate an example CSV file containing the measurement results for each graph.