User-defined summaries
NeuralEstimators.variogram Function
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 n_bins equal-width bins. Empty bins are NaN.
maxlag is a relative cutoff in 0.5). Bins span
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
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)NeuralEstimators.NeighbourhoodVariogram Type
NeighbourhoodVariogram(h_max, n_bins)
(l::NeighbourhoodVariogram)(g::GNNGraph)Computes the empirical variogram,
where
The distance bins are constructed to have constant width 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
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)NeuralEstimators.samplecorrelation Function
samplecorrelation(Z::AbstractArray)Computes the sample correlation matrix, R̂, and returns the vectorised strict lower triangle of R̂.
Examples
# 5 independent replicates of a 3-dimensional vector
z = rand(3, 5)
samplecorrelation(z)NeuralEstimators.samplecovariance Function
samplecovariance(Z::AbstractArray)Computes the sample covariance matrix, Σ̂, and returns the vectorised lower triangle of Σ̂.
Examples
# 5 independent replicates of a 3-dimensional vector
z = rand(3, 5)
samplecovariance(z)NeuralEstimators.samplesize Function
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.
NeuralEstimators.logsamplesize Function
logsamplesize(Z)Computes the log of the number of replicates in the data set Z.
NeuralEstimators.invsqrtsamplesize Function
invsqrtsamplesize(Z)Computes the inverse of the square root of the number of replicates in the data set Z.