Created
March 24, 2024 21:32
-
-
Save Mattriks/c297542525abbd1a4b5ec7b41370d2fe to your computer and use it in GitHub Desktop.
MEM: Spatial model
This file contains hidden or 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
module spm | |
using Distributions, LinearAlgebra | |
import MeasurementErrorModels as MEM | |
function Pf(s::T, p::T) where T<:AbstractVector | |
Dist = (s .-s').^2 | |
return p[2]*exp.(-Dist./p[1]) | |
end | |
function gls(Y::T, X::T, Σy::T) where T<:AbstractMatrix | |
Xa = [ones(size(X,1)) X] | |
B = (Xa'/Σy*Xa) \ (Xa'/Σy*Y) | |
Σb = inv(Xa'/Σy*Xa) | |
covB = 0.5*(Σb+Σb') | |
return MvNormal(B[:], covB) | |
end | |
# "Weighted total least squares" | |
function wtls(Y::AbstractVector, X::T, Ωv::T, ΣA::T) where T<:AbstractMatrix | |
n, p = size(X) | |
Xa = [ones(n) X] | |
Bml1 = MEM.Bml(Y, X, Ωv, ΣA) | |
e = Y - Xa*Bml1 | |
BI = kron(Bml1[2:end], I(n)) | |
W = Ωv + BI'ΣA*BI | |
covB = MEM.BBml(e, W, Xa, ΣA, BI) | |
return MvNormal(Bml1, covB) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An Example: