networksns.statistical_models.darn¶
- networksns.statistical_models.darn(time_series, p, z_p='uniform', param='local')¶
Estimate, by maximum likelihood method, the parameters of the \(DARN(p)\) model.
For a temporal network represented by a time series of adjacency matrices \(\{A_{ij}^t\}_{i,j=1,\ldots, n}^{t=1,\ldots,s}\), the \(DARN(p)\) model [1] describes the state \(A^{t}_{ij}\) of the link \((i,j)\) at time \(t\) with the following copying mechanism: (i) with probability \(q_{ij}\), the link is copied from the past itself, (ii) then the lag is selected with probability \(z_i\) with \(i=1,\ldots,p\), where \(p\) represents the order of the memory, (iii) while with probability \(1-q_{ij}\), it is sampled with (marginal) probability \(y_{ij}\).
In other words, the state \(A_{ij}^t\) of the link \((i,j)\) is described by the following stochastic process at discrete time,
\(\phantom{aaaaaaaaaaaaaaaaaaa}A^{t}_{ij}= Q^{t}_{ij} A^{t-Z_p^{t}}_{ij} + (1-Q^{t}_{ij}) Y^{t}_{ij},\)
with \(Q_{ij}^t\sim B(q_{ij})\) Bernoulli variable, \(Z_p^t\) random variable picking values from \(1\) to \(p\) with probability \(z_i\) \(i=1,\ldots,p\), respectively, and \(Y_{ij}^t\sim B(y_{ij})\) Bernoulli variable.
- Parameters:
time_series (List) – Time series. List of symmetric adjacency matrices [\(A_0, A_1, \dots, A_T\)].
p (integer) – Markov order.
z_p (array or string, optional) –
stochastic array of length \(p\) representing the memory distribution \(Z_p\). Default:
'uniform'. Possible strings:'uniform': \(Z_p = (\frac{1}{p}, \dots, \frac{1}{p}\)),'exponential': \(Z_p = \frac{(1, e^{-1}, \dots, e^{-p+1})}{\left|\left|(1, e^{-1}, \dots, e^{-p+1}\right|\right|_2)}\)'normal': let \(f(x)=\frac{e^{-(x-1)^2/2}}{\sqrt{2\pi}}\) then \(Z_p = \frac{(f(0), \dots, f(p-1))}{\left|\left|(f(0), \dots, f(p-1))\right|\right|}\)
param (string, optional) – If
'local'the parameters are different for each link. If'global'the parameters do not depend on the link. Default:'local'.
- Returns:
Q (array_like) – Symmetric matrix with the estimated probabilities of copying from the past.
Y (array_like) – Symmetric matrix with the estimated parameters for the Bernoulli trials.
Examples
>>> from networksns import statistical_models as sm >>> import numpy as np
Create temporal network
>>> n = 50 >>> s = 100 >>> p = 3 >>> Q = (np.ones((n, n)) - np.diag(np.ones(n))) * 0.5 >>> Y = (np.ones((n, n)) - np.diag(np.ones(n))) * 0.3 >>> time_series = sm.darn_simulation(p, Q, Y, n, s)
Estimate the \(DARN(p)\) model parameters
>>> Q, Y = sm.darn(time_series, p)
References