|
pathpy
1.0
pathpy is an OpenSource python package for the modeling and analysis of pathways and temporal networks using higher-order and multi-order graphical models
|
Public Member Functions | |
| def | __init__ |
| def | vcount |
| def | ecount |
| def | totalEdgeWeight |
| def | HigherOrderNodeToPath |
| def | pathToHigherOrderNodes |
| def | getNodeNameMap |
| def | getDoF |
| def | getDistanceMatrix |
| def | getShortestPaths |
| def | getDistanceMatrixFirstOrder |
| def | ClosenessCentrality |
| def | EvCent |
| def | PageRank |
| def | HigherOrderPathToFirstOrder |
| def | BetweennessCentrality |
| def | reduceToGCC |
| def | summary |
| def | __str__ |
| def | degrees |
| def | getAdjacencyMatrix |
| def | getTransitionMatrix |
| def | getLaplacianMatrix |
| def | getEigenValueGap |
| def | getFiedlerVectorSparse |
| def | getFiedlerVectorDense |
| def | getAlgebraicConnectivity |
Static Public Member Functions | |
| def | getLeadingEigenvector |
Public Attributes | |
| order | |
| The order of this HigherOrderNetwork. | |
| paths | |
| The paths object used to generate this instance. | |
| nodes | |
| The nodes in this HigherOrderNetwork. | |
| separator | |
| The separator character used to label higher-order nodes. More... | |
| edges | |
| A dictionary containing edges as well as edge weights. | |
| successors | |
| A dictionary containing the list of successors of all nodes. | |
| dof_paths | |
| The degrees of freedom of the higher-order model, under the paths assumption. | |
| dof_ngrams | |
| The degrees of freedom of the higher-order model, under the ngram assumption. | |
Instances of this class capture a k-th-order representation of path statistics. Path statistics can originate from pathway data, temporal networks, or from processes observed on top of a network topology.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.__init__ | ( | self, | |
| paths, | |||
k = 1, |
|||
separator = '-', |
|||
nullModel = False, |
|||
method = 'FirstOrderTransitions', |
|||
lanczosVecs = 15, |
|||
maxiter = 1000 |
|||
| ) |
Generates a k-th-order representation based on the given path statistics.
@param paths: An instance of class Paths, which contains the path statistics to be
used in the generation of the k-th order representation
@param k: The order of the network representation to generate. For the default case of
k=1, the resulting representation corresponds to the usual (first-order) aggregate network,
i.e. links connect nodes and link weights are given by the frequency of each interaction. For
k>1, a k-th order node corresponds to a sequence of k nodes. The weight of a k-th order link
captures the frequency of a path of length k.
@param separator: The separator character to be used in higher-order node names.
@param nullModel: For the default value False, link weights are generated based on the statistics of
paths of length k in the underlying path statistics instance. If True, link weights are generated
from the first-order model (k=1) based on the assumption of independent links (i.e. corresponding)
to a first-order Markov model.
@param method: specifies how the null model link weights in the k-th order model are calculated.
For the default method='FirstOrderTransitions', the weight w('v_1-v_2-...v_k', 'v_2-...-v_k-v_k+1') of
a k-order edge is set to the transition probability T['v_k', 'v_k+1'] in the first order network.
For method='KOrderPi' the entry pi['v1-...-v_k'] in the stationary distribution of the
k-order network is used instead.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.__str__ | ( | self | ) |
Returns the default string representation of this graphical model instance
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.BetweennessCentrality | ( | self, | |
normalized = False |
|||
| ) |
Calculates the betweenness centralities of all nodes.
If the order of the higher-order network is larger than one
centralities calculated based on the higher-order
topology will automatically be projected back to first-order
nodes.
@param normalized: If set to True, betweenness centralities of
nodes will be scaled by the maximum value (default False)
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.ClosenessCentrality | ( | self | ) |
Calculates the closeness centralities of all nodes. If the order of the higher-order network is larger than one centralities calculated based on the higher-order topology will automatically be projected back to first-order nodes.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.degrees | ( | self, | |
includeSubPaths = True, |
|||
weighted = True, |
|||
mode = "OUT" |
|||
| ) |
Returns the (weighted) degrees of nodes in the higher-order network
@param weighted: If true, calculates the sum of weights for each node. If false, the
number of links is calculated
@param mode: either "IN", "OUT", or "TOTAL"
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.ecount | ( | self | ) |
Returns the number of links
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.EvCent | ( | self, | |
projection = 'scaled', |
|||
includeSubPaths = True |
|||
| ) |
Calculates the eigenvector centralities of higher-order nodes. If
the order of the HigherOrderNetwork is larger than one, the centralities
will be projected to the first-order nodes.
@param projection: Indicates how the projection from k-th-order nodes (v1, v2, ... , v{k-1})
shall be performed. For the method 'all', the eigenvector centrality of the higher-order node
will be added to *all* first-order nodes on the path corresponding to the higher-order node. For
the method 'last', the centrality of the higher-order node will only be assigned to *last*
first-order node v{k-1}. For the method 'scaled' (default), the eigenvector centrality of higher-order
nodes will be assigned proportionally to first-order nodes, i.e. each of the three nodes in the
third-order node (a,b,c) will receive one third of the eigenvector centrality of (a,b,c).
@param includeSubPaths: whether or not to include subpath statistics in the calculation (default True)
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getAdjacencyMatrix | ( | self, | |
includeSubPaths = True, |
|||
weighted = True, |
|||
transposed = False |
|||
| ) |
Returns a sparse adjacency matrix of the higher-order network. By default, the entry
corresponding to a directed link source -> target is stored in row s and column t
and can be accessed via A[s,t].
@param includeSubPaths: if set to True, the returned adjacency matrix will
account for the occurrence of links of order k (i.e. paths of length k-1)
as subpaths
@param weighted: if set to False, the function returns a binary adjacency matrix.
If set to True, adjacency matrix entries will contain the weight of an edge.
@param transposed: whether to transpose the matrix or not.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getAlgebraicConnectivity | ( | self, | |
lanczosVecs = 15, |
|||
maxiter = 20 |
|||
| ) |
Returns the algebraic connectivity of the higher-order network.
@param lanczosVecs: number of Lanczos vectors to be used in the approximate
calculation of eigenvectors and eigenvalues. This maps to the ncv parameter
of scipy's underlying function eigs.
@param maxiter: scaling factor for the number of iterations to be used in the
approximate calculation of eigenvectors and eigenvalues. The number of iterations
passed to scipy's underlying eigs function will be n*maxiter where n is the
number of rows/columns of the Laplacian matrix.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getDistanceMatrix | ( | self | ) |
Calculates shortest path distances between all pairs of higher-order nodes using the Floyd-Warshall algorithm.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getDistanceMatrixFirstOrder | ( | self | ) |
Projects a distance matrix from a higher-order to first-order nodes, while path lengths are calculated based on the higher-order topology
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getDoF | ( | self, | |
assumption = "paths" |
|||
| ) |
Calculates the degrees of freedom (i.e. number of parameters) of
this k-order model. Depending on the modeling assumptions, this either
corresponds to the number of paths of length k in the first-order network
or to the number of all possible k-grams. The degrees of freedom of a model
can be used to assess the model complexity when calculating, e.g., the
Bayesian Information Criterion (BIC).
@param assumption: if set to 'paths', for the degree of freedon calculation in the BIC,
only paths in the first-order network topology will be considered. This is
needed whenever we are interested in a modeling of paths in a given network topology.
If set to 'ngrams' all possible n-grams will be considered, independent of whether they
are valid paths in the first-order network or not. The 'ngrams' and the 'paths' assumption
coincide if the first-order network is fully connected.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getEigenValueGap | ( | self, | |
includeSubPaths = True, |
|||
lanczosVecs = 15, |
|||
maxiter = 20 |
|||
| ) |
Returns the eigenvalue gap of the transition matrix.
@param includeSubPaths: whether or not to include subpath statistics in the
calculation of transition probabilities.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getFiedlerVectorDense | ( | self | ) |
Returns the (dense)Fiedler vector of the higher-order network. The Fiedler vector can be used for a spectral bisectioning of the network.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getFiedlerVectorSparse | ( | self, | |
normalized = True, |
|||
lanczosVecs = 15, |
|||
maxiter = 20 |
|||
| ) |
Returns the (sparse) Fiedler vector of the higher-order network. The Fiedler
vector can be used for a spectral bisectioning of the network.
Note that sparse linear algebra for eigenvalue problems with small eigenvalues
is problematic in terms of numerical stability. Consider using the dense version
of this method in this case. Note also that the sparse Fiedler vector might be scaled by
a factor (-1) compared to the dense version.
@param normalized: whether (default) or not to normalize the fiedler vector.
Normalization is done such that the sum of squares equals one in order to
get reasonable values as entries might be positive and negative.
@param lanczosVecs: number of Lanczos vectors to be used in the approximate
calculation of eigenvectors and eigenvalues. This maps to the ncv parameter
of scipy's underlying function eigs.
@param maxiter: scaling factor for the number of iterations to be used in the
approximate calculation of eigenvectors and eigenvalues. The number of iterations
passed to scipy's underlying eigs function will be n*maxiter where n is the
number of rows/columns of the Laplacian matrix.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getLaplacianMatrix | ( | self, | |
includeSubPaths = True |
|||
| ) |
Returns the transposed Laplacian matrix corresponding to the higher-order network.
@param includeSubpaths: Whether or not subpath statistics shall be included in the
calculation of matrix weights
|
static |
Compute normalized leading eigenvector of a given matrix A.
@param A: sparse matrix for which leading eigenvector will be computed
@param normalized: wheter or not to normalize. Default is C{True}
@param lanczosVecs: number of Lanczos vectors to be used in the approximate
calculation of eigenvectors and eigenvalues. This maps to the ncv parameter
of scipy's underlying function eigs.
@param maxiter: scaling factor for the number of iterations to be used in the
approximate calculation of eigenvectors and eigenvalues. The number of iterations
passed to scipy's underlying eigs function will be n*maxiter where n is the
number of rows/columns of the Laplacian matrix.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getNodeNameMap | ( | self | ) |
Returns a dictionary that can be used to map node nodes to matrix/vector indices
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getShortestPaths | ( | self | ) |
Calculates all shortest paths between all pairs of higher-order nodes using the Floyd-Warshall algorithm.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.getTransitionMatrix | ( | self, | |
includeSubPaths = True |
|||
| ) |
Returns a (transposed) random walk transition matrix
corresponding to the higher-order network.
@param includeSubpaths: whether or not to include subpath statistics in the
transition probability calculation (default True)
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.HigherOrderNodeToPath | ( | self, | |
| node | |||
| ) |
Helper function that transforms a node in a
higher-order network of order k into a corresponding
path of length k-1. For a higher-order node 'a-b-c-d'
this function will return ('a','b','c','d')
@param node: The higher-order node to be transformed to a path.
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.HigherOrderPathToFirstOrder | ( | self, | |
| path | |||
| ) |
Maps a path in the higher-order network
to a path in the first-order network. As an
example, the second-order path ('a-b', 'b-c', 'c-d')
of length two is mapped to the first-order path ('a','b','c','d')
of length four. In general, a path of length l in a network of
order k is mapped to a path of length l+k-1 in the first-order network.
@param path: The higher-order path that shall be mapped to the first-order network
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.PageRank | ( | self, | |
alpha = 0.85, |
|||
maxIterations = 100, |
|||
convergenceThres = 1.0e-6, |
|||
projection = 'scaled', |
|||
includeSubPaths = True |
|||
| ) |
Calculates the PageRank of higher-order nodes based on a
power iteration. If the order of the higher-order network is larger than one,
the PageRank calculated based on the higher-order
topology will automatically be projected back to first-order
nodes.
@param projection: Indicates how the projection from k-th-order nodes (v1, v2, ... , v{k-1})
shall be performed. For the method 'all', the pagerank value of the higher-order node
will be added to *all* first-order nodes on the path corresponding to the higher-order node. For
the method 'last', the PR value of the higher-order node will only be assigned to *last*
first-order node v{k-1}. For the method 'scaled' (default), the PageRank of higher-order
nodes will be assigned proportionally to first-order nodes, i.e. each of the three nodes in the
third-order node (a,b,c) will receive one third of the PageRank of (a,b,c).
@param includeSubpaths: whether or not to use subpath statistics in the PageRank calculation
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.pathToHigherOrderNodes | ( | self, | |
| path, | |||
k = None |
|||
| ) |
Helper function that transforms a path into a sequence of k-order nodes using the separator character of the HigherOrderNetwork instance Consider an example path (a,b,c,d) with a separator string '-' For k=1, the output will be the list of strings ['a', 'b', 'c', 'd'] For k=2, the output will be the list of strings ['a-b', 'b-c', 'c-d'] For k=3, the output will be the list of strings ['a-b-c', 'b-c-d'] etc. @param path: the path tuple to turn into a sequence of higher-order nodes @param k: the order of the representation to use (default: order of the HigherOrderNetwork instance)
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.reduceToGCC | ( | self | ) |
Reduces the higher-order network to its largest (giant) strongly connected component (using Tarjan's algorithm)
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.summary | ( | self | ) |
Returns a string containing basic summary statistics of this higher-order graphical model instance
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.totalEdgeWeight | ( | self | ) |
Returns the sum of all edge weights
| def pathpy.HigherOrderNetwork.HigherOrderNetwork.vcount | ( | self | ) |
Returns the number of nodes
| pathpy.HigherOrderNetwork.HigherOrderNetwork.separator |
The separator character used to label higher-order nodes.
For separator '-', a second-order node will be 'a-b'.
1.8.6