Skip to content

Commit

Permalink
Rename uo --> g0
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Jan 10, 2025
1 parent 1727f8b commit 5097c80
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 50 deletions.
12 changes: 6 additions & 6 deletions src/idw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ end
# PREDICTION STEP
#-----------------

predict(fitted::FittedIDW, var, uₒ) = idw(fitted, weights(fitted, uₒ), var)
predict(fitted::FittedIDW, var, gₒ) = idw(fitted, weights(fitted, gₒ), var)

predictprob(fitted::FittedIDW, var, uₒ) = Dirac(predict(fitted, var, uₒ))
predictprob(fitted::FittedIDW, var, gₒ) = Dirac(predict(fitted, var, gₒ))

function idw(fitted::FittedIDW, weights, var)
d = fitted.state.data
Expand All @@ -72,16 +72,16 @@ function idw(fitted::FittedIDW, weights, var)
end
end

function weights(fitted::FittedIDW, uₒ)
function weights(fitted::FittedIDW, gₒ)
e = fitted.model.exponent
δ = fitted.model.distance
d = fitted.state.data
Ω = domain(d)

# adjust CRS of uₒ
uₒ= uₒ |> Proj(crs(Ω))
# adjust CRS of gₒ
gₒ= gₒ |> Proj(crs(Ω))

pₒ = centroid(uₒ′)
pₒ = centroid(gₒ′)
p(i) = centroid(Ω, i)

λ(i) = 1 / evaluate(δ, pₒ, p(i)) ^ e
Expand Down
4 changes: 2 additions & 2 deletions src/krig/externaldrift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ function set_constraints_lhs!(model::ExternalDriftKriging, LHS::AbstractMatrix,
nothing
end

function set_constraints_rhs!(fitted::FittedKriging{<:ExternalDriftKriging}, uₒ)
function set_constraints_rhs!(fitted::FittedKriging{<:ExternalDriftKriging}, gₒ)
drifts = fitted.model.drifts
RHS = fitted.state.RHS
nobs = nrow(fitted.state.data)

# set external drift
pₒ = centroid(uₒ)
pₒ = centroid(gₒ)
for (j, m) in enumerate(drifts)
RHS[nobs + j] = m(pₒ)
end
Expand Down
2 changes: 1 addition & 1 deletion src/krig/ordinary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function set_constraints_lhs!(::OrdinaryKriging, LHS::AbstractMatrix, domain)
nothing
end

function set_constraints_rhs!(fitted::FittedKriging{<:OrdinaryKriging}, uₒ)
function set_constraints_rhs!(fitted::FittedKriging{<:OrdinaryKriging}, gₒ)
RHS = fitted.state.RHS
RHS[end] = one(eltype(RHS))
nothing
Expand Down
2 changes: 1 addition & 1 deletion src/krig/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ nconstraints(::SimpleKriging) = 0

set_constraints_lhs!(::SimpleKriging, LHS::AbstractMatrix, domain) = nothing

set_constraints_rhs!(::FittedKriging{<:SimpleKriging}, uₒ) = nothing
set_constraints_rhs!(::FittedKriging{<:SimpleKriging}, gₒ) = nothing

function predictmean(fitted::FittedKriging{<:SimpleKriging}, weights::KrigingWeights, var)
μ = fitted.model.μ
Expand Down
4 changes: 2 additions & 2 deletions src/krig/universal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ function set_constraints_lhs!(model::UniversalKriging, LHS::AbstractMatrix, doma
nothing
end

function set_constraints_rhs!(fitted::FittedKriging{<:UniversalKriging}, uₒ)
function set_constraints_rhs!(fitted::FittedKriging{<:UniversalKriging}, gₒ)
exponents = fitted.model.exponents
RHS = fitted.state.RHS
nobs = nrow(fitted.state.data)
nterms = size(exponents, 2)

# set polynomial drift
xₒ = CoordRefSystems.raw(coords(centroid(uₒ)))
xₒ = CoordRefSystems.raw(coords(centroid(gₒ)))
for j in 1:nterms
RHS[nobs + j] = prod(xₒ .^ exponents[:, j])
end
Expand Down
24 changes: 12 additions & 12 deletions src/lwr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,46 @@ end
# PREDICTION STEP
#-----------------

predict(fitted::FittedLWR, var, uₒ) = predictmean(fitted, var, uₒ)
predict(fitted::FittedLWR, var, gₒ) = predictmean(fitted, var, gₒ)

function predictprob(fitted::FittedLWR, var, uₒ)
X, W, A, x, z = matrices(fitted, var, uₒ)
function predictprob(fitted::FittedLWR, var, gₒ)
X, W, A, x, z = matrices(fitted, var, gₒ)
μ = lwrmean(X, W, A, x, z)
σ² = lwrvar(X, W, A, x)
Normal(μ, σ²)
end

function predictmean(fitted::FittedLWR, var, uₒ)
X, W, A, x, z = matrices(fitted, var, uₒ)
function predictmean(fitted::FittedLWR, var, gₒ)
X, W, A, x, z = matrices(fitted, var, gₒ)
lwrmean(X, W, A, x, z)
end

function matrices(fitted::FittedLWR, var, uₒ)
function matrices(fitted::FittedLWR, var, gₒ)
d = fitted.state.data
c = Tables.columns(values(d))
z = Tables.getcolumn(c, var)

# adjust CRS of uₒ
uₒ= uₒ |> Proj(crs(domain(d)))
# adjust CRS of gₒ
gₒ= gₒ |> Proj(crs(domain(d)))

X = fitted.state.X
W = wmatrix(fitted, uₒ′)
W = wmatrix(fitted, gₒ′)
A = X' * W * X

xₒ = CoordRefSystems.raw(coords(centroid(uₒ′)))
xₒ = CoordRefSystems.raw(coords(centroid(gₒ′)))
x = [one(eltype(xₒ)), xₒ...]

X, W, A, x, z
end

function wmatrix(fitted::FittedLWR, uₒ)
function wmatrix(fitted::FittedLWR, gₒ)
w = fitted.model.weightfun
δ = fitted.model.distance
d = fitted.state.data
Ω = domain(d)
n = nelements(Ω)

pₒ = centroid(uₒ)
pₒ = centroid(gₒ)
p(i) = centroid(Ω, i)

δs = map(i -> evaluate(δ, pₒ, p(i)), 1:n)
Expand Down
8 changes: 4 additions & 4 deletions src/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ Fit `model` to geospatial `data` and return a fitted model.
function fit end

"""
predict(model, var, uₒ)
predict(model, var, gₒ)
Predict variable `var` at geometry `uₒ` with given `model`.
Predict variable `var` at geometry `gₒ` with given `model`.
"""
function predict end

"""
predictprob(model, var, uₒ)
predictprob(model, var, gₒ)
Predict distribution of variable `var` at geometry `uₒ` with given `model`.
Predict distribution of variable `var` at geometry `gₒ` with given `model`.
"""
function predictprob end

Expand Down
12 changes: 6 additions & 6 deletions src/nn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ end
# PREDICTION STEP
#-----------------

predict(fitted::FittedNN, var, uₒ) = nn(fitted, distances(fitted, uₒ), var)
predict(fitted::FittedNN, var, gₒ) = nn(fitted, distances(fitted, gₒ), var)

predictprob(fitted::FittedNN, var, uₒ) = Dirac(predict(fitted, var, uₒ))
predictprob(fitted::FittedNN, var, gₒ) = Dirac(predict(fitted, var, gₒ))

function nn(fitted::FittedNN, distances, var)
d = fitted.state.data
Expand All @@ -51,15 +51,15 @@ function nn(fitted::FittedNN, distances, var)
z[argmin(distances)]
end

function distances(fitted::FittedNN, uₒ)
function distances(fitted::FittedNN, gₒ)
δ = fitted.model.distance
d = fitted.state.data
Ω = domain(d)

# adjust CRS of uₒ
uₒ= uₒ |> Proj(crs(Ω))
# adjust CRS of gₒ
gₒ= gₒ |> Proj(crs(Ω))

pₒ = centroid(uₒ′)
pₒ = centroid(gₒ′)
p(i) = centroid(Ω, i)

λ(i) = evaluate(δ, pₒ, p(i))
Expand Down
12 changes: 6 additions & 6 deletions src/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ end
# PREDICTION STEP
#-----------------

predict(fitted::FittedPolynomial, var, uₒ) = evalpoly(fitted, var, uₒ)
predict(fitted::FittedPolynomial, var, gₒ) = evalpoly(fitted, var, gₒ)

predictprob(fitted::FittedPolynomial, var, uₒ) = Dirac(predict(fitted, var, uₒ))
predictprob(fitted::FittedPolynomial, var, gₒ) = Dirac(predict(fitted, var, gₒ))

function evalpoly(fitted::FittedPolynomial, var, uₒ)
function evalpoly(fitted::FittedPolynomial, var, gₒ)
D = domain(fitted.state.data)
θ = fitted.state.coeffs
d = fitted.model.degree
# adjust CRS of uₒ
uₒ= uₒ |> Proj(crs(D))
xₒ = CoordRefSystems.raw(coords(centroid(uₒ′)))
# adjust CRS of gₒ
gₒ= gₒ |> Proj(crs(D))
xₒ = CoordRefSystems.raw(coords(centroid(gₒ′)))
V = vandermonde((xₒ,), d)
first(V * θ[var])
end
Expand Down
20 changes: 10 additions & 10 deletions test/krig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@
dk = GeoStatsModels.fit(DK(γ, [x -> 1.0]), data)

# predict on a quadrangle
uₒ = Quadrangle((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))
skdist = GeoStatsModels.predictprob(sk, :z, uₒ)
okdist = GeoStatsModels.predictprob(ok, :z, uₒ)
ukdist = GeoStatsModels.predictprob(uk, :z, uₒ)
dkdist = GeoStatsModels.predictprob(dk, :z, uₒ)
gₒ = Quadrangle((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))
skdist = GeoStatsModels.predictprob(sk, :z, gₒ)
okdist = GeoStatsModels.predictprob(ok, :z, gₒ)
ukdist = GeoStatsModels.predictprob(uk, :z, gₒ)
dkdist = GeoStatsModels.predictprob(dk, :z, gₒ)

# variance checks
@test var(skdist) 0
Expand All @@ -266,11 +266,11 @@
dk = GeoStatsModels.fit(DK(γ, [x -> 1.0]), data)

# prediction on a quadrangle
uₒ = Quadrangle((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))
skmean = GeoStatsModels.predict(sk, :z, uₒ)
okmean = GeoStatsModels.predict(ok, :z, uₒ)
ukmean = GeoStatsModels.predict(uk, :z, uₒ)
dkmean = GeoStatsModels.predict(dk, :z, uₒ)
gₒ = Quadrangle((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))
skmean = GeoStatsModels.predict(sk, :z, gₒ)
okmean = GeoStatsModels.predict(ok, :z, gₒ)
ukmean = GeoStatsModels.predict(uk, :z, gₒ)
dkmean = GeoStatsModels.predict(dk, :z, gₒ)

# type tests
@test skmean isa Composition
Expand Down

0 comments on commit 5097c80

Please sign in to comment.