Gaussian Processes
Types and functions for defining and sampling from Gaussian processes.
CovIterSolvers.AbstractBlockGP
— TypeAbstractBlockGP{T}
Abstract supertype for all Gaussian Process (GP), characterized by its covariance function.
CovIterSolvers.BrownianMotion
— TypeBrownianMotion([T=Float64])
A standard Brownian Motion / Wiener Process.
The covariance function is Σ(s, t) = min(s, t)
.
Examples
julia> bm = BrownianMotion();
julia> covariancekernel(bm, 0.2, 0.5)
0.2
CovIterSolvers.BrownianBridge
— TypeBrownianBridge([T=Float64])
A standard Brownian Bridge process, which is a Brownian Motion conditioned to be zero at t=0
and t=1
.
The covariance function is Σ(s, t) = min(s, t) - s * t
.
Examples
julia> bb = BrownianBridge();
julia> covariancekernel(bb, 0.2, 0.5)
0.1
CovIterSolvers.IntegratedBM
— TypeIntegratedBM([T=Float64])
An Integrated Brownian Motion process.
The covariance function is Σ(s, t) = max(s,t) * min(s,t)^2 / 2 - min(s,t)^3 / 6
.
Examples
julia> ibm = IntegratedBM();
julia> covariancekernel(ibm, 0.2, 0.5)
0.008666666666666668
CovIterSolvers.OrnsteinUhlenbeck
— TypeOrnsteinUhlenbeck(θ, σ)
An Ornstein-Uhlenbeck process, which models a mean-reverting stochastic process.
The covariance function is Σ(s, t) = (σ²/2θ) * (exp(-θ|s-t|) - exp(-θ(s+t)))
.
Arguments
θ::Real
: The mean reversion rate (must be positive).σ::Real
: The volatility parameter (must be non-negative).
Examples
julia> ou = OrnsteinUhlenbeck(1.0, 0.5);
julia> ou.θ
1.0
CovIterSolvers.CustomGP
— TypeCustomGP([T=Float64], Σ)
A Gaussian Process defined by a user-supplied covariance function Σ(s, t)
.
Arguments
T::Type
: The element type of the process. Defaults toFloat64
.Σ::Function
: A two-argument function(s, t) -> value
that defines the covariance.
Examples
julia> my_cov(s, t) = exp(-abs(s - t)); # Exponential covariance
julia> gp = CustomGP(my_cov);
julia> covariancekernel(gp, 0.2, 0.5) ≈ exp(-0.3)
true
CovIterSolvers.loc_grid
— Functionloc_grid([T=Float64], block_sizes; seed=nothing)
Generate a BlockVector
of random locations on the interval [0, 1).
This is useful for creating sample points for functional data, where each block represents the observation locations for a single function. Locations within each block are sorted for real-valued types.
Arguments
T::Type{<:Number}
: The element type of the locations. Defaults toFloat64
.block_sizes::Vector{Int}
: A vector specifying the number of locations for each block.
Keyword Arguments
seed::Union{Nothing,Int}
: An optional seed for reproducibility.
Examples
julia> loc = loc_grid([3, 2]; seed=42);
julia> blocklength(loc)
2
julia> blocksizes(loc, 1)
[3, 2]
julia> loc.blocks[1]
3-element Vector{Float64}:
0.4503389405961936
0.47740714343281776
0.6293451231426089
CovIterSolvers.covariancekernel
— Functioncovariancekernel(process, s, t)
covariancekernel(process, s)
covariancekernel(process, loc1, loc2)
covariancekernel(process, loc)
Compute the covariance for a given Gaussian Process.
This function has several methods:
covariancekernel(process, s, t)
: Computes the scalar covariance between two pointss
andt
.covariancekernel(process, s)
: Computes the covariance of a single points
with itself.covariancekernel(process, loc1, loc2)
: Computes the cross-covariance matrix between two vectors of locations.covariancekernel(process, loc)
: Computes the full covariance matrix (Gram matrix) for a single vector of locations.
Arguments
process::AbstractBlockGP
: The Gaussian Process object defining the covariance structure.s, t::Number
: Scalar locations.loc1, loc2, loc::AbstractVector
: Vectors of locations.
Examples
julia> bm = BrownianMotion();
julia> covariancekernel(bm, 0.3, 0.8) # scalar version
0.3
julia> loc = [0.1, 0.5, 0.9];
julia> K = covariancekernel(bm, loc) # matrix version
3×3 Matrix{Float64}:
0.1 0.1 0.1
0.1 0.5 0.5
0.1 0.5 0.9
See also sample_gp
for generating sample paths from the GP.
CovIterSolvers.sample_gp
— Functionsample_gp([μ], process, loc; jitter=1e-6, seed=nothing)
Generate one or more sample paths from a specified Gaussian Process.
Arguments
μ::Function
: (Optional) A mean functiont -> value
. Defaults to a zero mean.process::AbstractBlockGP
: The Gaussian Process object defining the covariance.loc::AbstractVector
orAbstractBlockVector
: A vector or block vector of locations. If aBlockVector
is provided, a separate sample path is generated for each block.
Keyword Arguments
jitter::Float64
: A small value added to the diagonal of the covariance matrix for numerical stability. Default is1e-6
.seed::Union{Nothing,Int}
: An integer seed for the random number generator to ensure reproducibility.
Returns
Vector
orBlockVector
: The generated sample path(s), matching the type ofloc
.
Examples
julia> loc = [0.1, 0.5, 0.9];
julia> bm = BrownianMotion();
julia> y = sample_gp(bm, loc; seed=123);
julia> length(y)
3