Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pairwise! for Covariance types #5

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/covariance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,30 @@ Evaluate the covariance at objects `x₁` and `x₁`.

"""
pairwise(cov, domain)

Evaluate covariance `cov` between all elements in the `domain`.

pairwise(cov, domain₁, domain₂)

Evaluate covariance `cov` between all elements of `domain₁` and `domain₂`.
"""
pairwise(cov::Covariance, args...) = sill(cov.γ) .- pairwise(cov.γ, args...)

"""
pairwise!(Γ, cov, domain)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We denote the covariance matrix by C or \Sigma. \Gamma is reserved for the variogram matrix.


Evaluates covariance `cov` between all elements in the `domain` in-place, filling the matrix `Γ`.

pairwise!(Γ, cov, domain₁, domain₂)

Evaluates covariance `cov` between all elements of `domain₁` and `domain₂` in-place, filling the matrix `Γ`."""
function pairwise!(Γ, cov::Covariance, args...)
pairwise!(Γ, cov.γ, args...)
Γ .*= -one(eltype(Γ))
Γ .+= sill(cov.γ)
Γ
juliohm marked this conversation as resolved.
Show resolved Hide resolved
end

# -----------
# IO METHODS
# -----------
Expand Down
10 changes: 10 additions & 0 deletions src/variogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function pairwise(γ::Variogram, domain)
pairwise!(Γ, γ, domain)
end

"""
pairwise!(Γ, γ, domain)

Evaluates covariance `γ` between all elements in the `domain` in-place, filling the matrix `Γ`.
"""
function pairwise!(Γ, γ::Variogram, domain)
n = length(domain)
@inbounds for j in 1:n
Expand Down Expand Up @@ -185,6 +190,11 @@ function pairwise(γ::Variogram, domain₁, domain₂)
pairwise!(Γ, γ, domain₁, domain₂)
end

"""
pairwise!(Γ, γ, domain)

Evaluates covariance `γ` between all elements of `domain₁` and `domain₂` in-place, filling the matrix `Γ`.
juliohm marked this conversation as resolved.
Show resolved Hide resolved
"""
function pairwise!(Γ, γ::Variogram, domain₁, domain₂)
m = length(domain₁)
n = length(domain₂)
Expand Down
Loading