Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pwollstadt committed Dec 2, 2018
2 parents 1d61737 + 65aa8e3 commit 1585d14
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 156 deletions.
18 changes: 14 additions & 4 deletions idtxl/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Data():
>>> data_2.set_data(data_new, 's')
Note:
Realisations are stored as attribute 'data'. This can only be set via
Realisations are stored as attribute 'data'. This can only be set via
the 'set_data()' method.
Args:
Expand Down Expand Up @@ -828,16 +828,26 @@ def generate_mute_data(self, n_samples=1000, n_replications=10):
Generate example data and overwrite the instance's current data. The
network is used as an example the paper on the MuTE toolbox (Montalto,
PLOS ONE, 2014, eq. 14). The network consists of five autoregressive
(AR) processes with model orders 2 and the following (non-linear)
couplings:
PLOS ONE, 2014, eq. 14) and was orginially proposed by Baccala &
Sameshima (2001). The network consists of five autoregressive (AR)
processes with model orders 2 and the following (non-linear) couplings:
0 -> 1, u = 2 (non-linear)
0 -> 2, u = 3
0 -> 3, u = 2 (non-linear)
3 -> 4, u = 1
4 -> 3, u = 1
References:
- Montalto, A., Faes, L., & Marinazzo, D. (2014) MuTE: A MATLAB toolbox
to compare established and novel estimators of the multivariate
transfer entropy. PLoS ONE 9(10): e109462.
https://doi.org/10.1371/journal.pone.0109462
- Baccala, L.A. & Sameshima, K. (2001). Partial directed coherence: a
new concept in neural structure determination. Biol Cybern 84:
463–474. https://doi.org/10.1007/PL00007990
Args:
n_samples : int
number of samples simulated for each process and replication
Expand Down
13 changes: 9 additions & 4 deletions idtxl/estimators_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Bertschinger, N., Rauh, J., Olbrich, E., Jost, J., & Ay, N. (2014). Quantifying
Unique Information. Entropy, 16(4), 2161–2183. http://doi.org/10.3390/e16042161
"""
import numpy as np
from . import synergy_tartu
Expand All @@ -17,9 +16,9 @@
class SydneyPID(Estimator):
"""Estimate partial information decomposition of discrete variables.
Fast implementation of the partial information decomposition (PID)
estimator for discrete data. The estimator does not require JAVA or GPU
modules to run.
Fast implementation of the BROJA partial information decomposition (PID)
estimator for discrete data (Bertschinger, 2014). The estimator does not
require JAVA or GPU modules to run.
The estimator finds shared information, unique information and
synergistic information between the two inputs s1 and s2 with respect to
Expand All @@ -34,6 +33,12 @@ class SydneyPID(Estimator):
CMI decreases; and an outer loop which decreases the size of the
probability mass increment the virtualised swapping utilises.
References
- Bertschinger, N., Rauh, J., Olbrich, E., Jost, J., & Ay, N. (2014).
Quantifying unique information. Entropy, 16(4), 2161–2183.
http://doi.org/10.3390/e16042161
Args:
settings : dict
estimation parameters
Expand Down
20 changes: 9 additions & 11 deletions idtxl/idtxl_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class for directed graphs (DiGraph). Multiple options for the weight are
available (see documentation of method get_adjacency_matrix for details).
Args:
adjacency_matrix : 2D numpy array
adjacency_matrix : AdjacencyMatrix instances
adjacency matrix to be exported, returned by get_adjacency_matrix()
method of Results() class
weights : str
Expand All @@ -389,9 +389,9 @@ class for directed graphs (DiGraph). Multiple options for the weight are
"""
# use 'weights' parameter (string) as networkx edge property name and use
# adjacency matrix entries as edge property values
custom_type = [(weights, type(adjacency_matrix[0, 0]))]
custom_npmatrix = np.matrix(adjacency_matrix, dtype=custom_type)
return nx.from_numpy_matrix(custom_npmatrix, create_using=nx.DiGraph())
G = nx.DiGraph()
G.add_weighted_edges_from(adjacency_matrix.get_edge_list(), weights)
return G


def export_networkx_source_graph(results, target, sign_sources=True, fdr=True):
Expand All @@ -410,7 +410,7 @@ def export_networkx_source_graph(results, target, sign_sources=True, fdr=True):
target : int
target index
sign_sources : bool [optional]
add only sources with significant information contribution
add sources with significant information contribution only
(default=True)
fdr : bool [optional]
return FDR-corrected results (default=True)
Expand Down Expand Up @@ -494,7 +494,7 @@ def export_brain_net_viewer(adjacency_matrix, mni_coord, file_name, **kwargs):
https://doi.org/10.1371/journal.pone.0068910
Args:
adjacency_matrix : 2D numpy array
adjacency_matrix : AdjacencyMatrix instance
adjacency matrix to be exported, returned by get_adjacency_matrix()
method of Results() class
mni_coord : numpy array
Expand All @@ -516,15 +516,13 @@ def export_brain_net_viewer(adjacency_matrix, mni_coord, file_name, **kwargs):
"""
# Check input and get default settings for plotting. The default for
# node labels is a list of '-' (no labels).
n_nodes = adjacency_matrix.shape[0]
n_edges = np.sum(adjacency_matrix > 0)
n_nodes = adjacency_matrix.n_nodes()
n_edges = adjacency_matrix.n_edges()
labels = kwargs.get('labels', ['-' for i in range(n_nodes)])
node_color = kwargs.get('node_color', np.ones(n_nodes))
node_size = kwargs.get('node_size', np.ones(n_nodes))
if n_edges == 0:
Warning('No edges in results file. Nothing to plot.')
assert adjacency_matrix.shape[0] == adjacency_matrix.shape[1], (
'Adjacency matrix must be quadratic.')
assert mni_coord.shape[0] == n_nodes and mni_coord.shape[1] == 3, (
'MNI coordinates must have shape [n_nodes, 3].')
assert len(labels) == n_nodes, (
Expand All @@ -551,6 +549,6 @@ def export_brain_net_viewer(adjacency_matrix, mni_coord, file_name, **kwargs):
with open('{0}.edge'.format(file_name), 'w') as text_file:
for i in range(n_nodes):
for j in range(n_nodes):
print('{0}\t'.format(adjacency_matrix[i, j]),
print('{0}\t'.format(adjacency_matrix._edge_matrix[i, j]),
file=text_file, end='')
print('', file=text_file)
4 changes: 2 additions & 2 deletions idtxl/network_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def compare_links_within(self, settings, link_a, link_b, network, data):
settings=self.settings,
union_network=self.union,
results={
'cmi_diff_abs': {link_a[1]: [np.abs(self.cmi_diff)],
link_b[1]: [np.abs(self.cmi_diff)]},
'cmi_diff_abs': {link_a[1]: np.abs(self.cmi_diff),
link_b[1]: np.abs(self.cmi_diff)},
'a>b': {link_a[1]: [te_a > te_b], link_b[1]: [te_a > te_b]},
'pval': {link_a[1]: [pvalue], link_b[1]: [pvalue]},
'cmi_surr': self.cmi_surr,
Expand Down
Loading

0 comments on commit 1585d14

Please sign in to comment.