| Type: | Package |
| Title: | Visibility Graphs and Partial Visibility Curves of Time Series |
| Version: | 0.1.0 |
| Description: | Maps time series into complex networks with the natural visibility algorithm of Lacasa et al. (2008) <doi:10.1073/pnas.0709247105> and the horizontal visibility algorithm of Luque et al. (2009) <doi:10.1103/PhysRevE.80.046103>, using fast exact algorithms. Provides degree statistics, exact results for uncorrelated and periodic series, Feigenbaum graphs (Luque et al., 2011) <doi:10.1371/journal.pone.0022411>, time irreversibility, sequential visibility motifs and plotting tools. It also implements the basins of visibility, the total visibility number and the partial visibility curve of Nuño and Muñoz (2020) <doi:10.1016/j.chaos.2019.109537>, computed with a genetic algorithm, a greedy heuristic or an exact integer linear programming formulation, together with the analytical partial visibility curves of the period doubling cascades of the logistic map. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| Depends: | R (≥ 3.5.0) |
| Imports: | graphics, stats |
| Suggests: | igraph, Matrix, lpSolve, knitr, rmarkdown, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Language: | en-GB |
| Config/roxygen2/version: | 8.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-11 16:59:46 UTC; franj |
| Author: | Francisco J. Muñoz
|
| Maintainer: | Francisco J. Muñoz <f.j.munoz.ortega@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-12-02 12:50:02 UTC |
tsvisibility: Visibility Graphs and Partial Visibility Curves of Time Series
Description
The visibility algorithm maps a time series x_1, \dots, x_n into a
graph with one node per observation.
-
Natural visibility (Lacasa et al., 2008): nodes
i < jare linked when every intermediate observation lies strictly below the straight line joining(i, x_i)and(j, x_j):x_k < x_i + (x_j - x_i)\frac{k - i}{j - i}, \quad i < k < j. -
Horizontal visibility (Luque et al., 2009): nodes
i < jare linked whenx_k < \min(x_i, x_j)for everyi < k < j.
Consecutive observations are always linked.
The package is organised in five groups of functions:
Graph construction:
vgraph(),visibility_edges(),visibility_matrix(),vgraph_to_igraph().Degree statistics and classical exact results:
visibility_degree(),degree_distribution(),degree_entropy(),hvg_lambda(),hvg_degree_iid(),hvg_mean_degree_periodic(),feigenbaum_degree_distribution(),visibility_irreversibility(),visibility_motifs().Basins of visibility (Nuño and Muñoz, 2020):
basin_point(),basin_set(),visibility_point(),visibility_set(),visibility_distribution(),max_visibility_point(),greatest_basin_point().Total and partial visibility:
total_visibility(),partial_visibility_set(),partial_visibility_curve(),pvc_length(),pvc_theoretical(),pvc_theoretical_length().Logistic map and utilities:
logistic_series(),logistic_superstable(),feigenbaum_constants(),plot_visibility(),pattern_frequency().
Author(s)
Maintainer: Francisco J. Muñoz f.j.munoz.ortega@gmail.com (ORCID)
Authors:
Francisco J. Muñoz f.j.munoz.ortega@gmail.com (ORCID)
Juan Carlos Nuño juancarlos.nuno@upm.es
References
Lacasa, L., Luque, B., Ballesteros, F., Luque, J. and Nuño, J. C. (2008). From time series to complex networks: the visibility graph. Proceedings of the National Academy of Sciences, 105, 4972–4975. doi:10.1073/pnas.0709247105
Luque, B., Lacasa, L., Ballesteros, F. and Luque, J. (2009). Horizontal visibility graphs: exact results for random time series. Physical Review E, 80, 046103. doi:10.1103/PhysRevE.80.046103
Nuño, J. C. and Muñoz, F. J. (2020). The partial visibility curve of the Feigenbaum cascade to chaos. Chaos, Solitons & Fractals, 131, 109537. doi:10.1016/j.chaos.2019.109537
Basins of visibility
Description
The basin of visibility B_k of a point P_k = (k, x_k) is
the set of points of the series seen from P_k; by default the point
sees itself. The basin of a set of points is the union of their basins
(Nuño and Muñoz, 2020). The visibility of a point (or of a set) is the
cardinality of its basin.
Usage
basin_point(x, k, type = c("horizontal", "natural"), itself = TRUE)
basin_set(x, v, type = c("horizontal", "natural"), itself = TRUE)
visibility_point(x, k, type = c("horizontal", "natural"), itself = TRUE)
visibility_set(x, v, type = c("horizontal", "natural"), itself = TRUE)
Arguments
x |
A numeric series or a |
k |
Index of a single point of the series. |
type |
Either |
itself |
If |
v |
The selected set of points: a logical vector with the same length as the series, a 0/1 vector, or a vector of indices. |
Value
basin_point() and basin_set() return a logical vector marking
the points of the basin; visibility_point() and visibility_set()
return its cardinality.
References
Nuño, J. C. and Muñoz, F. J. (2020). The partial visibility curve of the Feigenbaum cascade to chaos. Chaos, Solitons & Fractals, 131, 109537. doi:10.1016/j.chaos.2019.109537
Examples
x <- c(5, 3, 6, 7, 2, 1, 6, 7)
basin_point(x, k = 2, itself = FALSE)
visibility_point(x, k = 4)
basin_set(x, v = c(1, 4))
visibility_set(x, v = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE))
Empirical degree distribution
Description
Empirical degree distribution
Usage
degree_distribution(
x,
type = c("horizontal", "natural"),
mode = c("total", "out", "in")
)
Arguments
x |
A numeric series or a |
type |
Either |
mode |
|
Value
A data frame with columns k (degree), count and p (relative
frequency), sorted by k.
Examples
set.seed(1)
degree_distribution(runif(1000))
Shannon entropy of the degree distribution
Description
Shannon entropy of the degree distribution
Usage
degree_entropy(
x,
type = c("horizontal", "natural"),
mode = c("total", "out", "in"),
base = exp(1)
)
Arguments
x |
A numeric series, a |
type |
Either |
mode |
|
base |
Base of the logarithm (default: natural logarithm). |
Value
The entropy h = -\sum_k P(k) \log P(k).
References
Luque, B., Lacasa, L., Ballesteros, F. J. and Robledo, A. (2012). Analytical properties of horizontal visibility graphs in the Feigenbaum scenario. Chaos, 22, 013109.
Examples
degree_entropy(feigenbaum_degree_distribution(3))
set.seed(2)
degree_entropy(runif(2000))
Constants of the Feigenbaum scenario of the logistic map
Description
Constants of the Feigenbaum scenario of the logistic map
Usage
feigenbaum_constants()
Value
A named list: r_inf (accumulation point of the period-doubling
cascade), delta and alpha (Feigenbaum constants), r3 (onset of the
period-3 window, 1 + \sqrt{8}), r3_inf (accumulation point of
the period-3 cascade, approximate) and r_c (crossing point where the
total visibility number changes from 1/4 to 1/3, approximate; Nuño and
Muñoz, 2020).
References
Nuño, J. C. and Muñoz, F. J. (2020). The partial visibility curve of the Feigenbaum cascade to chaos. Chaos, Solitons & Fractals, 131, 109537. doi:10.1016/j.chaos.2019.109537
Examples
feigenbaum_constants()$r_inf
Degree distribution of Feigenbaum graphs
Description
Exact degree distribution of the horizontal visibility graph of the
periodic orbits of period T = 2^n in the period-doubling cascade of
unimodal maps (Feigenbaum graphs):
P(n, k) = (1/2)^{k/2} for k = 2, 4, \dots, 2n,
P(n, 2(n + 1)) = (1/2)^n and zero for odd k. At the
accumulation point (n = \infty) P(k) = (1/2)^{k/2} for every
even k.
Usage
feigenbaum_degree_distribution(n, kmax = 60)
Arguments
n |
Non-negative integer, or |
kmax |
Largest degree returned when |
Value
A data frame with columns k and p.
References
Luque, B., Lacasa, L., Ballesteros, F. J. and Robledo, A. (2011). Feigenbaum graphs: a complex network perspective of chaos. PLoS ONE, 6, e22411. doi:10.1371/journal.pone.0022411
Examples
feigenbaum_degree_distribution(3)
# mean degree equals 4 (1 - 1 / (2 T))
with(feigenbaum_degree_distribution(3), sum(k * p))
Exact degree distribution of the HVG of an uncorrelated series
Description
For any series of independent and identically distributed continuous
random variables the degree distribution of the horizontal visibility
graph is P(k) = \frac{1}{3}\left(\frac{2}{3}\right)^{k-2},
k \ge 2, i.e. an exponential with \lambda = \log(3/2). In the
directed version the in- and out-degree distributions are
P(k) = (1/2)^k, k \ge 1.
Usage
hvg_degree_iid(k, mode = c("total", "out", "in"))
Arguments
k |
Integer vector of degrees. |
mode |
|
Value
The probabilities P(k).
References
Luque, B., Lacasa, L., Ballesteros, F. and Luque, J. (2009). Horizontal visibility graphs: exact results for random time series. Physical Review E, 80, 046103. doi:10.1103/PhysRevE.80.046103
Lacasa, L., Núñez, A., Roldán, E., Parrondo, J. M. R. and Luque, B. (2012). Time series irreversibility: a visibility graph approach. The European Physical Journal B, 85, 217.
Examples
hvg_degree_iid(2:10)
sum(hvg_degree_iid(2:200))
Exponent of the exponential degree distribution of an HVG
Description
Fits P(k) \sim e^{-\lambda k} by least squares on
\log P(k). For uncorrelated series \lambda = \log(3/2)
\approx 0.405; Luque et al. (2009) found \lambda < \log(3/2) for
chaotic series and \lambda > \log(3/2) for correlated stochastic
series.
Usage
hvg_lambda(x, kmin = 2, kmax = Inf, type = "horizontal")
Arguments
x |
A numeric series or a |
kmin, kmax |
Range of degrees used in the fit. By default every
observed degree |
type |
Either |
Value
A list with components lambda, intercept, r.squared,
reference (\log(3/2)) and data (the degree distribution used).
Examples
set.seed(3)
hvg_lambda(runif(5000))$lambda
hvg_lambda(logistic_series(4, 5000, x0 = 0.2))$lambda
Mean degree of the HVG of a periodic series
Description
The mean degree of the horizontal visibility graph of a periodic series of
period T (with no repeated values within a period) is
\bar{k} = 4\left(1 - \frac{1}{2T}\right); it tends to 4 for
aperiodic series.
Usage
hvg_mean_degree_periodic(period)
Arguments
period |
Integer period |
Value
The mean degree.
References
Núñez, A. M., Lacasa, L., Gómez, J. P. and Luque, B. (2012). Visibility algorithms: a short review. In New Frontiers in Graph Theory, InTech.
Examples
hvg_mean_degree_periodic(c(1, 2, 4, 8, 16))
Time series of the logistic map
Description
Iterates x_{t+1} = r x_t (1 - x_t) after a transient of transient
steps and returns n consecutive values.
Usage
logistic_series(r, n, x0 = NULL, transient = 1e+05, digits = 8)
Arguments
r |
Parameter of the map, |
n |
Length of the series. |
x0 |
Initial condition in |
transient |
Number of initial iterations discarded. |
digits |
Number of decimal digits kept ( |
Details
Rounding (argument digits) is important when building horizontal
visibility graphs of periodic orbits: in exact arithmetic the values that
repeat along the orbit are equal and block the horizontal visibility, but
floating point iteration produces tiny differences that would create
spurious links.
Value
A numeric vector of length n.
See Also
logistic_superstable(), feigenbaum_constants().
Examples
logistic_series(r = 3.2, n = 10, x0 = 0.1)
x <- logistic_series(r = 4, n = 500, x0 = 0.2)
plot(x, type = "l")
Superstable parameters of the logistic map
Description
Values of r at which the critical point x = 1/2 belongs to the
periodic orbit (superstable orbits). They converge very fast to the orbit
and are convenient to generate the periodic series of the cascades.
Usage
logistic_superstable(k, cascade = c("feigenbaum", "period3"))
Arguments
k |
Order (see Details); vectorised. |
cascade |
|
Details
-
cascade = "feigenbaum": period2^k,k = 0, \dots, 11. -
cascade = "period3": period3 \cdot 2^{k-1},k = 1, 2, 3.
The values were computed by bisection on
f_r^{(T)}(1/2) = 1/2.
Value
A numeric vector of parameters.
Examples
logistic_superstable(0:5)
x <- logistic_series(logistic_superstable(3), 32, x0 = 0.3)
length(unique(x)) # period 8
Largest visibility of a single point
Description
max_visibility_point() returns the largest cardinality of the basin of
visibility of a point of the series and greatest_basin_point() the index
of a point that attains it (the first one in case of ties).
Usage
max_visibility_point(x, type = c("horizontal", "natural"), itself = TRUE)
greatest_basin_point(x, type = c("horizontal", "natural"))
Arguments
x |
A numeric series or a |
type |
Either |
itself |
If |
Value
A single integer.
Examples
x <- c(4, 5, 6, 3, 6, 5, 3, 6, 7, 4, 7)
max_visibility_point(x)
greatest_basin_point(x)
Partial visibility curve
Description
Computes the partial visibility curve of a time series (Nuño and Muñoz,
2020): for every cardinality m = 0, 1, 2, \dots the largest
visibility mV of a set of m points (see
partial_visibility_set()), normalised as \mu = m / n and
\nu = mV / n. The curve is computed until the whole series is seen
(\nu = 1, which happens at the total visibility number) or until
m_max.
Usage
partial_visibility_curve(
x,
type = c("horizontal", "natural"),
method = c("ga", "greedy", "exact"),
m_max = NULL,
control = list(),
keep_sets = FALSE,
verbose = FALSE
)
Arguments
x |
A numeric series or a |
type |
Either |
method |
One of |
m_max |
Largest cardinality computed (default: the length of the
series, i.e. until |
control |
A list of parameters of the genetic algorithm:
|
keep_sets |
If |
verbose |
If |
Details
With method = "ga" the search for m points is seeded with the best
set found for m - 1 points plus the best additional point, so the
computed curve is non-decreasing.
Value
A data frame of class pvcurve with columns m, mu,
visibility and nu, starting at (0, 0). Attributes type,
method and n store the settings.
References
Nuño, J. C. and Muñoz, F. J. (2020). The partial visibility curve of the Feigenbaum cascade to chaos. Chaos, Solitons & Fractals, 131, 109537. doi:10.1016/j.chaos.2019.109537
See Also
pvc_length(), pvc_theoretical(), plot.pvcurve().
Examples
x <- logistic_series(logistic_superstable(2), 48, x0 = 0.3)
cg <- partial_visibility_curve(x, method = "greedy")
pvc_length(cg)
plot(cg)
lines(pvc_theoretical(2), col = "red")
set.seed(1)
cga <- partial_visibility_curve(x, method = "ga",
control = list(num_iter = 300))
pvc_length(cga)
pvc_theoretical_length(2)
Partial visibility set
Description
Finds a set of exactly m points of the series whose basin of visibility
(the union of the basins of its points, each point seeing itself) has the
largest cardinality. This is the partial visibility set of Nuño and
Muñoz (2020), i.e. a maximum partial dominating set of the visibility
graph.
Usage
partial_visibility_set(
x,
m,
type = c("horizontal", "natural"),
method = c("ga", "greedy", "exact"),
control = list()
)
Arguments
x |
A numeric series or a |
m |
Number of points of the set ( |
type |
Either |
method |
One of |
control |
A list of parameters of the genetic algorithm:
|
Details
Three methods are available:
-
"ga": the genetic algorithm of Nuño and Muñoz (2020), with mutation, inversion, crossover, elitist selection and replacement of duplicated genomes. Genomes are repaired so that they always contain exactlympoints, and the greedy solution is included in the initial population. -
"greedy": chooses, one at a time, the point that adds the largest number of new points to the basin. Fast, but not optimal in general. -
"exact": solves the problem as an integer linear program with lpSolve. It guarantees the optimum but its cost grows quickly with the length of the series (practical up to a few hundred points).
Value
A list with components set (indices of the chosen points),
visibility (cardinality of its basin), fraction (visibility / n),
m, n and method.
References
Nuño, J. C. and Muñoz, F. J. (2020). The partial visibility curve of the Feigenbaum cascade to chaos. Chaos, Solitons & Fractals, 131, 109537. doi:10.1016/j.chaos.2019.109537
See Also
total_visibility(), partial_visibility_curve().
Examples
x <- logistic_series(logistic_superstable(2), 40, x0 = 0.3)
partial_visibility_set(x, m = 3, method = "greedy")
set.seed(1)
partial_visibility_set(x, m = 3, method = "ga",
control = list(num_iter = 100))
if (requireNamespace("lpSolve", quietly = TRUE)) {
partial_visibility_set(x, m = 3, method = "exact")
}
Frequency of the patterns (contiguous blocks) of a sequence
Description
Counts every contiguous block of length 1 to max_size of a sequence.
Applied to the sequence of degrees or visibilities of a time series it
reveals its visibility patterns (Muñoz and Nuño, 2020).
Usage
pattern_frequency(v, max_size = NULL, sep = "_")
Arguments
v |
A vector (numeric, integer or character). |
max_size |
Largest length of the patterns (default: |
sep |
Separator used to paste the elements of a pattern. |
Value
A data frame with columns pattern, freq and length, sorted
by length and decreasing frequency.
References
Muñoz, F. J. and Nuño, J. C. (2020). Universal visibility patterns of unimodal maps. Chaos, 30. doi:10.1063/5.0006652
Examples
pattern_frequency(c(1, 2, 3, 1, 2, 3), max_size = 3)
x <- logistic_series(logistic_superstable(2), 40, x0 = 0.3)
pattern_frequency(visibility_degree(x), max_size = 4)
Plot a partial visibility curve
Description
Plot a partial visibility curve
Usage
## S3 method for class 'pvcurve'
plot(
x,
type = "b",
xlab = expression(mu),
ylab = expression(nu),
xlim = NULL,
ylim = c(0, 1),
...
)
## S3 method for class 'pvcurve'
lines(x, ...)
Arguments
x |
A |
type, xlab, ylab, xlim, ylim |
Graphical parameters. |
... |
Value
NULL, invisibly.
Examples
plot(pvc_theoretical(1), type = "l")
lines(pvc_theoretical(4), col = "red")
Plot a time series and its visibility links
Description
Draws the series as vertical bars and the visibility links between its
points: straight segments for natural visibility and horizontal segments
(at the height of the lower point) for horizontal visibility. If select
is given, the selected points are highlighted and only their links are
drawn, which shows their basin of visibility (for instance, a partial or
total visibility set).
Usage
plot_visibility(
x,
type = c("horizontal", "natural"),
select = NULL,
bars = TRUE,
col_links = "grey40",
col_select = "red",
xlab = "t",
ylab = "x",
main = NULL,
...
)
## S3 method for class 'vgraph'
plot(x, ...)
Arguments
x |
A numeric series or a |
type |
Either |
select |
Optional selection of points (logical mask, 0/1 vector or indices). |
bars |
If |
col_links |
Colour of the visibility links. |
col_select |
Colour of the selected points. |
xlab, ylab, main |
Axis labels and title. |
... |
Further graphical parameters passed to |
Value
The vgraph object, invisibly.
Examples
x <- c(1, 1, 2, 3, 4, 3, 2, 3, 1)
plot_visibility(x, type = "natural")
plot_visibility(x, type = "horizontal")
plot_visibility(x, type = "horizontal", select = c(5, 8))
y <- logistic_series(logistic_superstable(2), 24, x0 = 0.3)
tv <- total_visibility(y, method = "greedy")
plot_visibility(y, select = tv$set)
Length of a partial visibility curve
Description
Euclidean length of the polygonal line through the points
(\mu, \nu) of a partial visibility curve,
L = \sum_j \sqrt{\Delta\mu_j^2 + \Delta\nu_j^2}.
Usage
pvc_length(curve)
Arguments
curve |
A |
Value
The length of the curve.
Examples
pvc_length(pvc_theoretical(3))
Analytical partial visibility curves of the period-doubling cascades
Description
Vertices of the exact partial visibility curves (horizontal visibility) of the periodic series of the logistic map obtained by Nuño and Muñoz (2020).
Usage
pvc_theoretical(k, cascade = c("feigenbaum", "period3"))
Arguments
k |
Order of the cascade (see Details). |
cascade |
|
Details
-
cascade = "feigenbaum", periodT = 2^k,k \ge 0: thek-polygonal is\nu_k(\mu) = (2k + 3)\mufor0 \le \mu \le 1/(3 \cdot 2^k),\nu_k(\mu) = 2k\mu + 2^{-k}for1/(3 \cdot 2^k) \le \mu \le 2^{-(k+1)}and\nu_k(\mu) = 2j\mu + 2^{-j}for2^{-(j+2)} \le \mu \le 2^{-(j+1)},j = k - 1, \dots, 1. It reaches\nu = 1at the total visibility number\mu = 1/4(1/3fork = 0). -
cascade = "period3", periodT = 3 \cdot 2^{k-1},k \ge 1:\nu_k(\mu) = 2(k + 2)\mufor0 \le \mu \le 1/(9 \cdot 2^{k-1})and then\nu_k(\mu) = (2j + 1)\mu + 1/(3 \cdot 2^{j-1})forj = k, \dots, 0, ending at\mu = 1/3,\nu = 1.
Value
A data frame of class pvcurve with columns mu and nu
(vertices of the polygonal).
References
Nuño, J. C. and Muñoz, F. J. (2020). The partial visibility curve of the Feigenbaum cascade to chaos. Chaos, Solitons & Fractals, 131, 109537. doi:10.1016/j.chaos.2019.109537
Examples
pvc_theoretical(1)
pvc_theoretical(2, cascade = "period3")
plot(pvc_theoretical(1), type = "l")
for (k in 2:6) lines(pvc_theoretical(k), col = k)
Length of the analytical partial visibility curves
Description
Length of the k-polygonals of pvc_theoretical(). With k = Inf
the limit at the accumulation point of the cascade is returned
(computed with k = 60, beyond which the value does not change in
double precision): L_\infty \approx 1.0414387863956818 for the
Feigenbaum cascade and L_\infty \approx 1.089156529597995 for the
period-3 cascade (Nuño and Muñoz, 2020).
Usage
pvc_theoretical_length(k, cascade = c("feigenbaum", "period3"))
Arguments
k |
A vector of orders, possibly including |
cascade |
|
Value
A numeric vector of lengths.
Examples
pvc_theoretical_length(0:6)
pvc_theoretical_length(Inf)
pvc_theoretical_length(Inf, cascade = "period3")
# the ratio (L_n - L_{n-1}) / (L_{n+1} - L_n) tends to 2
L <- pvc_theoretical_length(1:12)
head(diff(L)[-length(diff(L))] / diff(L)[-1])
Total visibility number
Description
Finds a smallest set of points whose basins of visibility cover the whole series (a minimum dominating set of the visibility graph). Its cardinality is the total visibility of the series; divided by the length of the series it is the total visibility number. For the horizontal visibility of the whole Feigenbaum cascade it equals 1/4 (Nuño and Muñoz, 2020).
Usage
total_visibility(
x,
type = c("horizontal", "natural"),
method = c("ga", "greedy", "exact"),
control = list()
)
Arguments
x |
A numeric series or a |
type |
Either |
method |
One of |
control |
A list of parameters of the genetic algorithm:
|
Details
With method = "greedy" and method = "ga" the result is an upper bound
(redundant points are always removed); method = "exact" gives the
optimum.
Value
A list with components set, size, fraction (size / n),
n and method.
References
Nuño, J. C. and Muñoz, F. J. (2020). The partial visibility curve of the Feigenbaum cascade to chaos. Chaos, Solitons & Fractals, 131, 109537. doi:10.1016/j.chaos.2019.109537
Examples
x <- logistic_series(logistic_superstable(1), 40, x0 = 0.3)
total_visibility(x, method = "greedy")$fraction
if (requireNamespace("lpSolve", quietly = TRUE)) {
total_visibility(x, method = "exact")$fraction
}
Visibility graph object
Description
Builds a lightweight vgraph object that stores the series, the type of
visibility, the list of links and the degree of every node. Most functions
of the package accept either a numeric series or a vgraph; passing a
vgraph avoids recomputing the graph.
Usage
vgraph(x, type = c("horizontal", "natural"), tol = 0)
Arguments
x |
A numeric vector (or |
type |
Either |
tol |
Non-negative tolerance used only for the natural visibility:
node |
Value
An object of class vgraph: a list with components x (the
series), type, n (number of nodes), edges (see
visibility_edges()) and degree (integer vector).
See Also
plot_visibility(), vgraph_to_igraph().
Examples
g <- vgraph(c(3, 1, 4, 1, 5, 9, 2, 6), type = "natural")
g
g$degree
Convert a visibility graph to an igraph object
Description
Convert a visibility graph to an igraph object
Usage
vgraph_to_igraph(x, type = c("horizontal", "natural"), directed = FALSE)
Arguments
x |
A numeric series or a |
type |
Either |
directed |
If |
Value
An igraph object. The series is stored in the vertex attribute
value and the visibility type in the graph attribute type.
Examples
if (requireNamespace("igraph", quietly = TRUE)) {
ig <- vgraph_to_igraph(rnorm(50))
igraph::transitivity(ig, type = "global")
igraph::mean_distance(ig)
}
Degrees of a visibility graph
Description
Degrees of a visibility graph
Usage
visibility_degree(
x,
type = c("horizontal", "natural"),
mode = c("total", "out", "in")
)
Arguments
x |
A numeric series or a |
type |
Either |
mode |
|
Value
An integer vector with one degree per observation.
Examples
x <- c(3, 1, 4, 1, 5, 9, 2, 6)
visibility_degree(x)
visibility_degree(x, mode = "out")
Visibility distribution of a time series
Description
Distribution of the visibilities v_k = |B_k| of the points of the
series (degree plus one when the point sees itself). For instance, in the
horizontal visibility graph of a series of period 2 half of the points see
3 points and the other half see 5.
Usage
visibility_distribution(x, type = c("horizontal", "natural"), itself = TRUE)
Arguments
x |
A numeric series or a |
type |
Either |
itself |
If |
Value
A data frame with columns visibility, count and fraction.
Examples
x <- logistic_series(logistic_superstable(1), 200, x0 = 0.3)
visibility_distribution(x)
Edges of the natural or horizontal visibility graph
Description
Computes the list of links of the visibility graph of a time series.
The horizontal visibility graph is obtained in linear time with a stack
algorithm; the natural visibility graph uses, for every node, a
vectorised sweep over the slopes to the following nodes, which needs
O(n^2) operations instead of the O(n^3) of the direct
definition.
Usage
visibility_edges(x, type = c("horizontal", "natural"), tol = 0)
Arguments
x |
A numeric vector (or a |
type |
Either |
tol |
Non-negative tolerance used only for the natural visibility:
node |
Details
Two nodes i < j see each other naturally when
x_k < x_i + (x_j - x_i)(k - i)/(j - i) for all i < k < j,
which is equivalent to the slope from i to j being strictly
larger than all the slopes from i to the intermediate nodes. They see
each other horizontally when x_k < \min(x_i, x_j) for all
i < k < j. Both inequalities are strict, so equal intermediate values
block the visibility. Consecutive nodes are always linked.
Value
An integer matrix with two columns, from and to, with one row
per link and from < to, sorted by from and then by to.
References
Lacasa, L., Luque, B., Ballesteros, F., Luque, J. and Nuño, J. C. (2008). From time series to complex networks: the visibility graph. Proceedings of the National Academy of Sciences, 105, 4972–4975. doi:10.1073/pnas.0709247105
Luque, B., Lacasa, L., Ballesteros, F. and Luque, J. (2009). Horizontal visibility graphs: exact results for random time series. Physical Review E, 80, 046103. doi:10.1103/PhysRevE.80.046103
See Also
vgraph(), visibility_matrix(), vgraph_to_igraph().
Examples
x <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
visibility_edges(x, type = "horizontal")
visibility_edges(x, type = "natural")
Time irreversibility from directed visibility graphs
Description
Kullback-Leibler divergence between the out-degree (forward) and in-degree
(backward) distributions of the directed visibility graph,
D = \sum_k P_{out}(k) \log \frac{P_{out}(k)}{P_{in}(k)}.
It vanishes asymptotically for time-reversible processes and is positive
for irreversible ones. Only degrees observed in both distributions
contribute to the sum.
Usage
visibility_irreversibility(x, type = c("horizontal", "natural"))
Arguments
x |
A numeric series or a |
type |
Either |
Value
The estimated divergence (in nats).
References
Lacasa, L., Núñez, A., Roldán, E., Parrondo, J. M. R. and Luque, B. (2012). Time series irreversibility: a visibility graph approach. The European Physical Journal B, 85, 217.
Examples
set.seed(4)
visibility_irreversibility(runif(5000)) # reversible: ~ 0
visibility_irreversibility(logistic_series(4, 5000, x0 = 0.3)) # > 0
Visibility (adjacency) matrix
Description
Returns the adjacency matrix of the natural or horizontal visibility graph, as a dense integer matrix or as a sparse matrix of package Matrix.
Usage
visibility_matrix(
x,
type = c("horizontal", "natural"),
directed = FALSE,
diag = FALSE,
sparse = FALSE
)
Arguments
x |
A numeric series or a |
type |
Either |
directed |
If |
diag |
If |
sparse |
If |
Value
An n \times n matrix of zeros and ones.
Examples
visibility_matrix(c(1, 2, 1, 2, 1), type = "horizontal")
visibility_matrix(c(1, 2, 3, 4), type = "natural", diag = TRUE)
Sequential visibility-graph motifs
Description
Slides a window of size consecutive observations along the series,
builds the visibility graph of each window and counts the different
patterns of links. Since consecutive nodes are always linked, a motif is
identified by its non-consecutive links (labelled "i-j" with positions
inside the window); "none" is the path graph.
Usage
visibility_motifs(x, size = 4L, type = c("horizontal", "natural"))
Arguments
x |
A numeric vector (or a |
size |
Window size (default 4). |
type |
Either |
Value
A data frame with columns motif, count and p.
References
Iacovacci, J. and Lacasa, L. (2016). Sequential visibility-graph motifs. Physical Review E, 93, 042309.
Examples
set.seed(5)
visibility_motifs(runif(2000), size = 4)