diff --git a/src/nesting.jl b/src/nesting.jl index f35c6b7..d6fd484 100644 --- a/src/nesting.jl +++ b/src/nesting.jl @@ -26,51 +26,15 @@ end NestedVariogram(cs, γs) = NestedVariogram{typeof(cs),typeof(γs)}(cs, γs) -(g::NestedVariogram)(h) = raw(sum(g.cs .* map(γ -> γ(h), g.γs))) -(g::NestedVariogram)(u::Point, v::Point) = raw(sum(g.cs .* map(γ -> γ(u, v), g.γs))) +isstationary(γ::NestedVariogram) = all(isstationary, γ.γs) -sill(g::NestedVariogram) = raw(sum(g.cs .* map(sill, g.γs))) -nugget(g::NestedVariogram) = raw(sum(g.cs .* map(nugget, g.γs))) -Base.range(g::NestedVariogram) = maximum(range(γ) for γ in g.γs) -isstationary(g::NestedVariogram) = all(isstationary, g.γs) -isisotropic(g::NestedVariogram) = all(isisotropic, g.γs) +isisotropic(γ::NestedVariogram) = all(isisotropic, γ.γs) -# algebraic structure -*(c, γ::Variogram) = NestedVariogram((c,), (γ,)) -*(c, γ::NestedVariogram) = NestedVariogram(map(x -> c .* x, γ.cs), γ.γs) -+(γ₁::Variogram, γ₂::Variogram) = NestedVariogram((1, 1), (γ₁, γ₂)) -+(γ₁::NestedVariogram, γ₂::Variogram) = NestedVariogram((γ₁.cs..., 1), (γ₁.γs..., γ₂)) -+(γ₁::Variogram, γ₂::NestedVariogram) = NestedVariogram((1, γ₂.cs...), (γ₁, γ₂.γs...)) -+(γ₁::NestedVariogram, γ₂::NestedVariogram) = NestedVariogram((γ₁.cs..., γ₂.cs...), (γ₁.γs..., γ₂.γs...)) - -""" - structures(γ) +sill(γ::NestedVariogram) = raw(sum(γ.cs .* map(sill, γ.γs))) -Return the individual structures of a (possibly nested) -variogram as a tuple. The structures are the total nugget -`cₒ`, and the coefficients (or contributions) `c[i]` for the -remaining non-trivial structures `g[i]` after normalization -(i.e. sill=1, nugget=0). +nugget(γ::NestedVariogram) = raw(sum(γ.cs .* map(nugget, γ.γs))) -## Examples - -```julia -γ₁ = GaussianVariogram(nugget=1, sill=2) -γ₂ = SphericalVariogram(nugget=2, sill=3) - -γ = 2γ₁ + 3γ₂ - -cₒ, c, g = structures(γ) -``` -""" -function structures(γ::Variogram) - cₒ = nugget(γ) - c = sill(γ) - nugget(γ) - T = typeof(c) - γ = @set γ.sill = one(T) - γ = @set γ.nugget = zero(T) - cₒ, (c,), (γ,) -end +Base.range(γ::NestedVariogram) = maximum(range(g) for g in γ.γs) function structures(γ::NestedVariogram) ks, gs = γ.cs, γ.γs @@ -93,6 +57,17 @@ function structures(γ::NestedVariogram) cₒ, cs, γs end +(γ::NestedVariogram)(h) = raw(sum(γ.cs .* map(g -> g(h), γ.γs))) +(γ::NestedVariogram)(u::Point, v::Point) = raw(sum(γ.cs .* map(g -> g(u, v), γ.γs))) + +# algebraic structure +*(c, γ::Variogram) = NestedVariogram((c,), (γ,)) +*(c, γ::NestedVariogram) = NestedVariogram(map(x -> c .* x, γ.cs), γ.γs) ++(γ₁::Variogram, γ₂::Variogram) = NestedVariogram((1, 1), (γ₁, γ₂)) ++(γ₁::NestedVariogram, γ₂::Variogram) = NestedVariogram((γ₁.cs..., 1), (γ₁.γs..., γ₂)) ++(γ₁::Variogram, γ₂::NestedVariogram) = NestedVariogram((1, γ₂.cs...), (γ₁, γ₂.γs...)) ++(γ₁::NestedVariogram, γ₂::NestedVariogram) = NestedVariogram((γ₁.cs..., γ₂.cs...), (γ₁.γs..., γ₂.γs...)) + # ----------- # IO METHODS # ----------- diff --git a/src/variogram.jl b/src/variogram.jl index 6ba1b8d..9970975 100644 --- a/src/variogram.jl +++ b/src/variogram.jl @@ -9,6 +9,27 @@ A theoretical variogram model (e.g. Gaussian variogram). """ abstract type Variogram end +""" + variotype(γ) + +Return the type constructor of the variogram `γ`. +""" +function variotype end + +""" + isstationary(γ) + +Check if variogram `γ` possesses the 2nd-order stationary property. +""" +isstationary(γ::Variogram) = isstationary(typeof(γ)) + +""" + isisotropic(γ) + +Tells whether or not variogram `γ` is isotropic. +""" +isisotropic(γ::Variogram) = isisotropic(γ.ball) + """ sill(γ) @@ -38,11 +59,33 @@ Return the maximum range of the variogram `γ`. Base.range(γ::Variogram) = maximum(radii(γ.ball)) """ - variotype(γ) + structures(γ) -Return the type constructor of the variogram `γ`. +Return the individual structures of a (possibly nested) +variogram as a tuple. The structures are the total nugget +`cₒ`, and the coefficients (or contributions) `c[i]` for the +remaining non-trivial structures `g[i]` after normalization +(i.e. sill=1, nugget=0). + +## Examples + +```julia +γ₁ = GaussianVariogram(nugget=1, sill=2) +γ₂ = SphericalVariogram(nugget=2, sill=3) + +γ = 2γ₁ + 3γ₂ + +cₒ, c, g = structures(γ) +``` """ -function variotype end +function structures(γ::Variogram) + cₒ = nugget(γ) + c = sill(γ) - nugget(γ) + T = typeof(c) + γ = @set γ.sill = one(T) + γ = @set γ.nugget = zero(T) + cₒ, (c,), (γ,) +end """ γ(u, v) @@ -85,27 +128,6 @@ function (γ::Variogram)(U::Geometry, V::Geometry) mean(γ(u, v) for u in us, v in vs) end -""" - returntype(γ, u, v) - -Return result type of γ(u, v). -""" -returntype(γ::Variogram, u, v) = typeof(γ(u, v)) - -""" - isstationary(γ) - -Check if variogram `γ` possesses the 2nd-order stationary property. -""" -isstationary(γ::Variogram) = isstationary(typeof(γ)) - -""" - isisotropic(γ) - -Tells whether or not variogram `γ` is isotropic. -""" -isisotropic(γ::Variogram) = isisotropic(γ.ball) - """ pairwise(γ, domain) @@ -167,6 +189,23 @@ function pairwise!(Γ, γ::Variogram, domain₁, domain₂) Γ end +""" + returntype(γ, u, v) + +Return type of γ(u, v). +""" +returntype(γ::Variogram, u, v) = typeof(γ(u, v)) + +""" + scale(γ, s) + +Scale ranges of variogram `γ` with strictly positive scaling factor `s`. +""" +function scale(γ::Variogram, s::Real) + V = variotype(γ) + V(s * metricball(γ); sill=sill(γ), nugget=nugget(γ)) +end + # ----------- # IO METHODS # -----------