Skip to content

Commit

Permalink
Add PiecewiseLinearTransiogram
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 28, 2024
1 parent 58f552c commit 631792f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/GeoStatsFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export
# theoretical transiogram
Transiogram,
ExponentialTransiogram,
PiecewiseLinearTransiogram,

# fitting algorithms
WeightedLeastSquares,
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/transiogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Base.range(t::Transiogram) = maximum(ranges(t))
# ----------------

include("transiogram/exponential.jl")
include("transiogram/piecewiselinear.jl")
47 changes: 47 additions & 0 deletions src/theoretical/transiogram/piecewiselinear.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

"""
PiecewiseLinear(abscissas, ordinates)
A piecewise-linear transiogram model from `abscissas` and matrix `ordinates`.
## References
* Li, W. & Zhang, C. 2005. [Application of Transiograms to Markov Chain
Simulation and Spatial Uncertainty Assessment of Land-Cover Classes]
(https://www.tandfonline.com/doi/abs/10.2747/1548-1603.42.4.297)
* Li, W. & Zhang, C. 2010. [Linear interpolation and joint model fitting
of experimental transiograms for Markov chain simulation of categorical
spatial variables](https://www.tandfonline.com/doi/abs/10.1080/13658810903127991)
"""
struct PiecewiseLinearTransiogram{ℒ<:Len,M} <: Transiogram
abscissas::Vector{ℒ}
ordinates::Vector{M}
end

function PiecewiseLinearTransiogram(abscissas::AbstractVector, ordinates::AbstractMatrix)
n = length(abscissas)
m = size(ordinates, 1)
ordinates′ = map(1:n) do k
SMatrix{m, m}([ordinates[i, j][k] for i in 1:m, j in 1:m])
end
PiecewiseLinearTransiogram(abscissas, ordinates′)
end

function (t::PiecewiseLinearTransiogram)(h)
hs = t.abscissas
if h < first(hs) # left extrapolation
((first(hs) - h) * I + h * first(t.ordinates)) / first(hs)
elseif h > last(hs) # right extrapolation
T = last(t.ordinates)
m = size(T, 1)
p = normalize(SVector{m}(T[j, j] for j in 1:m), 1)
SMatrix{m, m}(p[j] for i in 1:m, j in 1:m)
else # middle interpolation
k = findfirst((h), hs)
((hs[k + 1] - h) * t.ordinates[k] + (h - hs[k]) * t.ordinates[k + 1]) / (hs[k + 1] - hs[k])
end
end

0 comments on commit 631792f

Please sign in to comment.