Skip to content

Commit

Permalink
inversedistance fix
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Jul 15, 2020
1 parent b3825dc commit ca7a17c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PyPlot.close(fig)

inversedistancefield = Array{Float64}(undef, length(xs), length(ys))
@time for (i, x) in enumerate(xs), (j, y) in enumerate(ys)
inversedistancefield[i, j] = Kriging.inversedistance(permutedims([x y]), X, Z, 1/2)[1]
inversedistancefield[i, j] = Kriging.inversedistance(permutedims([x y]), X, Z, 2)[1]
end

fig, ax = PyPlot.subplots()
Expand Down
8 changes: 4 additions & 4 deletions src/Kriging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ function gaussianvariogram(h::Number, sill::Number, range::Number, nugget::Numbe
end
end

function distance(a::AbstractArray, b::AbstractArray)
function distance(a::AbstractArray, b::AbstractArray, pow::Number)
result = 0.0
for i = 1:length(a)
result += abs.(a[i] .- b[i])
result += abs.(a[i] .- b[i]) .^ pow
end
return result
end

function distsquared(a::AbstractArray, b::AbstractArray)
result = 0.0
for i = 1:length(a)
result += abs.(a[i] .- b[i]) ^ 2
result += abs.(a[i] .- b[i]) .^ 2
end
return result
end
Expand All @@ -137,7 +137,7 @@ function inversedistance(x0mat::AbstractMatrix, X::AbstractMatrix, Z::AbstractVe
weights = Array{Float64}(undef, size(X, 2))
for i = 1:size(x0mat, 2)
for j = 1:size(X, 2)
weights[j] = inv.(distance(x0mat[:, i], X[:, j]) ^ pow)
weights[j] = inv.(distance(x0mat[:, i], X[:, j], pow))
end
result[i] = LinearAlgebra.dot(weights, Z) / sum(weights)
end
Expand Down

2 comments on commit ca7a17c

@montyvesselinov
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/17975

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.2 -m "<description of version>" ca7a17c32338cdf1d590b4470404cb3eea27f7fe
git push origin v0.6.2

Please sign in to comment.