Skip to content

Commit 40eea2c

Browse files
committed
Refactor LUSIM and improve docstrings
1 parent 9a354f1 commit 40eea2c

File tree

4 files changed

+14
-41
lines changed

4 files changed

+14
-41
lines changed

src/simulation/field.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function defaultsimulation(process::GaussianProcess, domain; data=nothing)
210210
end
211211
end
212212

213-
defaultsimulation(::IndicatorProcess, domain; data=nothing) = SEQSIM(path=RandomPath())
213+
defaultsimulation(::IndicatorProcess, domain; data=nothing) = SEQSIM()
214214

215215
# ----------------
216216
# IMPLEMENTATIONS

src/simulation/field/gaussian/lu.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ function preprocess(::AbstractRNG, process::GaussianProcess, method::LUSIM, init
77
f = process.func
88
μ = process.mean
99

10-
# method options
11-
factorization = method.factorization
12-
1310
# sanity checks
1411
isvalid(f) = isstationary(f) && issymmetric(f) && isbanded(f)
1512
if !isvalid(f)
@@ -59,18 +56,18 @@ function preprocess(::AbstractRNG, process::GaussianProcess, method::LUSIM, init
5956

6057
if isempty(dinds)
6158
d₂ = zero(eltype(z₁))
62-
L₂₂ = factorization(Symmetric(C₂₂)).L
59+
L₂₂ = cholesky(Symmetric(C₂₂)).L
6360
else
6461
# covariance beween data locations
6562
C₁₁ = _pairwise(cov, ddom)
6663
C₁₂ = _pairwise(cov, ddom, sdom)
6764

68-
L₁₁ = factorization(Symmetric(C₁₁)).L
65+
L₁₁ = cholesky(Symmetric(C₁₁)).L
6966
B₁₂ = L₁₁ \ C₁₂
7067
A₂₁ = transpose(B₁₂)
7168

7269
d₂ = A₂₁ * (L₁₁ \ z₁)
73-
L₂₂ = factorization(Symmetric(C₂₂ - A₂₁ * B₁₂)).L
70+
L₂₂ = cholesky(Symmetric(C₂₂ - A₂₁ * B₁₂)).L
7471
end
7572

7673
(; var, z₁, μ₁, d₂, L₂₂, dinds, sinds)

src/simulation/field/methods.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ A method for simulating field processes.
1010
abstract type FieldSimulationMethod end
1111

1212
"""
13-
LUSIM(; [options])
13+
LUSIM()
1414
15-
The LU simulation method introduced by Alabert 1987.
15+
The LU simulation method introduced by Alabert 1987 and Davis 1987.
1616
1717
The full covariance matrix is built to include all locations
1818
of the data, and samples from the multivariate Gaussian are
1919
drawn via a lower-upper (LU) matrix factorization.
2020
21-
## Options
22-
23-
`factorization` - Factorization function from LinearAlgebra (default to `cholesky`)
24-
2521
## References
2622
2723
* Alabert 1987. [The practice of fast conditional simulations
@@ -44,9 +40,7 @@ factorize the full covariance.
4440
For larger domains (e.g. 3D grids), other methods are preferred
4541
such as [`SEQSIM`](@ref) and [`FFTSIM`](@ref).
4642
"""
47-
@kwdef struct LUSIM{F} <: FieldSimulationMethod
48-
factorization::F = cholesky
49-
end
43+
struct LUSIM <: FieldSimulationMethod end
5044

5145
"""
5246
SEQSIM(; [options])
@@ -82,9 +76,9 @@ the nearest neighbors are used without additional constraints.
8276
8377
### Notes
8478
85-
This method is very sensitive to the neighbor search options.
86-
Care must be taken to make sure that enough neighbors are used
87-
in the underlying geostatistical model.
79+
This method is very sensitive to neighbor search options and
80+
simulation path. Care must be taken to make sure that enough
81+
neighbors are used in the underlying geostatistical model.
8882
"""
8983
@kwdef struct SEQSIM{P,N,D} <: FieldSimulationMethod
9084
path::P = LinearPath()
@@ -104,6 +98,9 @@ after a fast Fourier transform. White noise is added to the
10498
phase of the spectrum, and a realization is produced by an
10599
inverse Fourier transform.
106100
101+
Data conditioning is currently performed with Kriging, which
102+
accepts the following neighbor search options.
103+
107104
## Options
108105
109106
* `minneighbors` - Minimum number of neighbors (default to `1`)

test/field.jl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@
4242
@test eltype(real.field1) <: Float64
4343
@test eltype(real.field2) <: Float64
4444

45-
# custom factorization
46-
rng = StableRNG(123)
47-
grid = CartesianGrid(100)
48-
proc = GaussianProcess(SphericalCovariance(range=10.0))
49-
real = rand(rng, proc, grid; method=LUSIM(factorization=lu), data=data)
50-
@test eltype(real.Z) <: Float64
51-
5245
# 2D example
5346
rng = StableRNG(123)
5447
grid = CartesianGrid(100, 100)
@@ -61,7 +54,7 @@
6154
grid = CartesianGrid((100, 100), (0.5, 0.5), (1.0, 1.0))
6255
data = georef((; Z=[1.0, 0.0, 1.0]), [(25.0, 25.0), (50.0, 75.0), (75.0, 50.0)])
6356

64-
method = SEQSIM(neighborhood=MetricBall(35.0), maxneighbors=3)
57+
method = SEQSIM(maxneighbors=3)
6558

6659
# unconditional simulation
6760
rng = StableRNG(2017)
@@ -99,13 +92,6 @@
9992
data = georef((; Z=[1.0, 0.0, 1.0]), [(25.0, 25.0), (50.0, 75.0), (75.0, 50.0)])
10093
real = rand(rng, proc, grid, method=FFTSIM(maxneighbors=3), data=data)
10194
end
102-
103-
proc = GaussianProcess(GaussianVariogram())
104-
@test sprint(show, proc) == "GaussianProcess(func: GaussianVariogram(range: 1.0 m, sill: 1.0, nugget: 0.0), mean: 0.0)"
105-
@test sprint(show, MIME("text/plain"), proc) == """
106-
GaussianProcess
107-
├─ func: GaussianVariogram(range: 1.0 m, sill: 1.0, nugget: 0.0)
108-
└─ mean: 0.0"""
10995
end
11096

11197
@testset "IndicatorProcess" begin
@@ -174,13 +160,6 @@
174160
rng = StableRNG(2024)
175161
real = rand(rng, proc, mesh; data)
176162
@test isapprox(sum(real.Z) / length(real.Z), 0.0, atol=1e-3)
177-
178-
proc = LindgrenProcess()
179-
@test sprint(show, proc) == "LindgrenProcess(range: 1.0 m, sill: 1.0)"
180-
@test sprint(show, MIME("text/plain"), proc) == """
181-
LindgrenProcess
182-
├─ range: 1.0 m
183-
└─ sill: 1.0"""
184163
end
185164

186165
@testset "QuiltingProcess" begin

0 commit comments

Comments
 (0)