Skip to content

Commit

Permalink
ExponentialTransiogram --> MatrixExponentialTransiogram
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 28, 2024
1 parent 7bd6866 commit e0ad400
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ext/transioplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function transioplot(
p = normalize(diag(t(100H)), 1)

# base transiogram model
= ExponentialTransiogram(r, p)
= MatrixExponentialTransiogram(r, p)
t̂s = .(hs)

fig = Makie.Figure()
Expand Down
2 changes: 1 addition & 1 deletion src/GeoStatsFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export

# theoretical transiogram
Transiogram,
ExponentialTransiogram,
MatrixExponentialTransiogram,
PiecewiseLinearTransiogram,

# fitting algorithms
Expand Down
2 changes: 1 addition & 1 deletion src/theoretical/transiogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Base.range(t::Transiogram) = maximum(ranges(t))
# IMPLEMENTATIONS
# ----------------

include("transiogram/exponential.jl")
include("transiogram/matrixexponential.jl")
include("transiogram/piecewiselinear.jl")
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -23,37 +23,37 @@ 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
new(rate, ball)
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
Expand Down
12 changes: 6 additions & 6 deletions test/theoretical/transiogram.jl
Original file line number Diff line number Diff line change
@@ -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 ==
Expand All @@ -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

0 comments on commit e0ad400

Please sign in to comment.