Utils

This section describes utility functionalities provided by RecurrenceMicrostatesAnalysis.jl, including parameter optimization and operations on recurrence microstates.

Optimizing a parameter

When working with recurrence plots (RPs), a well-known challenge is selecting an appropriate recurrence threshold. Within the RMA framework, this issue is addressed by optimizing an information-theoretic or complexity-based measure with respect to the threshold parameter.

In practice, it is common to determine the threshold that maximizes either the RecurrenceEntropy or the Disorder quantifier (Lima Prado et al., 2023).

This optimization procedure is implemented via the optimize function, which computes the optimal value of a given Parameter.

Parameters

RecurrenceMicrostatesAnalysis.ThresholdType
Threshold <: Parameter

Threshold parameter used to classify two states as recurrent or non-recurrent.

The Threshold parameter can be optimized using the optimize function in combination with specific QuantificationMeasures:

optimize(::Threshold, qm::RecurrenceEntropy, [x], n::int; kwargs...)
optimize(::Threshold, qm::Disorder{N}, [x]; kwargs...)
Compat

Threshold optimization using RMA is currently supported only for the RecurrenceEntropy and Disorder quantification measures.

Arguments

  • qm: A QuantificationMeasure used to determine the optimal threshold. Supported measures are RecurrenceEntropy and Disorder.
  • [x]: Input data used to estimate the optimal threshold.
  • n: Size of the square microstate used in the optimization.

Returns

A Tuple{Float64, Float64}, where:

  • the first element is the optimal threshold value, and
  • the second element is the value of the corresponding QuantificationMeasure at the optimum.

Keyword Arguments

  • rate: Sampling rate. Default is 0.05.
  • sampling: Sampling mode. Default is SRandom.
  • th_max_range: Fraction of the maximum distance defining the upper bound of the threshold search range. Default is 0.5.
  • th_start: Initial value of the threshold search range. Default is 1e-6.
  • fraction: Interaction fraction controlling the refinement process. Default is 5.

Example

using Distributions, RecurrenceMicrostatesAnalysis
data = StateSpaceSet(rand(Uniform(0, 1), 1000))
th, s = optimize(Threshold(), RecurrenceEntropy(), data, 3)
source

Operations on microstates

The package also provides a set of operations that can be applied to recurrence microstates or to their decimal representations.

Permutations and Transposition

When working with square microstates, it is natural to consider symmetry operations such as row and column permutations, as well as transposition. These operations are particularly important for defining equivalence classes used in the computation of the Disorder quantifier.

To illustrate these operations, we consider a square microstate of size $3 \times 3$:

\[\mathbf{M} = \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & i \end{pmatrix}.\]

Info

The primary purpose of these operations is to define equivalence classes of microstates used in the computation of Disorder.

Permutations of Rows

Let $\sigma \in S_N$ be a permutation, where $S_N$ is the symmetric group, and let $\mathcal{L}_\sigma$ denote the operator that permutes the rows of a microstate $\mathbf{M}$ according to $\sigma$.

For example, for $\sigma = 132$, the third and second rows are exchanged, while the first row remains unchanged:

\[\mathcal{L}_{132}\mathbf{M} = \begin{pmatrix} a & b & c \\ g & h & i \\ d & e & f \end{pmatrix}.\]

For a given microstate size $n$, all possible row (or column) permutations can be generated using the Combinatorics.jl package:

using Combinatorics

n = 3
Sn = collect(permutations(1:n))
6-element Vector{Vector{Int64}}:
 [1, 2, 3]
 [1, 3, 2]
 [2, 1, 3]
 [2, 3, 1]
 [3, 1, 2]
 [3, 2, 1]
σ = Sn[2]
3-element Vector{Int64}:
 1
 3
 2

The permutation is applied using PermuteRows operation. For example, consider the square $3\times 3$ microstate with decimal index $I = 237$:

\[\mathbf{M} = \begin{pmatrix} 0 & 0 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}.\]

using RecurrenceMicrostatesAnalysis

shape = Rect(n, n)
row_permutation = PermuteRows(shape)

operate(row_permutation, 237, σ)
349

The result is the microstate with decimal identifier $I = 239$, corresponding to:

\[\mathcal{L}_{132}\mathbf{M} = \begin{pmatrix} 0 & 0 & 1 \\ 1 & 1 & 0 \\ 1 & 0 & 1 \end{pmatrix}.\]

RecurrenceMicrostatesAnalysis.PermuteRowsType
PermuteRows{R, C} <: Operation

Operation that permutes the rows of a microstate $\mathbf{M}$.

To initialize a PermuteRows operation, a rectangular microstate shape must be provided via a Rect structure:

PermuteRows(::Rect2{R, C, B, E})

Examples

PermuteRows(Rect(3, 3))     #   Microstate 3 x 3
PermuteRows(Rest(3, 1))     #   Microstate 3 x 1 (it is a column)

This operation is applied via the operate function:

operate(::PermuteRows, I::Int, σ::Vector{Int})

Arguments

  • op: A PermuteRows operation.
  • I: Decimal identifier of the microstate (1-based).
  • σ: Permutation of rows to be applied.

Returns

The resulting microstate binary identifier (1-based).

source

Permutations of Columns

Column permutations follow the same logic as row permutations, but are applied to the columns of the microstate.

Let $\mathcal{C}_\sigma$ denote the operator that permutes the columns of $\mathbf{M}$ according to $\sigma \in S_N$. For $\sigma = 132$, the transformation is given by:

\[\mathcal{C}_{132}\mathbf{M} = \begin{pmatrix} a & c & b \\ d & f & e \\ g & i & h \end{pmatrix}.\]

Using the same example of $I = 237$, column permutation is performed using the PermuteColumns operation:

col_permutation = PermuteColumns(shape; S = Sn)
PermuteColumns{3, 3}(Vector{UInt32}[[0x00000000, 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007], [0x00000000, 0x00000001, 0x00000004, 0x00000005, 0x00000002, 0x00000003, 0x00000006, 0x00000007], [0x00000000, 0x00000002, 0x00000001, 0x00000003, 0x00000004, 0x00000006, 0x00000005, 0x00000007], [0x00000000, 0x00000002, 0x00000004, 0x00000006, 0x00000001, 0x00000003, 0x00000005, 0x00000007], [0x00000000, 0x00000004, 0x00000001, 0x00000005, 0x00000002, 0x00000006, 0x00000003, 0x00000007], [0x00000000, 0x00000004, 0x00000002, 0x00000006, 0x00000001, 0x00000005, 0x00000003, 0x00000007]])
operate(col_permutation, 237, 2)
347

The resulting microstate has decimal identifier $I = 347$, corresponding to:

\[\mathcal{C}_{132}\mathbf{M} = \begin{pmatrix} 0 & 1 & 0 \\ 1 & 1 & 0 \\ 1 & 0 & 1 \end{pmatrix}.\]

RecurrenceMicrostatesAnalysis.PermuteColumnsType
PermuteColumns{R, C} <: Operation

Operation that permutes the columns of a microstate $\mathbf{M}$.

To initialize a PermuteColumns operation, a rectangular microstate shape must be provided via a Rect structure:

PermuteColumns(::Rect2{R, C, B, E}; S::Vector{Vector{Int}} = collect(permutations(1:C))

Here, the keyword argument S defines the set $S_n$ of column permutations. The PermuteColumns struct precomputes the column permutations for each row of the microstate. These precomputed permutations can be accessed via the field Q.

Examples

PermuteColumns(Rect(3, 3))     #   Microstate 3 x 3
PermuteColumns(Rest(1, 3))     #   Microstate 1 x 3 (it is a line)

This operation is applied via the operate function:

operate(op::PermuteColumns, I::Int, Qi::Int)

Arguments

  • op: A PermuteColumns operation.
  • I: Decimal identifier of the microstate (1-based).
  • Qi: Index of the permutation in the set S.

Returns

The resulting microstate decimal identifier (1-based).

source

Transposition

Transposition exchanges rows and columns of a microstate. Let $\mathcal{T}$ denote the transposition operator:

\[\mathcal{T}\mathbf{M} = \begin{pmatrix} a & d & g \\ b & e & f \\ c & f & i \end{pmatrix}.\]

Using the same example microstate with identifier $I = 237$, transposition is performed via the Transpose operator:

transposition = Transpose(shape)
operate(transposition, 237)
231

The resulting microstate has decimal identifier $I = 231$ corresponding to:

\[\mathcal{T}\mathbf{M} = \begin{pmatrix} 0 & 1 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}.\]

RecurrenceMicrostatesAnalysis.TransposeType
Transpose{R, C} <: Operation

Operation that transposes a microstate $\mathbf{M}$.

To initialize a Transpose operation, a rectangular microstate shape must be provided via a Rect structure:

Transpose(::Rect2{R, C, B, E})

Examples

Transpose(Rect(3, 3))     # 3 x 3 microstate

This operation is applied via the operate function:

operate(::Transpose, I::Int)

Arguments

  • op: A Transpose operation.
  • I: DEcima identifier of the microstate (1-based).

Returns

The resulting microstate decimal identifier (1-based).

source