|
| layers |
| A dictionary containing the layers of HigherOrderNetworks, where layers[k] contains the network of order k.
|
|
| maxOrder |
| the maximum order of this multi-order model
|
|
| paths |
| the paths object from which this multi-order model was created
|
|
| T |
| a dictionary of transition matrices for all layers of the model
|
|
Instances of this class represent a hierarchy of
higher-order networks which collectively represent
a multi-order model for path statistics.
def pathpy.MultiOrderModel.MultiOrderModel.__init__ |
( |
|
self, |
|
|
|
paths, |
|
|
|
maxOrder = 1 |
|
) |
| |
Generates a hierarchy of higher-order
models for the given path statistics,
up to a given maximum order
@param paths: the paths instance for which the model should be created
@param maxOrder: the maximum order of the multi-order model
def pathpy.MultiOrderModel.MultiOrderModel.__str__ |
( |
|
self | ) |
|
Returns the default string representation of
this multi-order model instance
def pathpy.MultiOrderModel.MultiOrderModel.estimateOrder |
( |
|
self, |
|
|
|
paths, |
|
|
|
maxOrder = None , |
|
|
|
significanceThreshold = 0.01 |
|
) |
| |
Selects the optimal maximum order of a multi-order network model for the
observed paths, based on a likelihood ratio test with p-value threshold of p
By default, all orders up to the maximum order of the multi-order model will be tested.
@param paths: The path statistics for which to perform the order selection
@param maxOrder: The maximum order up to which the multi-order model shall be tested.
def pathpy.MultiOrderModel.MultiOrderModel.factorial |
( |
|
self, |
|
|
|
n, |
|
|
|
log = True |
|
) |
| |
Caclulates (or approximates) the (log of the) factorial n!. The function applies Stirling's approximation if n>20.
@param n: computes factorial of n
@param log: whether or not to return the (natural) logarithm of the factorial
def pathpy.MultiOrderModel.MultiOrderModel.getDegreesOfFreedom |
( |
|
self, |
|
|
|
maxOrder = None , |
|
|
|
assumption = "paths" |
|
) |
| |
Calculates the degrees of freedom of the model based on
different assumptions, and taking into account layers up to
a maximum order.
@param: maxOrder: the maximum order up to which model layers shall be
taken into account
@param assumption: if set to 'paths', for the degree of freedom calculation
only paths in the first-order network topology will be considered. This is
needed whenever we model 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, i.e. if all possible paths actually occur.
def pathpy.MultiOrderModel.MultiOrderModel.getLayerLikelihood |
( |
|
self, |
|
|
|
paths, |
|
|
|
l = 1 , |
|
|
|
considerLongerPaths = True , |
|
|
|
log = True |
|
) |
| |
Calculates the (log-)likelihood of the first l layers of a multi-order network model
using all observed paths of (at least) length l
@param paths: the path statistics for which to calculate the layer likelihood
@param l: The minimum length of paths for which the likelihood shall be calculated.
Paths of length l (and possibly longer) will be used to calculate the likelihood
of model layers for all orders up to l
@param considerLongerPaths: whether or not to include paths longer than l
in the calculation of the likelihood. In general, when calculating the likelihood
of a multi-order model which combines orders from 1 to l, this should be set to
true only for the value of l that corresponds to the largest order in the model.
@param log: whether to compute Log-Likelihood (default: True)
@returns: the (log-)likelihood of the model layer given the path statistics
def pathpy.MultiOrderModel.MultiOrderModel.getLikelihood |
( |
|
self, |
|
|
|
paths, |
|
|
|
maxOrder = None , |
|
|
|
log = True |
|
) |
| |
Calculates the likelihood of a multi-order
network model up to a maximum order maxOrder based on all
path statistics.
@param paths: the path statistics to be used in the likelihood
calculation
@param maxOrder: the maximum layer order to take into
account for the likelihood calculation. For the default
value None, all orders will be used for the
likelihood calculation.
@log: Whether or not to return the log likelihood (default: True)
def pathpy.MultiOrderModel.MultiOrderModel.likeliHoodRatioTest |
( |
|
self, |
|
|
|
paths, |
|
|
|
maxOrderNull = 0 , |
|
|
|
maxOrder = 1 , |
|
|
|
assumption = 'paths' , |
|
|
|
significanceThreshold = 0.01 |
|
) |
| |
Performs a likelihood-ratio test between two multi-order models with given maximum orders, where maxOrderNull serves
as null hypothesis and maxOrder serves as alternative hypothesis. The null hypothesis is rejected if the p-value for
the observed paths under the null hypothesis is smaller than the given significance threshold.
Applying this test makes the assumption that we have nested models, i.e. that the null model is contained
as a special case in the parameter space of the more complex model. If we assume that the path constraint holds,
this is not true for the test of the first- against the zero-order model (since some sequences of the zero order model
cannot be generated in the first-order model). However, since the set of possible higher-order transitions is generated
based on the first-order model, the nestedness property holds for all higher order models.
@param paths: the path data to be used in the liklihood ratio test
@param maxOrderNull: maximum order of the multi-order model
to be used as a null hypothesis
@param maxOrder: maximum order of the multi-order model to be used as
alternative hypothesis
@param assumption: paths or ngrams
@param significanceThreshold: the threshold for the p-value
below which to accept the alternative hypothesis
@returns: a tuple of the format (reject, p) which captures whether or
not the null hypothesis is rejected in favor of the alternative
hypothesis, as well as the p-value that led to the decision
def pathpy.MultiOrderModel.MultiOrderModel.summary |
( |
|
self | ) |
|
Returns a string containing basic summary information
of this multi-order model instance.
def pathpy.MultiOrderModel.MultiOrderModel.testNetworkAssumption |
( |
|
self, |
|
|
|
paths, |
|
|
|
method = 'AIC' |
|
) |
| |
Tests whether the assumption that the observed paths result
from an underlying network topology is justified. Roughly speaking,
this test yields true if the explanatory gained by the assumption of
a network topology justifies the additional model complexity
The decision will be made based on a comparison between the first-
and zero-order model layers. Different from the comparison of different
multi-order models which is the basis of the order detection procedure,
here the first- and the zero-order model are fundamentally different:
For the zero-order model we do not assume a network topology, while for
the first-order model we do assume an underlying network topology.
For this reason, the zero-order model cannot be cast as a special case
of the first-order model, i.e. the models are not nested!
So we need to use the AIC or BIC rather than a likelihood ratio test.
The documentation for this class was generated from the following file:
- /mnt/c/Users/ingos/Desktop/pathpy/pathpy/MultiOrderModel.py