mobility Package

mobility Package

distance Module

complex_systems.mobility.distance.distance(X, Y)[source]

Calculate the Euclidian distance between coordinates at differents step in time

\[dist_{i+1} = Distance( (x_i,y_i), (x_{i+1},y_{i+1}) ) \ \forall i\]
Example :
>>> from complex_systems.mobility.levy_flight import *
>>> X = [0,0,0]
>>> Y = [1,2,3]
>>> distance(X,Y)
[1.0,1.0]
Parameters :
  • X: list(float)

    X coordinates

  • Y: list(float)

    Y coordinates

Returns :
  • dist : list

    Euclidian distance

levy_walk Module

complex_systems.mobility.levy_walk.levy_walk(alpha, beta, sample_length, size_max, velocity, f_min, f_max, s_min, s_max, duration=90000, b_c=1)[source]

This code is based on the following paper:

[Rhee08]Injong Rhee, Minsu Shin, Seongik Hong, Kyunghan Lee and Song Chong, “On the Levy-walk Nature of Human Mobility”, INFOCOM, Arizona, USA, 2008

Note

Levy Flight or Levy Walk model:
 

The Levy Walk generalize the concept of random walker with jump length distribution \(p(\Delta x)\) and and waitting time distribution \(p(\Delta t)\) for waitting ting time \(\Delta t_i\) and jump length \(\Delta x_i\) at evry steps \(i = 1, 2, ..., n\) of the walk.

\[\begin{split}p(\Delta x) \sim \frac{1}{(\Delta x)^{1+\alpha} },\ \ \ p(\Delta t) \sim \frac{1}{(\Delta t)^{1+\beta} }, \ \alpha , \beta > 0\end{split}\]
Example :
>>> from complex_systems.mobility.levy_walk import *
>>> levy_walk(alpha=0.66, beta=0.99, sample_length=1, size_max=83000, velocity=1.0, f_min=8, f_max=83000, s_min=0.8, s_max=430, duration=500, b_c=2)
Parameters :
  • alpha : float

    Levy exponent for flight length distribution, 0 < alpha <= 2

  • beta : float

    Levy exponent for pause time distribution, 0 < beta <= 2

  • sample_length : int

    Sample time in mins

  • size_max : int

    size of simulation area

  • velocity : float

    speed in m/s

  • f_min : int

    min flight length

  • f_max : int

    max flight length

  • s_min : int

    min pause time (second)

  • s_max : int

    max pause time (second)

  • duration : int

    simulation duration (minutes)

  • b_c : int
    boundary condition:
    • wrap-around if b_c=1
    • reflection boundary if b_c=2
Returns :
  • un_sampled : list(tulpe(X, Y, T))
    • X : list(int)

      list of X location

    • Y : list(int)

      list of Y location

    • T : list(float)

      time in seconds

  • A : list(int)

    list of jump length

  • B : list(int)

    list of pause time length

  • sampled : list(tulpe(X_sampled, Y_sampled, T_sampled))
    • X_sampled

      list of X location at sampled intervals

    • Y_sampled

      list of Y location at sampled intervals

    • T_sampled

      list of sampled intervals

stabrnd Module

complex_systems.mobility.stabrnd.stabrnd(alpha, beta, c, delta, m, n)[source]

Stable Random Number Generator (McCulloch 12/18/96) based on the paper [Cha71]

Returns m x n matrix of iid stable random numbers with characteristic exponent alpha in [.1,2], skewness parameter beta in [-1,1], scale c > 0, and location parameter delta. Based on the method of [Cha71] .

[Cha71](1, 2) J.M. Chambers, C. L. Mallows and B. W.Stuck, “A Method for Simulating Stable Random Variables,” JASA 71 (1976): 340-4.
History of this Code:
 
Parameters :
  • alpha : float

    Characteristic exponent in [.1,2]

  • beta : float

    Skewness in [-1,1]

  • c : float

    Scale c > 0

  • delta : float

    Location parameter

  • m, n : int

    Dimension of the matrix resultat

Returns :
  • x : matrix

Note

The CMS method is applied in such a way that x will have the log characteristic function

\[\log E \cdot e^{(ixt)} = i \Delta t + \psi( c \cdot t ),\]

where

\[\psi(t) = -|t|^{\alpha} \cdot [ 1 - i\beta \cdot sign(t) \cdot \tan(\pi \alpha/2) ],\ for\ \alpha \neq 1\]
\[\psi(t) = -|t| \cdot [1 + i \beta (2 \pi) \cdot sign(t) \cdot \log |t| ],\ for\ \alpha = 1.\]

With this parameterization, the stable cdf, see [Mcc96] for details.

\[S(x; \alpha, \beta,c, \delta) = S((x-\delta)/c; \alpha, \beta, 1, 0). \]

When \(\alpha = 2\):, the distribution is Gaussian with mean delta and variance \(2 c^2\), and beta has no effect.

When \(\alpha > 1\), the mean is delta for all \(\beta\).

When \(\alpha <= 1\), the mean is undefined.

When \(\beta = 0\), the distribution is symmetrical and delta is the median for all \(\alpha\).

When \(\alpha = 1\) and \(\beta = 0\), the distribution is Cauchy (arctangent) with median \(\delta\).

When the submitted \(\alpha\) is > 2 or < .1, or \(\beta\) is outside [-1,1], an error message is generated and x is returned as a matrix of NaNs.

\(\alpha < 0.1\) is not allowed here because of the non-negligible probability of overflows.

If you’re only interested in the symmetric cases, you may just set \(\beta = 0\) and skip the following considerations:

When \(\beta > 0, (< 0)\), the distribution is skewed to the right (left).

When \(\alpha < 1, \delta\), as defined above, is the unique fractile that is invariant under averaging of iid contributions. I call such a fractile a “focus of stability.” This, like the mean, is a natural location parameter.

When \(\alpha = 1\), either every fractile is a focus of stability, as in the \(\beta = 0\) Cauchy case, or else there is no focus of stability at all, as is the case for \(\beta ~= 0\). In the latter cases, which I call “afocal,” delta is just an arbitrary fractile that has a simple relation to the c.f.

When \(\alpha > 1 and \beta > 0\), med(x) must lie very far below the mean as alpha approaches 1 from above. Furthermore, asalpha approaches 1 from below, med(x) must lie very far above the focus of stability when \(\beta > 0\). If \(\beta ~= 0\), there is therefore a discontinuity in the distribution as a function of alpha as alpha passes 1, when delta is held constant. CMS, following an insight of Vladimir Zolotarev, remove this discontinuity by subtracting:

\[\beta \cdot c \cdot \tan(\pi \cdot \alpha/2)\]

in their program RSTAB, a.k.a. RNSTA in IMSL (formerly GGSTA). The result is a random number whose distribution is a continuous function of alpha, but whose location parameter (which I call zeta) is a shifted version of delta that has no known interpretation other than computational convenience.

The present program restores the more meaningful \(\delta\) parameterization by using the CMS (4.1), but with \(\beta \cdot c \cdot tan(\pi \alpha/2)\) added back in (ie with their initial \(tan(\alpha \phi_0)\) deleted). RNSTA therefore gives different results than the present program when \(\beta ~= 0\). However, the present beta is equivalent to the CMS beta’ (BPRIME).

Rather than using the CMS D2 and exp2 functions to compensate for the ill- condition of the CMS (4.1) when \(\alpha\) is very near 1, the present program merely fudges these cases by computing \(x\) from their (2.4) and adjusting for \(\beta \cdot c \cdot tan(\pi \alpha/2)\) when alpha is within 1.e-8 of 1. This should make no difference for simulation results with samples of size less than approximately 10^8, and then only when the desired alpha is within 1.e-8 of 1, but not equal to 1.

The frequently used Gaussian and symmetric cases are coded separately so as to speed up execution.

References
[Mcc96]J.H. McCulloch, “On the parametrization of the afocal stable distributions,” Bull. London Math. Soc. 28 (1996): 651-55,
[Zov86]V.M. Zolotarev, “One Dimensional Stable Laws,” Amer. Math. Soc., 1986.
[Sam94]
  1. Samorodnitsky and M.S. Taqqu, “Stable Non-Gaussian Random Processes,” Chapman & Hill, 1994.
[Jan94]
  1. Janicki and A. Weron, “Simulaton and Chaotic Behavior of Alpha-Stable Stochastic Processes,” Dekker, 1994.
[Mcc97]J.H. McCulloch, “Financial Applications of Stable Distributons,” Handbook of Statistics, Vol. 14, 1997.

Project Versions

Table Of Contents

Previous topic

complex_systems Package

Next topic

spatial Package

This Page