| Title: | Visibility Graphs and Partial Visibility Curves of Time Series |
|---|---|
| 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. |
| Authors: | Francisco J. Muñoz [aut, cre] (ORCID: <https://orcid.org/0000-0002-0874-6275>), Juan Carlos Nuño [aut] |
| Maintainer: | Francisco J. Muñoz <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-12-02 21:10:37 UTC |
| Source: | https://github.com/cran/tsvisibility |
The basin of visibility of a point is
the set of points of the series seen from ; 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.
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)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)
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. |
basin_point() and basin_set() return a logical vector marking
the points of the basin; visibility_point() and visibility_set()
return its cardinality.
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
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))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
degree_distribution( x, type = c("horizontal", "natural"), mode = c("total", "out", "in") )degree_distribution( x, type = c("horizontal", "natural"), mode = c("total", "out", "in") )
x |
A numeric series or a |
type |
Either |
mode |
|
A data frame with columns k (degree), count and p (relative
frequency), sorted by k.
set.seed(1) degree_distribution(runif(1000))set.seed(1) degree_distribution(runif(1000))
Shannon entropy of the degree distribution
degree_entropy( x, type = c("horizontal", "natural"), mode = c("total", "out", "in"), base = exp(1) )degree_entropy( x, type = c("horizontal", "natural"), mode = c("total", "out", "in"), base = exp(1) )
x |
A numeric series, a |
type |
Either |
mode |
|
base |
Base of the logarithm (default: natural logarithm). |
The entropy .
Luque, B., Lacasa, L., Ballesteros, F. J. and Robledo, A. (2012). Analytical properties of horizontal visibility graphs in the Feigenbaum scenario. Chaos, 22, 013109.
degree_entropy(feigenbaum_degree_distribution(3)) set.seed(2) degree_entropy(runif(2000))degree_entropy(feigenbaum_degree_distribution(3)) set.seed(2) degree_entropy(runif(2000))
Constants of the Feigenbaum scenario of the logistic map
feigenbaum_constants()feigenbaum_constants()
A named list: r_inf (accumulation point of the period-doubling
cascade), delta and alpha (Feigenbaum constants), r3 (onset of the
period-3 window, ), 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).
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
feigenbaum_constants()$r_inffeigenbaum_constants()$r_inf
Exact degree distribution of the horizontal visibility graph of the
periodic orbits of period in the period-doubling cascade of
unimodal maps (Feigenbaum graphs):
for ,
and zero for odd . At the
accumulation point () for every
even .
feigenbaum_degree_distribution(n, kmax = 60)feigenbaum_degree_distribution(n, kmax = 60)
n |
Non-negative integer, or |
kmax |
Largest degree returned when |
A data frame with columns k and p.
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
feigenbaum_degree_distribution(3) # mean degree equals 4 (1 - 1 / (2 T)) with(feigenbaum_degree_distribution(3), sum(k * p))feigenbaum_degree_distribution(3) # mean degree equals 4 (1 - 1 / (2 T)) with(feigenbaum_degree_distribution(3), sum(k * p))
For any series of independent and identically distributed continuous
random variables the degree distribution of the horizontal visibility
graph is ,
, i.e. an exponential with . In the
directed version the in- and out-degree distributions are
, .
hvg_degree_iid(k, mode = c("total", "out", "in"))hvg_degree_iid(k, mode = c("total", "out", "in"))
k |
Integer vector of degrees. |
mode |
|
The probabilities .
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.
hvg_degree_iid(2:10) sum(hvg_degree_iid(2:200))hvg_degree_iid(2:10) sum(hvg_degree_iid(2:200))
Fits by least squares on
. For uncorrelated series ; Luque et al. (2009) found for
chaotic series and for correlated stochastic
series.
hvg_lambda(x, kmin = 2, kmax = Inf, type = "horizontal")hvg_lambda(x, kmin = 2, kmax = Inf, type = "horizontal")
x |
A numeric series or a |
kmin, kmax
|
Range of degrees used in the fit. By default every
observed degree |
type |
Either |
A list with components lambda, intercept, r.squared,
reference () and data (the degree distribution used).
set.seed(3) hvg_lambda(runif(5000))$lambda hvg_lambda(logistic_series(4, 5000, x0 = 0.2))$lambdaset.seed(3) hvg_lambda(runif(5000))$lambda hvg_lambda(logistic_series(4, 5000, x0 = 0.2))$lambda
The mean degree of the horizontal visibility graph of a periodic series of
period (with no repeated values within a period) is
; it tends to 4 for
aperiodic series.
hvg_mean_degree_periodic(period)hvg_mean_degree_periodic(period)
period |
Integer period |
The mean degree.
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.
hvg_mean_degree_periodic(c(1, 2, 4, 8, 16))hvg_mean_degree_periodic(c(1, 2, 4, 8, 16))
Iterates after a transient of transient
steps and returns n consecutive values.
logistic_series(r, n, x0 = NULL, transient = 1e+05, digits = 8)logistic_series(r, n, x0 = NULL, transient = 1e+05, digits = 8)
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 ( |
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.
A numeric vector of length n.
logistic_superstable(), feigenbaum_constants().
logistic_series(r = 3.2, n = 10, x0 = 0.1) x <- logistic_series(r = 4, n = 500, x0 = 0.2) plot(x, type = "l")logistic_series(r = 3.2, n = 10, x0 = 0.1) x <- logistic_series(r = 4, n = 500, x0 = 0.2) plot(x, type = "l")
Values of at which the critical point 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.
logistic_superstable(k, cascade = c("feigenbaum", "period3"))logistic_superstable(k, cascade = c("feigenbaum", "period3"))
k |
Order (see Details); vectorised. |
cascade |
|
cascade = "feigenbaum": period , .
cascade = "period3": period , .
The values were computed by bisection on
.
A numeric vector of parameters.
logistic_superstable(0:5) x <- logistic_series(logistic_superstable(3), 32, x0 = 0.3) length(unique(x)) # period 8logistic_superstable(0:5) x <- logistic_series(logistic_superstable(3), 32, x0 = 0.3) length(unique(x)) # period 8
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).
max_visibility_point(x, type = c("horizontal", "natural"), itself = TRUE) greatest_basin_point(x, type = c("horizontal", "natural"))max_visibility_point(x, type = c("horizontal", "natural"), itself = TRUE) greatest_basin_point(x, type = c("horizontal", "natural"))
x |
A numeric series or a |
type |
Either |
itself |
If |
A single integer.
x <- c(4, 5, 6, 3, 6, 5, 3, 6, 7, 4, 7) max_visibility_point(x) greatest_basin_point(x)x <- c(4, 5, 6, 3, 6, 5, 3, 6, 7, 4, 7) max_visibility_point(x) greatest_basin_point(x)
Computes the partial visibility curve of a time series (Nuño and Muñoz,
2020): for every cardinality the largest
visibility of a set of points (see
partial_visibility_set()), normalised as and
. The curve is computed until the whole series is seen
(, which happens at the total visibility number) or until
m_max.
partial_visibility_curve( x, type = c("horizontal", "natural"), method = c("ga", "greedy", "exact"), m_max = NULL, control = list(), keep_sets = FALSE, verbose = FALSE )partial_visibility_curve( x, type = c("horizontal", "natural"), method = c("ga", "greedy", "exact"), m_max = NULL, control = list(), keep_sets = FALSE, verbose = FALSE )
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 |
With method = "ga" the search for points is seeded with the best
set found for points plus the best additional point, so the
computed curve is non-decreasing.
A data frame of class pvcurve with columns m, mu,
visibility and nu, starting at . Attributes type,
method and n store the settings.
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
pvc_length(), pvc_theoretical(), plot.pvcurve().
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)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)
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.
partial_visibility_set( x, m, type = c("horizontal", "natural"), method = c("ga", "greedy", "exact"), control = list() )partial_visibility_set( x, m, type = c("horizontal", "natural"), method = c("ga", "greedy", "exact"), control = list() )
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:
|
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 exactly m
points, 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).
A list with components set (indices of the chosen points),
visibility (cardinality of its basin), fraction (visibility / n),
m, n and method.
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
total_visibility(), partial_visibility_curve().
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") }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") }
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).
pattern_frequency(v, max_size = NULL, sep = "_")pattern_frequency(v, max_size = NULL, sep = "_")
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. |
A data frame with columns pattern, freq and length, sorted
by length and decreasing frequency.
Muñoz, F. J. and Nuño, J. C. (2020). Universal visibility patterns of unimodal maps. Chaos, 30. doi:10.1063/5.0006652
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)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)
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).
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, ...)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, ...)
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 |
The vgraph object, invisibly.
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)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)
Plot a partial visibility curve
## 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, ...)## 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, ...)
x |
A |
type, xlab, ylab, xlim, ylim
|
Graphical parameters. |
... |
NULL, invisibly.
plot(pvc_theoretical(1), type = "l") lines(pvc_theoretical(4), col = "red")plot(pvc_theoretical(1), type = "l") lines(pvc_theoretical(4), col = "red")
Euclidean length of the polygonal line through the points
of a partial visibility curve,
.
pvc_length(curve)pvc_length(curve)
curve |
A |
The length of the curve.
pvc_length(pvc_theoretical(3))pvc_length(pvc_theoretical(3))
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).
pvc_theoretical(k, cascade = c("feigenbaum", "period3"))pvc_theoretical(k, cascade = c("feigenbaum", "period3"))
k |
Order of the cascade (see Details). |
cascade |
|
cascade = "feigenbaum", period , : the
-polygonal is for
,
for and
for
, .
It reaches at the total visibility number
( for ).
cascade = "period3", period , :
for
and then
for
, ending at , .
A data frame of class pvcurve with columns mu and nu
(vertices of the polygonal).
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
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)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 -polygonals of pvc_theoretical(). With k = Inf
the limit at the accumulation point of the cascade is returned
(computed with , beyond which the value does not change in
double precision): for the
Feigenbaum cascade and for the
period-3 cascade (Nuño and Muñoz, 2020).
pvc_theoretical_length(k, cascade = c("feigenbaum", "period3"))pvc_theoretical_length(k, cascade = c("feigenbaum", "period3"))
k |
A vector of orders, possibly including |
cascade |
|
A numeric vector of lengths.
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])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])
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).
total_visibility( x, type = c("horizontal", "natural"), method = c("ga", "greedy", "exact"), control = list() )total_visibility( x, type = c("horizontal", "natural"), method = c("ga", "greedy", "exact"), control = list() )
x |
A numeric series or a |
type |
Either |
method |
One of |
control |
A list of parameters of the genetic algorithm:
|
With method = "greedy" and method = "ga" the result is an upper bound
(redundant points are always removed); method = "exact" gives the
optimum.
A list with components set, size, fraction (size / n),
n and method.
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
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 }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 }
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.
vgraph(x, type = c("horizontal", "natural"), tol = 0)vgraph(x, type = c("horizontal", "natural"), tol = 0)
x |
A numeric vector (or |
type |
Either |
tol |
Non-negative tolerance used only for the natural visibility:
node |
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).
plot_visibility(), vgraph_to_igraph().
g <- vgraph(c(3, 1, 4, 1, 5, 9, 2, 6), type = "natural") g g$degreeg <- vgraph(c(3, 1, 4, 1, 5, 9, 2, 6), type = "natural") g g$degree
Convert a visibility graph to an igraph object
vgraph_to_igraph(x, type = c("horizontal", "natural"), directed = FALSE)vgraph_to_igraph(x, type = c("horizontal", "natural"), directed = FALSE)
x |
A numeric series or a |
type |
Either |
directed |
If |
An igraph object. The series is stored in the vertex attribute
value and the visibility type in the graph attribute type.
if (requireNamespace("igraph", quietly = TRUE)) { ig <- vgraph_to_igraph(rnorm(50)) igraph::transitivity(ig, type = "global") igraph::mean_distance(ig) }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
visibility_degree( x, type = c("horizontal", "natural"), mode = c("total", "out", "in") )visibility_degree( x, type = c("horizontal", "natural"), mode = c("total", "out", "in") )
x |
A numeric series or a |
type |
Either |
mode |
|
An integer vector with one degree per observation.
x <- c(3, 1, 4, 1, 5, 9, 2, 6) visibility_degree(x) visibility_degree(x, mode = "out")x <- c(3, 1, 4, 1, 5, 9, 2, 6) visibility_degree(x) visibility_degree(x, mode = "out")
Distribution of the visibilities 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.
visibility_distribution(x, type = c("horizontal", "natural"), itself = TRUE)visibility_distribution(x, type = c("horizontal", "natural"), itself = TRUE)
x |
A numeric series or a |
type |
Either |
itself |
If |
A data frame with columns visibility, count and fraction.
x <- logistic_series(logistic_superstable(1), 200, x0 = 0.3) visibility_distribution(x)x <- logistic_series(logistic_superstable(1), 200, x0 = 0.3) visibility_distribution(x)
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
operations instead of the of the direct
definition.
visibility_edges(x, type = c("horizontal", "natural"), tol = 0)visibility_edges(x, type = c("horizontal", "natural"), tol = 0)
x |
A numeric vector (or a |
type |
Either |
tol |
Non-negative tolerance used only for the natural visibility:
node |
Two nodes see each other naturally when
for all ,
which is equivalent to the slope from to being strictly
larger than all the slopes from to the intermediate nodes. They see
each other horizontally when for all
. Both inequalities are strict, so equal intermediate values
block the visibility. Consecutive nodes are always linked.
An integer matrix with two columns, from and to, with one row
per link and from < to, sorted by from and then by to.
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
vgraph(), visibility_matrix(), vgraph_to_igraph().
x <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5) visibility_edges(x, type = "horizontal") visibility_edges(x, type = "natural")x <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5) visibility_edges(x, type = "horizontal") visibility_edges(x, type = "natural")
Kullback-Leibler divergence between the out-degree (forward) and in-degree
(backward) distributions of the directed visibility graph,
.
It vanishes asymptotically for time-reversible processes and is positive
for irreversible ones. Only degrees observed in both distributions
contribute to the sum.
visibility_irreversibility(x, type = c("horizontal", "natural"))visibility_irreversibility(x, type = c("horizontal", "natural"))
x |
A numeric series or a |
type |
Either |
The estimated divergence (in nats).
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.
set.seed(4) visibility_irreversibility(runif(5000)) # reversible: ~ 0 visibility_irreversibility(logistic_series(4, 5000, x0 = 0.3)) # > 0set.seed(4) visibility_irreversibility(runif(5000)) # reversible: ~ 0 visibility_irreversibility(logistic_series(4, 5000, x0 = 0.3)) # > 0
Returns the adjacency matrix of the natural or horizontal visibility graph, as a dense integer matrix or as a sparse matrix of package Matrix.
visibility_matrix( x, type = c("horizontal", "natural"), directed = FALSE, diag = FALSE, sparse = FALSE )visibility_matrix( x, type = c("horizontal", "natural"), directed = FALSE, diag = FALSE, sparse = FALSE )
x |
A numeric series or a |
type |
Either |
directed |
If |
diag |
If |
sparse |
If |
An matrix of zeros and ones.
visibility_matrix(c(1, 2, 1, 2, 1), type = "horizontal") visibility_matrix(c(1, 2, 3, 4), type = "natural", diag = TRUE)visibility_matrix(c(1, 2, 1, 2, 1), type = "horizontal") visibility_matrix(c(1, 2, 3, 4), type = "natural", diag = TRUE)
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.
visibility_motifs(x, size = 4L, type = c("horizontal", "natural"))visibility_motifs(x, size = 4L, type = c("horizontal", "natural"))
x |
A numeric vector (or a |
size |
Window size (default 4). |
type |
Either |
A data frame with columns motif, count and p.
Iacovacci, J. and Lacasa, L. (2016). Sequential visibility-graph motifs. Physical Review E, 93, 042309.
set.seed(5) visibility_motifs(runif(2000), size = 4)set.seed(5) visibility_motifs(runif(2000), size = 4)