Skip to content

User-defined summaries

NeuralEstimators.variogram Function
julia
variogram(Z::AbstractVector, D::AbstractMatrix; n_bins = 20, maxlag = 0.5)
variogram(Z::AbstractMatrix; n_bins = 20, maxlag = 0.5)
variogram(Z::AbstractArray{<:Real,3}; n_bins = 20, maxlag = 0.5)

Empirical isotropic variogram,

where is the set of pairs whose distance falls in the bin containing . Distances are partitioned into n_bins equal-width bins. Empty bins are NaN.

maxlag is a relative cutoff in : the fraction of the maximum distance that is included (default 0.5). Bins span  , and pairs farther than that are dropped. For the pairwise method, is ; for the FFT methods, is the grid diagonal in grid steps.

The pairwise method takes observations Z at n locations and an n×n distance matrix D. The diagonal of D is excluded.

The matrix and 3-dimensional-array methods compute the same estimator on a complete regular grid via FFT (Marcotte, 1996), and require FFTW.jl (using FFTW). Distances are in grid steps, so no coordinate or distance matrix is required. A matrix is one field and returns a vector. A 3-dimensional array is a stack of fields and returns a matrix with size(Z, 3) columns.

See the GeoStats.jl variogram documentation.

Examples

julia
using NeuralEstimators

# Pairwise method (irregular locations)
using Distances, LinearAlgebra
n = 300
S = rand(n, 2)
D = pairwise(Euclidean(), S, dims = 1)
Σ = exp.(-D ./ 0.1)       
L = cholesky(Symmetric(Σ)).L
Z = L * randn(n)
variogram(Z, D)

# FFT method (complete regular grid; requires `using FFTW`)
using FFTW
using GaussianRandomFields
grid_dim = 64
pts = range(0, 1, grid_dim)
cov = CovarianceFunction(2, Exponential(0.1))
grf = GaussianRandomField(cov, CirculantEmbedding(), pts, pts; minpadding = grid_dim)
# one field
Z = sample(grf)                
variogram(Z)
# stack of fields
Z = [sample(grf) for _ in 1:5] |> stack
variogram(Z)
source
NeuralEstimators.NeighbourhoodVariogram Type
julia
NeighbourhoodVariogram(h_max, n_bins) 
(l::NeighbourhoodVariogram)(g::GNNGraph)

Computes the empirical variogram,

where    is the set of pairs of locations separated by a distance within   , and   denotes set cardinality.

The distance bins are constructed to have constant width , chosen based on the maximum distance h_max to be considered, and the specified number of bins n_bins.

The input type is a GNNGraph, and the empirical variogram is computed based on the corresponding graph structure. Specifically, only locations that are considered neighbours will be used when computing the empirical variogram.

Examples

julia
using NeuralEstimators, GraphNeuralNetworks, Distances, LinearAlgebra
  
# Simulate Gaussian spatial data with exponential covariance function 
θ = 0.1                                 # true range parameter 
n = 250                                 # number of spatial locations 
S = rand(n, 2)                          # spatial locations 
D = pairwise(Euclidean(), S, dims = 1)  # distance matrix 
Σ = exp.(-D ./ θ)                       # covariance matrix 
L = cholesky(Symmetric(Σ)).L            # Cholesky factor 
m = 5                                   # number of replicates 
Z = L * randn(n, m)                     # simulated data 

# Construct the spatial graph 
r = 0.15                                # radius of neighbourhood set
g = spatialgraph(S, Z, r = r)

# Construct the variogram object with 10 bins
nv = NeighbourhoodVariogram(r, 10) 

# Compute the empirical variogram 
nv(g)
source
NeuralEstimators.samplecorrelation Function
julia
samplecorrelation(Z::AbstractArray)

Computes the sample correlation matrix, R̂, and returns the vectorised strict lower triangle of R̂.

Examples

julia
# 5 independent replicates of a 3-dimensional vector
z = rand(3, 5)
samplecorrelation(z)
source
NeuralEstimators.samplecovariance Function
julia
samplecovariance(Z::AbstractArray)

Computes the sample covariance matrix, Σ̂, and returns the vectorised lower triangle of Σ̂.

Examples

julia
# 5 independent replicates of a 3-dimensional vector
z = rand(3, 5)
samplecovariance(z)
source
NeuralEstimators.samplesize Function
julia
samplesize(Z)

Computes the number of replicates in the data set Z.

Note that this function is a wrapper around numberreplicates with return type equal to the eltype of Z.

source
NeuralEstimators.logsamplesize Function
julia
logsamplesize(Z)

Computes the log of the number of replicates in the data set Z.

source
NeuralEstimators.invsqrtsamplesize Function
julia
invsqrtsamplesize(Z)

Computes the inverse of the square root of the number of replicates in the data set Z.

source