Internals
These are not exported and may change. Every local measure is built from LocalInformation.local_subset_entropies.
Local subset entropies
LocalInformation.local_subset_entropies — Function
LocalInformation.local_subset_entropies(est, x...; backend = CPU(), precision = nothing) → HThe internal core of the package. Return a callable H such that H(S) is a host Vector{T} of length N (the number of samples or encoded symbols) holding the local joint Shannon entropies $h(x_S)_i = -\log \hat p(x_S)_i$ of the inputs x[S], in the unit est.definition.base, with T = LocalInformation.resolve_precision(backend, precision). mean(H(S)) equals the estimate of the joint entropy of x[S] that Associations.jl uses for est (e.g. Associations.subset_entropies(est, x...)(S)).
H is directly usable as the entropy callable of Associations.entropy_combination (local higher-order measures) and to build local mutual informations, e.g. H((1,)) + H((2,)) - H((1, 2)).
The callable
Sis aTuple,Vectoror range of distinct indices in1:length(x); order does not matter.H(S)for an emptySreturnszeros(T, N).- Results are cached per subset (sorted index vector), so repeated calls are cheap. The returned vectors are the cached objects: do not mutate them.
His not safe to call concurrently from several tasks. - The concrete type is
LocalInformation.LocalSubsetEntropies.
Methods
JointProbabilitieswithCodifyVariablesand the defaultRelativeAmountprobabilities: plug-in local entropies from counts of the joint outcomes ofx[S], with the same encoding asAssociations.counts(est.discretization, x...). CPU.EntropyDecompositionwithPlugIn(Shannon()): the same, with the encoding ofAssociations.codified_marginals(est.discretization, x...). CPU.EntropyDecompositionwithKraskovorKozachenkoLeonenko: k-NN local entropies ofStateSpaceSet(x[S]...), usingLocalInformation.knn_distances.GaussianDecomposition,GaussianMI,GaussianCMI: Gaussian local entropies (seeLocalInformation.local_gaussian_entropies). CPU or GPU.
Extending
A new estimator family adds one method
function LocalInformation.local_subset_entropies(est::MyEstimator, x...; backend = CPU(), precision = nothing)
T = LocalInformation.resolve_precision(backend, precision)
N = ... # number of local values
h(S::Vector{Int}) = ... # Vector{T} of local entropies, unit est.definition.base
return LocalInformation.LocalSubsetEntropies{T}(h, N)
endafter which local_association works for its higher-order definitions, MIShannon and CMIShannon (see higher_order.jl and bivariate.jl).
LocalInformation.LocalSubsetEntropies — Type
LocalInformation.LocalSubsetEntropies{T}The callable returned by LocalInformation.local_subset_entropies. H(S) returns the Vector{T} of local joint entropies of the inputs with indices S, computed by H.h(key) for the sorted subset key::Vector{Int} and cached. H(()) (empty subset) returns zeros(T, H.N), the additive zero required by Associations.entropy_combination.
LocalInformation.local_gaussian_entropies — Function
LocalInformation.local_gaussian_entropies(model, S::Vector{Int}, backend, T) → Vector{T}Local Gaussian entropies, in nats, of the inputs with indices S, for a model built by GaussianLocalModel(x, copula, backend, T). See the comment at the top of gaussian.jl for the formula and its normalisation.
LocalInformation.local_knn_entropies — Function
LocalInformation.local_knn_entropies(X, k, w, backend, T; metric = Euclidean(), estimator = :kraskov) → Vector{T}Local k-NN entropies, in nats, of the points X (StateSpaceSet, vector or D × N matrix): -ψ(k) + ψ(N) + log V_D + D log ρ_i for estimator = :kraskov, and D log ρ_i + log V_D + γ + log(N - 1) (with k = 1) for estimator = :kozachenkoleonenko, where V_D is the unit-ball volume of metric. Kraskov and KozachenkoLeonenko (ComplexityMeasures) always use Euclidean().
Nearest neighbours
LocalInformation.knn_distances — Function
knn_distances(points, k::Integer, w::Integer = 0; metric = Euclidean(), backend = CPU(), precision = nothing) → Vector{T}
knn_distances(backend, P::AbstractMatrix, k::Int, w::Int, metric, T) → Vector{T}Distance from every point to its k-th nearest neighbour, excluding the neighbours j of point i with abs(i - j) ≤ w (a Theiler window; w = 0 excludes only the point itself). Returned as a host Vector{T} in the order of the points.
points is a StateSpaceSet, an AbstractVector (a 1-D variable) or a D × N matrix whose columns are the points. metric is a Distances.jl metric (Euclidean(), Chebyshev(), ...).
The second, positional form is the backend-dispatched implementation called by the first, with P a D × N host matrix (Float64, one column per point) and T = LocalInformation.resolve_precision(backend, precision). The CPU method uses a NearestNeighbors.KDTree (in Float64, converted to T); any other KernelAbstractions backend (a GPU) uses the exact brute-force kernel LocalInformation.gpu_knn, in precision T and for the metrics Euclidean(), Chebyshev() and Cityblock().
LocalInformation.log_ball_volume — Function
LocalInformation.log_ball_volume(metric, D) → Float64Natural logarithm of the volume of the D-dimensional unit ball of metric.
LocalInformation.kth_neighbours — Function
LocalInformation.kth_neighbours(backend, P::AbstractMatrix, k, w, metric, T) → (dists, idxs)Distance to and index of the k-th nearest neighbour of every column of P outside the Theiler window w. The CPU method searches a KDTree point by point, as Neighborhood.bulksearch(tree, points, NeighborNumber(k), Theiler(w)) does in Associations (so ties are resolved identically); the GPU method is LocalInformation.gpu_knn.
LocalInformation.range_counts — Function
LocalInformation.range_counts(backend, P::AbstractMatrix, r::AbstractVector, metric, T) → Vector{Int}For every column i of P, the number of columns j with metric(P[:, i], P[:, j]) ≤ r[i], including i itself and without Theiler window: NearestNeighbors.inrangecount on the CPU, LocalInformation.gpu_range_counts on a GPU.
LocalInformation.ksg_counts — Function
LocalInformation.ksg_counts(est, x...; backend = CPU(), precision = nothing) → Vector{Vector{Int}}The per-sample neighbour counts behind the local values of est, one vector per term:
KSG1: $n_m(t)$ for every marginalm(≤ ε_t, the point itself included);KSG2: $θ_m(t)$ for every marginalm(≤ ε_m(t), the point itself excluded);FPVP: $[n_{xz}, n_{yz}, n_z]$ (≤ ε_t, the point itself included).
On a GPU in Float32, a distance that ties with (or rounds across) a radius can shift a count by one relative to the Float64 CPU computation.
LocalInformation.gpu_knn — Function
LocalInformation.gpu_knn(backend::KernelAbstractions.Backend, P::AbstractMatrix, k, w, metric, T) → (dists::Vector{T}, idxs::Vector{Int})Exact brute-force search on backend, in precision T: for every column i of the D × N matrix P, the distance to and the index of its k-th nearest neighbour among the columns j with abs(i - j) > w. Ties in distance are broken by the lower index. metric is Euclidean(), Chebyshev() or Cityblock().
LocalInformation.gpu_range_counts — Function
LocalInformation.gpu_range_counts(backend::KernelAbstractions.Backend, P::AbstractMatrix, r::AbstractVector, metric, T) → Vector{Int}For every column i of the D × N matrix P, the number of columns j (including i itself, and with no Theiler window) at distance ≤ r[i] from it, computed on backend in precision T. Same semantics as NearestNeighbors.inrangecount(KDTree(P, metric), P[:, i], r[i]).
Backends and precision
LocalInformation.default_precision — Function
LocalInformation.default_precision(backend) → Type{<:AbstractFloat}The element type used when precision = nothing: Float64 on CPU(), Float32 on any GPU backend (consumer GPUs run Float64 at a small fraction of the Float32 rate).
LocalInformation.check_backend — Function
LocalInformation.check_backend(backend) → nothingThrow an ArgumentError if backend cannot be used. Package extensions add methods for their backend types (the CUDA extension checks CUDA.functional()).
LocalInformation.resolve_precision — Function
LocalInformation.resolve_precision(backend, precision) → TValidate backend (with LocalInformation.check_backend) and return the element type to compute in: precision if it is a floating-point type, and LocalInformation.default_precision(backend) if it is nothing.
LocalInformation.to_device — Function
LocalInformation.to_device(backend, A::AbstractArray, T) → array on `backend`Copy A, converted to element type T, to backend (KernelAbstractions.allocate + copyto!). On the CPU an Array{T} is returned as is, without copying.
LocalInformation.to_host — Function
LocalInformation.to_host(A) → ArrayCopy a device array to host memory (Array(A); a no-op for an Array).
Subset counts (PID and ΦID)
LocalInformation.SubsetCounts — Type
LocalInformation.SubsetCounts
LocalInformation.SubsetCounts(codes::AbstractVector) → SubsetCountsPlug-in counts of every nonempty subset of k inputs, per distinct joint state of all the inputs (K states, N samples), from the per-sample codes codes[1], …, codes[k] (any hashable values, e.g. integers or StateSpaceSet points). A subset is a bitmask M in 1:2ᵏ-1, input i being bit i - 1.
ninputs:k;N: the number of samples.state[i]: the joint state (1:K) of samplei, numbered in order of first appearance;weight[s]: its number of samples.counts[s, M]: the number of samples whose inputs inMhave the values of states(K × (2ᵏ - 1)).
The joint labellings of the subsets are built depth first, each from its parent's, so at most k label vectors are alive. Counts are stored as Float64 (exact for counts below 2⁵³), so that inclusion–exclusion sums are matrix products.
Layouts used:
- PID of
nsources and a target (k = n + 1, the target is inputn + 1, bitn): columns1:2ⁿ-1are the source sets (bitmasks of Associations' redundancy lattice), column2ⁿthe target, and column2ⁿ + Msource setMjointly with the target (seeLocalInformation.pid_counts). - ΦID of
nvariables (k = 2n): past variableiis biti - 1, future variableibitn + i - 1.
LocalInformation.pid_counts — Function
LocalInformation.pid_counts(sc::SubsetCounts) → (src, srct, tgt)Views into the counts of a PID of n = sc.ninputs - 1 sources and a target (the last input): src[s, M] and srct[s, M] are the numbers of samples whose sources in the set M (1:2ⁿ-1) have the values of state s, without and with the target value of state s, and tgt[s] the number of samples with that target value.
LocalInformation.PIDLatticeData — Type
LocalInformation.PIDLatticeDataData derived once per number of sources n from Associations' (shared, never modified) redundancy_lattice(n):
sx: the(2ⁿ - 1) × minclusion–exclusion coefficients ofISx: $P(a_1 \cup \ldots \cup a_k) = \sum_M$sx[M, node]$P(x_M)$, withsx[M, node]$= \sum_{J \subseteq \alpha,\, \bigcup J = M} (-1)^{|J|+1}$.zeta: the zeta matrix of the lattice in the orderlattice.order,zeta[a, b] = 1if nodeorder[a]≼ nodeorder[b]. It is unit upper triangular, and the atoms are $A = R Z^{-1}$ for local redundanciesR(one column per node, in that order).
ΦID
The product lattice and the average atoms:
LocalInformation.PhiIDLattice — Type
LocalInformation.PhiIDLatticeData for the ΦID of n variables, built once per n by LocalInformation.phiid_lattice(n) from Associations' (shared, never modified) PID lattice redundancy_lattice(n), with m nodes (4 for n = 2, 18 for n = 3) and m² ΦID atoms.
Fields
lattice::RedundancyLattice: the PID lattice. Nodes are referred to by their index inlattice.nodes("node order").zeta::BitMatrix: them × mzeta matrix in the orderlattice.order,zeta[a, b] = 1iff nodeorder[a]≼ nodeorder[b]; unit upper triangular.mobius::Matrix{Int}: $Z^{-1}$ (the Möbius function, exact) in node order:mobius[i, j]= $\mu(\alpha_i, \alpha_j)$. For redundanciesR(m × m, node order, rows = past) the atoms aremobius' * R * mobius.kron::Matrix{Int}:kron(mobius, mobius),m² × m². For local redundancies as rows of aK × m²matrix in theveclayout (columni + (j - 1) mfor past nodeiand future nodej), the local atoms areR * kron, in the same layout.pairs::Vector{CartesianIndex{2}}: all(past node, future node)pairs from the bottom to the top of the product lattice (lexicographic inlattice.order, past first; a linear extension of the product order). Forn = 2this is the order ofphyid:rtr, rtx, rty, rts, xtr, …, sts.
LocalInformation.phiid_lattice — Function
LocalInformation.phiid_lattice(n::Int) → PhiIDLatticeThe LocalInformation.PhiIDLattice of n variables (1 ≤ n ≤ 3), built once and cached (thread-safe). Do not modify it.
LocalInformation.phiid_mobius — Function
LocalInformation.phiid_mobius(lattice::PhiIDLattice, R::AbstractMatrix) → MatrixThe ΦID atoms $\Pi = Z^{-\top} R Z^{-1}$ of the double redundancies R (m × m, node order, rows = past nodes), in the same layout: lattice.mobius' * R * lattice.mobius. The Möbius matrix is exact (integers), so integer redundancies give exact atoms.
LocalInformation.PHIID_INFORMATION_DYNAMICS — Constant
LocalInformation.PHIID_INFORMATION_DYNAMICSThe six information-dynamics modes of a two-variable ΦID (Mediano et al. 2021, 2025), as sums of named atoms (see information_dynamics); they partition the 16 atoms. The single place to change the definitions.
LocalInformation.phiid_prepare — Function
LocalInformation.phiid_prepare(est, x...) → (est′, past::Tuple, future::Tuple)Validate the inputs of association(est, x...) for a ΦID estimator, encode discrete data once with LocalInformation.phiid_series and lag by est.definition.τ with LocalInformation.lag_series. past and future are then given to LocalInformation.phiid_from_past_future(est′, past, future).
LocalInformation.phiid_series — Function
LocalInformation.phiid_series(est, x::Tuple) → (est′, s::Tuple)The full-length series that ΦID lags, and the estimator to apply to the lagged series.
- Discrete estimators:
sare the per-sample codes ofx(relabelled to1, 2, …per variable), encoded once over the full length with the estimator's discretization, exactly asJointProbabilities(seejoint_codes) orEntropyDecomposition(decomposition_codes) encode them;est′is the same estimator family withCodifyVariables(UniqueElements()). - Continuous estimators:
s = xandest′ = est.
Unsupported estimators throw an ArgumentError.
LocalInformation.lag_series — Function
LocalInformation.lag_series(s::Tuple, τ::Int) → (past::Tuple, future::Tuple)past[k] = s[k][1:N-τ] and future[k] = s[k][1+τ:N] (copies), for series of equal length N > τ.
LocalInformation.phiid_from_past_future — Function
LocalInformation.phiid_from_past_future(est, past::Tuple, future::Tuple) → PhiIDResultThe ΦID of the system whose past variables are past and future variables future (n = 2 or 3 each, all with the same number of samples), with no lagging or shared encoding: est is applied to the 2n inputs (past..., future...) as given (inputs 1:n are the past, n+1:2n the future). association(est, x...) calls this after LocalInformation.phiid_prepare; it is also the entry point for an exact joint distribution given as samples of (past, future) states, e.g. with JointProbabilities(def, CodifyVariables(UniqueElements())) and integer states.
The double redundancies come from LocalInformation.phiid_redundancies(est.definition.redundancy, est, lattice, past, future) and the atoms from LocalInformation.phiid_mobius. est.definition.τ is not used.
LocalInformation.phiid_redundancies — Function
LocalInformation.phiid_redundancies(r::RedundancyFunction, est, lattice::PhiIDLattice, past::Tuple, future::Tuple) → MatrixThe extension hook for double redundancies: return the m × m matrix R with R[i, j] = $I_\cap^{\alpha_i \to \alpha_j}$, the double redundancy of past node i and future node j (indices into lattice.lattice.nodes), in the unit est.definition.base.
est is applied to the 2n inputs (past..., future...) as given (for discrete data these are integer codes and est uses CodifyVariables(UniqueElements()), see LocalInformation.phiid_series). Associations.lattice_node_vectors reads a node as variable sets.
Methods
IMMI, any estimator withAssociations.subset_entropies:R[i, j] = min(I(past_A; future_B) for A in αᵢ, B in αⱼ), withI = H(A) + H(B) - H(A ∪ B)(one mutual information per pair of variable sets).ISxandIPMwithJointProbabilities(aCodifyVariablesdiscretization, plug-in probabilities;src/phiid_pointwise.jl): the mean over samples of the pointwise double redundancies, computed once per distinct joint state of the2ninputs from theirLocalInformation.SubsetCounts. Other estimators throw anArgumentError.IMin(no double-redundancy form) and every other redundancy function throw anArgumentError.
Add a method for a new redundancy function (and estimator), e.g. LocalInformation.phiid_redundancies(r::MyRedundancy, est::JointProbabilities, lattice, past, future).
Per-sample atoms with ISx and IPM, and the inversion helper:
LocalInformation.local_phiid_from_past_future — Function
LocalInformation.local_phiid_from_past_future(est, past::Tuple, future::Tuple;
backend = CPU(), precision = nothing, memory_limit = 2^31) → LocalPhiIDResultThe per-sample ΦID with ISx or IPM of the system whose past variables are past and future variables future (n = 2 or 3 each, all with the same number of samples N), for est = JointProbabilities(IntegratedInformationDecomposition(r), CodifyVariables(o)): the per-sample analogue of LocalInformation.phiid_from_past_future, with no lagging or shared encoding. Row t of the result is sample t. local_association(est, x...) calls this after LocalInformation.phiid_prepare; it is also the entry point for an exact joint distribution given as samples of (past, future) states. The keywords are those of local_association.
LocalInformation.PhiIDPointwiseData — Type
LocalInformation.PhiIDPointwiseDataData for the ΦID of n variables with ISx and IPM, built once per n by LocalInformation.phiid_pointwise_data(n) from the LocalInformation.PhiIDLattice (m nodes, in node order). Input masks are over the 2n inputs of a LocalInformation.SubsetCounts: past variable i is bit i - 1, future variable i bit n + i - 1.
Fields
lattice::PhiIDLattice: the shared lattice ofphiid_lattice(n).sx::Matrix{Float64}:(2²ⁿ - 1) × (2m + m²)inclusion–exclusion coefficients (integers). For subset countsC(K × (2²ⁿ - 1), one row per joint state),U = C * sxholds the counts of the samples in the unions of the events of a state: columnifor past node $\alpha_i = \{A_1, \ldots\}$: $c(\bigcup_k \{A_k = a_k\})$; columnm + jfor future node $\beta_j$: $c(\bigcup_l \{B_l = b_l\})$; column2m + i + (j - 1) m: $c(\bigcup_{k,l} \{A_k \cup B_l \text{ take their values}\})$, the union over all pairs (theveclayout of phiid.jl).past::Vector{Vector{Int}},future::Vector{Vector{Int}}: the input masks of the variable sets of each node, read as past and as future sets.
LocalInformation.phiid_local_atoms — Function
LocalInformation.phiid_local_atoms(lattice::PhiIDLattice, R::AbstractMatrix, rows = nothing;
backend = CPU(), precision = nothing, memory_limit = 2^31) → Matrix{T}Per-sample ΦID atoms from per-sample double redundancies, with one matrix product R * lattice.kron (i.e. $\Pi = Z^{-\top} R Z^{-1}$ for every row) on backend, in precision T = LocalInformation.resolve_precision(backend, precision). Returns a host Matrix{T}.
R:K × m²local double redundancies, one row per distinct joint state (or per sample), in theveclayout: columni + (j - 1) mis the pair (past nodei→ future nodej), nodes indexed as inlattice.lattice.nodes. Any unit; the atoms have the same.rows:nothing(the rows ofRare the samples; the result isK × m²) or a vector ofNrow indices in1:K, the row ofRof each sample (the result isN × m², rowtholding the atoms of rowrows[t]).
By linearity, the mean of the local atoms is the inversion of the mean local redundancy. An ArgumentError is thrown before any large allocation if the estimated memory (bytes) exceeds memory_limit.
LocalInformation.local_phiid_result — Function
LocalInformation.local_phiid_result(definition, lattice, R, rows = nothing; kwargs...) → LocalPhiIDResultA LocalPhiIDResult from per-sample double redundancies R (K × m²) and the row of each sample, computed by LocalInformation.phiid_local_atoms (the keywords are passed on).
Per-sample atoms with IMMI:
LocalInformation.local_phiid_mmi — Function
LocalInformation.local_phiid_mmi(est, past::Tuple, future::Tuple;
backend = CPU(), precision = nothing, memory_limit = 2^31) → LocalPhiIDResultPer-sample MMI ΦID atoms (see local_association for an IntegratedInformationDecomposition with IMMI) of the system whose past variables are past and future variables future, with no lagging or shared encoding: est is applied to the 2n inputs (past..., future...) as given, like LocalInformation.phiid_from_past_future does for the average atoms. Rows are the samples of past and future.
LocalInformation.local_pair_mutual_informations — Function
LocalInformation.local_pair_mutual_informations(H, n, T, N) → Matrix{T}The N × (2ⁿ - 1)² local mutual informations i_t(A; B) = h_t(A) + h_t(B) - h_t(A ∪ B) between every nonempty set A of the past variables (inputs 1:n of H) and B of the future variables (inputs n+1:2n), from the local subset entropies H. Column a + (b - 1)(2ⁿ - 1) holds the pair with bitmasks a of A and b of B. The 2(2ⁿ - 1) single-side entropies are cached in H; the joint ones are computed once each, uncached.
LocalInformation.mmi_pair_selection — Function
LocalInformation.mmi_pair_selection(lattice::PhiIDLattice, μ::AbstractVector) → Vector{Int}For every ΦID atom column c = i + (j - 1) m (past node i, future node j), the column of the local-MI matrix (see LocalInformation.local_pair_mutual_informations) of the pair (A, B) ∈ αᵢ × αⱼ with the smallest mean μ. Candidates are ordered by the bitmask of A, then of B; the first whose mean is within LocalInformation.PHIID_MMI_TIE_RTOL* max(1, maximum(abs, μ)) (finite μ) of the smallest is selected. A NaN among the candidates selects the first NaN pair.
LocalInformation.mmi_selection_weights — Function
LocalInformation.mmi_selection_weights(lattice::PhiIDLattice, sel::AbstractVector{Int}, np::Int) → Matrix{Int}W = S * lattice.kron (np × m²), with S[sel[c], c] = 1 the selection of a local-MI column for every ΦID atom column c: the local atoms of local MIs Lmi (N × np) are Lmi * W. Row p of W is the sum of the rows c of kron with sel[c] == p.
LocalInformation.PHIID_MMI_TIE_RTOL — Constant
LocalInformation.PHIID_MMI_TIE_RTOL = 1e-12Relative tolerance for ties in the pair selection of per-sample ΦID atoms with IMMI: a pair counts as tied with the smallest mean local mutual information Īₘᵢₙ if its mean is at most Īₘᵢₙ + PHIID_MMI_TIE_RTOL * max(1, maximum(abs, Ī)), the maximum over all pairs of variable sets with finite means. Exactly tied means can differ by summation-order rounding (~1e-14); this makes the documented tie-break independent of it.