Skip to content

Export networkx graph

Patricia Wollstadt edited this page Jul 18, 2018 · 1 revision

IDTxl allows to export inferred networks to the networkx Python package. The networkx package provides plotting functionalities, graph algorithms, and further export functions. The inferred network is exported as a weighted, directed graph object DiGraph().

Import IO functions and load example data

import pickle
from idtxl import idtxl_io as io

results = pickle.load(open('test/data/mute_results_0.p', 'rb'))

Export inferred network graph

Example: export inferred network, using the lag of the past variable with maximum information transfer into the target to weight edges

weights = 'max_te_lag'
adj_matrix = results.get_adjacency_matrix(weights=weights, fdr=False)
io.export_networkx_graph(adjacency_matrix=adj_matrix, weights=weights)

Export graph of selected source variables

Example: export graph of inferred past variables for a single target

io.export_networkx_source_graph(
    results=results, target=1, sign_sources=True, fdr=False)

By setting sign_sources to True only significant sources are included, otherwise all sources in the cadidate set are plotted.

Clone this wiki locally