Skip to content

Parameters

Sampled parameters (e.g., from the prior distribution) are often stored as   matrices, where is the dimension of the parameter vector of interest and is the number of sampled parameter vectors. However, any batchable object (compatible with numobs/getobs) is supported.

It can sometimes be helpful to wrap the parameters in a user-defined type that also stores expensive intermediate objects needed for simulating data (e.g., Cholesky factors). The user-defined type should be a subtype of AbstractParameterSet, whose only requirement is a field θ that stores parameters.

For convenience, parameters can be stored with named dimensions; see, for example, NamedMatrix.

NeuralEstimators.AbstractParameterSet Type
julia
AbstractParameterSet

An abstract supertype for user-defined types that store parameters and any auxiliary objects needed for data simulation.

The user-defined type must have a field θ that stores the parameters. Typically, θ is a × matrix, where is the dimension of the parameter vector and is the number of sampled parameter vectors, though any batchable object compatible with numobs/getobs is supported. There are no other requirements.

The number of parameter instances can be retrieved with numobs, and the size of θ can be inspected with size.

Subtypes of AbstractParameterSet support indexing via Base.getindex, with any batchable fields subsetted accordingly and all other fields left unchanged. To modify this default behaviour, provide a specific Base.getindex method for your concrete subtype.

Examples

julia
struct Parameters <: AbstractParameterSet
	θ
	# auxiliary objects needed for data simulation
end

θ = randn(2, 100)
parameters = Parameters(θ)
numobs(parameters)   # 100
size(parameters)     # (2, 100)
parameters[1:10]     # subset of 10 parameter vectors
source
NamedArrays.NamedMatrix Type
julia
NamedMatrix(; kwargs...)

Returns a NamedArray with named rows (parameters) and indexed columns (samples).

Examples

julia
NamedMatrix= randn(3), σ = rand(3))
source

Data

Simulated data sets are stored as mini-batches in a format amenable to the chosen neural-network architecture; the only requirement is compatibility with numobs/getobs. For example, when constructing an estimator from data collected over a two-dimensional grid, one may use a CNN, with each data set stored in the final dimension of a four-dimensional array.

Precomputed (expert) summary statistics can be incorporated by wrapping the simulated data in a DataSet object, which couples the raw data with a matrix of summary statistics.

NeuralEstimators.DataSet Type
julia
DataSet(Z, S)
DataSet(Z)

A container that couples raw data Z with precomputed expert summary statistics S (a matrix with one column per data set).

Passing a DataSet to any neural estimator causes the summary network to be applied to Z, with the resulting learned summary statistics concatenated with S before being passed to the inference network.

If S is not provided, DataSet(Z) is equivalent to passing Z directly.

See also summarystatistics.

Examples

julia
using NeuralEstimators
using Statistics: mean, var

# Simulate data: Z|μ,σ ~ N(μ, σ²)
n, m, K = 1, 50, 500
θ = rand(2, K)
Z = [θ[1, k] .+ θ[2, k] .* randn(n, m) for k in 1:K]

# Precompute expert summary statistics (e.g., sample mean and variance)
S = hcat([vcat(mean(z), var(z)) for z in Z]...)

# Package into a DataSet object
datasets = DataSet(Z, S)
source