From e0ad400f9abc09e0af77c44c1c0455c57e2edd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Hoffimann?= Date: Mon, 28 Oct 2024 15:14:58 -0300 Subject: [PATCH] ExponentialTransiogram --> MatrixExponentialTransiogram --- ext/transioplot.jl | 2 +- src/GeoStatsFunctions.jl | 2 +- src/theoretical/transiogram.jl | 2 +- .../{exponential.jl => matrixexponential.jl} | 30 +++++++++---------- test/theoretical/transiogram.jl | 12 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) rename src/theoretical/transiogram/{exponential.jl => matrixexponential.jl} (63%) diff --git a/ext/transioplot.jl b/ext/transioplot.jl index cdd2d58..5ff6a45 100644 --- a/ext/transioplot.jl +++ b/ext/transioplot.jl @@ -96,7 +96,7 @@ function transioplot( p = normalize(diag(t(100H)), 1) # base transiogram model - t̂ = ExponentialTransiogram(r, p) + t̂ = MatrixExponentialTransiogram(r, p) t̂s = t̂.(hs) fig = Makie.Figure() diff --git a/src/GeoStatsFunctions.jl b/src/GeoStatsFunctions.jl index 8cc30e8..642513c 100644 --- a/src/GeoStatsFunctions.jl +++ b/src/GeoStatsFunctions.jl @@ -95,7 +95,7 @@ export # theoretical transiogram Transiogram, - ExponentialTransiogram, + MatrixExponentialTransiogram, PiecewiseLinearTransiogram, # fitting algorithms diff --git a/src/theoretical/transiogram.jl b/src/theoretical/transiogram.jl index a9200fc..801d466 100644 --- a/src/theoretical/transiogram.jl +++ b/src/theoretical/transiogram.jl @@ -24,5 +24,5 @@ Base.range(t::Transiogram) = maximum(ranges(t)) # IMPLEMENTATIONS # ---------------- -include("transiogram/exponential.jl") +include("transiogram/matrixexponential.jl") include("transiogram/piecewiselinear.jl") diff --git a/src/theoretical/transiogram/exponential.jl b/src/theoretical/transiogram/matrixexponential.jl similarity index 63% rename from src/theoretical/transiogram/exponential.jl rename to src/theoretical/transiogram/matrixexponential.jl index 8535278..89a69e0 100644 --- a/src/theoretical/transiogram/exponential.jl +++ b/src/theoretical/transiogram/matrixexponential.jl @@ -3,14 +3,14 @@ # ------------------------------------------------------------------ """ - ExponentialTransiogram(rate) - ExponentialTransiogram(ball, rate) + MatrixExponentialTransiogram(rate) + MatrixExponentialTransiogram(ball, rate) An exponential transiogram with transition `rate` matrix. Optionally, specify a metric `ball` to model anisotropy. - ExponentialTransiogram(lengths, proportions) - ExponentialTransiogram(ball, lengths, proportions) + MatrixExponentialTransiogram(lengths, proportions) + MatrixExponentialTransiogram(ball, lengths, proportions) Alternatively, build transition rate matrix from mean `lengths` and relative `proportions`. @@ -23,11 +23,11 @@ and relative `proportions`. * Carle et al 1998. [Conditional Simulation of Hydrofacies Architecture: A Transition Probability/Markov Approach](https://doi.org/10.2110/sepmcheg.01.147) """ -struct ExponentialTransiogram{R<:StaticMatrix,B<:MetricBall} <: Transiogram +struct MatrixExponentialTransiogram{R<:StaticMatrix,B<:MetricBall} <: Transiogram rate::R ball::B - function ExponentialTransiogram{R,B}(rate, ball) where {R<:StaticMatrix,B<:MetricBall} + function MatrixExponentialTransiogram{R,B}(rate, ball) where {R<:StaticMatrix,B<:MetricBall} if !allequal(size(rate)) throw(ArgumentError("transition rate matrix must be square")) end @@ -35,25 +35,25 @@ struct ExponentialTransiogram{R<:StaticMatrix,B<:MetricBall} <: Transiogram end end -function ExponentialTransiogram(ball::MetricBall, rate::AbstractMatrix) +function MatrixExponentialTransiogram(ball::MetricBall, rate::AbstractMatrix) srate = SMatrix{size(rate)...}(rate) - ExponentialTransiogram{typeof(srate),typeof(ball)}(srate, ball) + MatrixExponentialTransiogram{typeof(srate),typeof(ball)}(srate, ball) end -function ExponentialTransiogram(rate::AbstractMatrix) +function MatrixExponentialTransiogram(rate::AbstractMatrix) ball = MetricBall(1 / unit(eltype(rate))) - ExponentialTransiogram(ball, rate) + MatrixExponentialTransiogram(ball, rate) end -ExponentialTransiogram(ball::MetricBall, props::AbstractVector) = - ExponentialTransiogram(ball, baseratematrix(lens, props)) +MatrixExponentialTransiogram(ball::MetricBall, props::AbstractVector) = + MatrixExponentialTransiogram(ball, baseratematrix(lens, props)) -ExponentialTransiogram(lens::AbstractVector, props::AbstractVector) = - ExponentialTransiogram(baseratematrix(lens, props)) +MatrixExponentialTransiogram(lens::AbstractVector, props::AbstractVector) = + MatrixExponentialTransiogram(baseratematrix(lens, props)) ranges(t::Transiogram) = 1 ./ -diag(t.rate) -(t::ExponentialTransiogram)(h) = exp(h * t.rate) +(t::MatrixExponentialTransiogram)(h) = exp(h * t.rate) # ----------------- # HELPER FUNCTIONS diff --git a/test/theoretical/transiogram.jl b/test/theoretical/transiogram.jl index 0e4f60b..4406472 100644 --- a/test/theoretical/transiogram.jl +++ b/test/theoretical/transiogram.jl @@ -1,4 +1,4 @@ -@testset "ExponentialTransiogram" begin +@testset "MatrixExponentialTransiogram" begin # base transition rate matrix R = GeoStatsFunctions.baseratematrix([1.0, 2.0, 3.0]u"m", [0.2, 0.5, 0.3]) @test R == @@ -9,20 +9,20 @@ ] * u"m^-1" # corresponding exponential transiogram - t = ExponentialTransiogram([1.0, 2.0, 3.0]u"m", [0.2, 0.5, 0.3]) - @test t isa ExponentialTransiogram + t = MatrixExponentialTransiogram([1.0, 2.0, 3.0]u"m", [0.2, 0.5, 0.3]) + @test t isa MatrixExponentialTransiogram @test GeoStatsFunctions.ranges(t) == [1.0, 2.0, 3.0]u"m" @test range(t) == 3.0u"m" # random transition rate matrix A = rand(3, 3) R = A ./ sum(A, dims=2) - t = ExponentialTransiogram(R) - @test t isa ExponentialTransiogram + t = MatrixExponentialTransiogram(R) + @test t isa MatrixExponentialTransiogram @test range(t) == maximum(1 ./ -diag(R)) # invalid transition rate matrix A = rand(3, 2) R = A ./ sum(A, dims=2) - t = @test_throws ArgumentError ExponentialTransiogram(R) + t = @test_throws ArgumentError MatrixExponentialTransiogram(R) end