-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |