API Reference

This page provides a complete list of all exported functions and types.

MultifractalTools.bin_dataMethod
bin_data(data::AbstractMatrix, l::Integer) -> Matrix

Performs spatial coarse-graining (binning) of the data.

This function divides the input data matrix into non-overlapping square boxes of size l x l. It calculates the "measure" (probability) in each box by summing the abs2 of all elements within that box.

The abs2 (e.g., |ψ|^2) is used, as the multifractal measure μ is typically a probability distribution.

Arguments

  • data::AbstractMatrix: The input 2D data, assumed to be renormalized (though not strictly required).
  • l::Integer: The side length of the square bins.

Returns

  • A new Matrix (named BinnedData) of size floor.(size(data) ./ l), where each element is the sum of abs2(data[...]) within that bin.

Examples

```jldoctest julia> A = [1.0 1.0 2.0 2.0; 1.0 1.0 2.0 2.0; 3.0 3.0 4.0 4.0; 3.0 3.0 4.0 4.0] 4×4 Matrix{Float64}: 1.0 1.0 2.0 2.0 1.0 1.0 2.0 2.0 3.0 3.0 4.0 4.0 3.0 3.0 4.0 4.0

Bin with l=2

Box 1 (top-left): 1²+1²+1²+1² = 4

Box 2 (top-right): 2²+2²+2²+2² = 16

Box 3 (bottom-left): 3²+3²+3²+3² = 36

Box 4 (bottom-right): 4²+4²+4²+4² = 64

julia> MultifractalTools.bin_data(A, 2) 2×2 Matrix{Float64}: 4.0 16.0 36.0 64.0

source
MultifractalTools.compute_scaling_quantitiesMethod
compute_scaling_quantities(data, qs; ls=Integer[], crop_to_best_fit=true, crop_ratio=0.1)

Computes the core scaling quantities required for multifractal analysis.

This function calculates the partition function $Z(q, l)$, the entropy $S(q, l)$, and the average $\log(\mu)$ weighted by $\mu^q$ (which we call $Z'(q, l)$) for a given data matrix, across a range of q values and box sizes l.

Arguments

  • data::AbstractMatrix: The input 2D data (e.g., a wavefunction or probability distribution).
  • qs::AbstractVector: A vector of q values (the "moments") to analyze.

Keyword Arguments

  • ls::AbstractVector{<:Integer}: An optional vector of box sizes l to use. If left empty (default), the function will automatically determine box sizes based on the data size and other keyword arguments.
  • crop_to_best_fit::Bool: If true (default) and ls is empty, the function will find the largest "best" square size (with the most divisors) within crop_ratio of the original data size. If false, it uses the full data size.
  • crop_ratio::Float64: The fraction of the data size to search for a "best" size (default: 0.1). For a 1000x1000 matrix, it will search from 900-1000.

Returns

  • A NamedTuple containing:
    • ls: The vector of box sizes l that were used.
    • Zqs: An (l, q) matrix of the partition functions, $Z(q, l) = \sum_i \mu_i^q$.
    • Sqs: An (l, q) matrix of the information entropies, $S(q, l) = \sum_i p_i \log(p_i)$.
    • ZPrimes: An (l, q) matrix of the weighted log averages, $Z'(q, l) = \sum_i p_i \log(\mu_i)$.

Examples

```jldoctest julia> data = rand(128, 128); julia> qs = obtainqs(-5, 5, 11); julia> scalingdata = computescalingquantities(data, qs; croptobestfit=false); julia> scalingdata.ls 8-element Vector{Int64}: 1 2 4 8 16 32 64 128

source
MultifractalTools.compute_spectrumMethod
compute_spectrum(ScalingQuantities, qs, λ1, λ2) -> NamedTuple

Calculates the multifractal spectrum exponents ($ au(q)$, $lpha(q)$, $f(lpha)$) by fitting the results from compute_scaling_quantities.

This function performs a linear regression in log-log space to find the scaling exponents. For example, the multifractal exponent $ au(q)$ is found by fitting the power law $Z(q, psilon) \sim psilon^{ au(q)}$, which becomes linear in log space: $\log(Z) = au(q) \log(psilon) + C$.

The function fits this linear relationship using the power_law_model for $ au(q)$, $lpha(q)$, and $f(lpha)$ simultaneously.

Arguments

  • ScalingQuantities::NamedTuple: The NamedTuple output from compute_scaling_quantities.
  • qs::AbstractVector: The vector of q values. This must be the same qs vector used to generate the ScalingQuantities.
  • λ1::Integer: The starting index (not value) from ScalingQuantities.ls to use for the linear fit.
  • λ2::Integer: The ending index from ScalingQuantities.ls to use for the linear fit.

Returns

  • A NamedTuple containing the calculated spectra:
    • qs: The q values.
    • τqs: The vector of multifractal exponents, $ au(q)$.
    • αs: The vector of singularity spectrum $lpha(q)$.
    • fs: The vector of singularity spectrum $f(lpha)$.

Examples

```jldoctest julia> data = rand(128, 128); julia> qs = MultifractalTools.obtainqs(-5, 5, 3); # -5.0, 0.0, 5.0 julia> scalingdata = MultifractalTools.computescalingquantities(data, qs); julia> scaling_data.ls 8-element Vector{Int64}: 1 2 4 8 16 32 64 128

We fit using the scaling range from index 2 (l=2) to index 6 (l=32)

julia> spectrum = computespectrum(scalingdata, qs, 2, 6); julia> spectrum.τqs 3-element Vector{Float64}: 1.9999999999999996 -0.0 -2.0

source
MultifractalTools.find_best_scaling_sizeMethod
find_best_scaling_size(max_size::Integer, crop_ratio::Float64) -> NamedTuple

Finds an optimal square size for box-counting analysis near max_size.

This function searches for an integer n in the range [floor(max_size * (1 - crop_ratio)), max_size] that has the maximum number of divisors. This is useful for maximizing the number of available scaling sizes (l values) for the analysis, which improves the quality of the linear fits.

Arguments

  • max_size::Integer: The largest possible size (e.g., minimum(size(data))).
  • crop_ratio::Float64: The fraction of the max_size to search within. For example, 0.1 searches in the top 10% of the range.

Returns

  • A NamedTuple with two fields:
    • size: The integer n found to have the most divisors.
    • divisors: A Vector{Int} of the divisors of n.

Examples

```jldoctest

Search in the range [90, 100]

96 has 12 divisors: [1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 96]

100 has 9 divisors: [1, 2, 4, 5, 10, 20, 25, 50, 100]

julia> result = MultifractalTools.findbestscaling_size(100, 0.1);

julia> result.size 96

julia> result.divisors 12-element Vector{Int64}: 1 2 3 4 6 8 12 16 24 32 48 96

source
MultifractalTools.get_divisorsMethod
get_divisors(n::Integer) -> Vector{Int}

Finds all positive divisors of an integer n and returns them in a sorted vector.

The function computes divisors by iterating up to sqrt(n) for efficiency. It correctly handles n=0 (returning an empty list) and negative numbers (by taking the absolute value).

Arguments

  • n::Integer: The number to find the divisors of.

Returns

  • A Vector{Int} containing all divisors of n in ascending order.

Examples

```jldoctest julia> MultifractalTools.get_divisors(100) 9-element Vector{Int64}: 1 2 4 5 10 20 25 50 100

julia> MultifractalTools.get_divisors(17) 2-element Vector{Int64}: 1 17

source
MultifractalTools.obtain_qsMethod
obtain_qs(qmin::Number, qmax::Number, num_q::Integer) -> Vector{Float64}

Generates a vector of num_q q-values, linearly spaced between qmin and qmax.

Arguments

  • qmin: The minimum value for the q range.
  • qmax: The maximum value for the q range.
  • num_q: The number of q values to generate.

Returns

  • A Vector of Float64 values.

Examples

```jldoctest julia> obtain_qs(-5, 5, 3) 3-element Vector{Float64}: -5.0 0.0 5.0

source
MultifractalTools.power_law_modelMethod
power_law_model(x, p)

A simple linear model $f(x) = p_1 x + p_2$ used for fitting power-law data.

This function is intended to be passed to LsqFit.curve_fit to find scaling exponents from log-transformed data.

It represents a power law $y = C x^\alpha$ that has been transformed into log-log space: $\log(y) = \alpha \log(x) + \log(C)$.

In this model:

  • x corresponds to the log-transformed independent variable (e.g., $\log(l)$).
  • p[1] is the parameter for the slope (the scaling exponent $\alpha$).
  • p[2] is the parameter for the y-intercept (the prefactor $\log(C)$).

Arguments

  • x: The independent variable (e.g., log.(ls)).
  • p: A 2-element vector of parameters [slope, intercept].

Returns

  • The fitted value p[1] .* x .+ p[2].

Examples

```jldoctest julia> using LsqFit

Create data for a line y = 2x + 1

julia> xdata = [1.0, 2.0, 3.0, 4.0]; julia> ydata = [3.0, 5.0, 7.0, 9.0]; julia> p0 = [1.0, 0.0]; # Initial guess for [slope, intercept]

julia> fit = curvefit(MultifractalTools.powerlawmodel, xdata, y_data, p0);

julia> fit.param 2-element Vector{Float64}: 2.0 1.0

source
MultifractalTools.renormalize_dataMethod
renormalize_data(data::AbstractMatrix)

Normalizes the input data matrix according to its $L^2$-norm.

This ensures that the sum of the absolute squares of the elements is equal to 1. Mathematically, this computes: $D' = D / \sqrt{\sum |D_{ij}|^2}$

This is typically the first step in a multifractal analysis to treat the data as a probability distribution ($\|\psi\|^2 = 1$).

Arguments

  • data::AbstractMatrix: The input 2D data.

Returns

  • A new AbstractMatrix of the same size, with its elements scaled.

Examples

```jldoctest julia> A = [1.0 1.0; 1.0 1.0] 2×2 Matrix{Float64}: 1.0 1.0 1.0 1.0

julia> B = MultifractalTools.renormalize_data(A);

julia> sum(abs2.(B)) 1.0

source