Git Product home page Git Product logo

danielvandh / naturalneighbours.jl Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 0.0 824.53 MB

Natural neighbour interpolation methods for scattered data interpolation and derivative generation of planar point sets.

Home Page: https://danielvandh.github.io/NaturalNeighbours.jl/

License: MIT License

Julia 100.00%
interpolation scattered-data-interpolation spatial-interpolation tessellation derivative-estimation derivative-generation natural-neighbours

naturalneighbours.jl's People

Contributors

danielvandh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

naturalneighbours.jl's Issues

Interpolating vector quantities

I wonder if it would be nice to have a way to interpolate data of the form $\mathbf z = f(x, y)$. One application would be solutions from a PDE, in which case we might want to interpolate at the same point but at many times. Being able to do this just a single time would save a lot of time.

Remaining algorithms

Would still like to eventually implement the following algorithms; chapter numbers refer to pages in Bobach's thesis here.

  • Farin's $C^1$ interpolant (Chapter 3.2.7.2)
  • Hiyoshi's $C^2$ interpolant (Chapter 3.2.7.3)
  • Hioyshi's coordinates (Chapter 3.2.5.5, Chapter 5.5)
  • Ghost point extrapolation (Chapter 8)

The main issues being I'm not 100% sure I understand the splines yet for the first two methods, and Bobach's description of Hiyoshi's coordinates confuses me.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Mismatched coordinate scales

Nice package, and easy to use!

I come across some weird behavior, though, when the x and y coordinates of the grid points have different scales.
I wonder if this could be easily fixed by having a normalization step before constructing the interpolant, which would scale the given points to an e.g. unit box (then, when the interpolant is called, the coordinates used for the new interpolated data can be transformed with the same normalization)?

An example of the current problem below, and let me know if I've missed something obvious in the docs that solves this 😅


When the y indices have a scale that is 50-times smaller than the x indices:

   using NaturalNeighbours
    using CairoMakie
    N = 50
    f = (xy) -> sinc(sqrt((xy[1])^2 + (xy[2] * N)^2) .+ 0.1 * randn())
    x = Float64.(-6:0.1:6)
    y = Float64.((-6:0.1:6) ./ N)
    xy = Iterators.product(x, y)
    z = f.(xy)

    itp = interpolate(first.(xy)[:], last.(xy)[:], z[:])
    _x = range(-6, 6, length=100)
    _y = range(-6 / N, 6 / N, length=100)
    _xy = Iterators.product(_x, _y)
    _z = itp(first.(_xy)[:], last.(_xy)[:])
    Z = reshape(_z, length.([_x, _y])...)

    f = Figure(size=(600, 300))
    ax = Axis(f[1, 1]; title="Input")
    p = heatmap!(ax, x, y, z)
    ax1 = Axis(f[1, 2]; title="Output")
    heatmap!(ax1, _x, _y, Z)
    display(f)

image

It works fine for N = 1 though (matched scales):
image

How to get the gradient of the specific points?

Dear DanielVandH
I apologize for reaching out to you again. I am writing to seek your guidance on a specific issue regarding obtaining the gradient of a specific point after interpolating a model. Our project has made use of the interpolation method you provided, and we have successfully obtained the model. However, we are currently facing a challenge in retrieving the gradient information of a specific point. It is crucial for us to access the gradient value of that point in order to further refine our algorithms and applications.
The code we have been using is as follows:
itpF(0.0115, 0.1, method=Farin(1), project=false)
this code only returns the Z value of the point,We are wondering if there is any way to retrieve the gradient information with this point.

Thank you for your time and support. We look forward to your response!

Best regards,
Weiling

Derivative generation crashes when the triangulation has only a single triangle

julia> let
           m = 3
           pts = [(cos(θ) + 1e-6randn(), sin(θ) + 1e-6randn()) for θ = LinRange(0, 2π, (m + 1))][1:end-1]
           tri = triangulate(pts)
           f = (x, y) -> sin(x) * cos(y)
           z = [f(x, y) for (x, y) in each_point(tri)]
           itp = interpolate(tri, z; derivatives = true)
       end

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x283041f7cc8 -- * at .\float.jl:410 [inlined]
_wide_qr_ldiv! at C:\workdir\usr\share\julia\stdlib\v1.9\LinearAlgebra\src\qr.jl:959
in expression starting at REPL[4]:1
* at .\float.jl:410 [inlined]
_wide_qr_ldiv! at C:\workdir\usr\share\julia\stdlib\v1.9\LinearAlgebra\src\qr.jl:959
ldiv! at C:\workdir\usr\share\julia\stdlib\v1.9\LinearAlgebra\src\qr.jl:974
ldiv! at C:\workdir\usr\share\julia\stdlib\v1.9\LinearAlgebra\src\qr.jl:982 [inlined]
#_generate_second_order_derivatives_direct#77 at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\methods\direct.jl:82
_generate_second_order_derivatives_direct at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\methods\direct.jl:38 [inlined]
#generate_second_order_derivatives#79 at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\methods\direct.jl:113 [inlined]
generate_second_order_derivatives at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\methods\direct.jl:101 [inlined]
#generate_second_order_derivatives#67 at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\generate.jl:191 [inlined]
generate_second_order_derivatives at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\generate.jl:180 [inlined]
#generate_second_order_derivatives!#65 at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\generate.jl:149 [inlined]
generate_second_order_derivatives! at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\generate.jl:137 [inlined]
macro expansion at C:\Users\User\.julia\packages\NaturalNeighbours\ki3ai\src\differentiation\generate.jl:84 [inlined]
#64#threadsfor_fun#34 at .\threadingconstructs.jl:163
#64#threadsfor_fun at .\threadingconstructs.jl:130 [inlined]
#1 at .\threadingconstructs.jl:108
unknown function (ip: 00000283041fd453)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
start_task at C:/workdir/src\task.c:1092
Allocations: 22729726 (Pool: 22704549; Big: 25177); GC: 17

Query Regarding Gradient Discrepancy in Natural Neighbours Interpolation

          Following your instructions, I utilized the following code snippet:

Gsx = Gs[:,1]
Gsy = Gs[:,2]
Gsz = Gs[:,3]
dz = [(row[4], row[5]) for row in eachrow(Gs)] #Gs is a matrix containing data information.
itpF = NaturalNeighbours.interpolate(model.Gsx, model.Gsy, model.Gsz; gradient=model.dz)
diffr = differentiate(itpF, 1)
F = itpF(ϕA, ϕB, method=Nearest(), project=false)
mu = diffr(ϕA, ϕB, interpolant_method=Nearest(), project=false, method=Direct()) /mu = diffr(ϕA, ϕB, interpolant_method=Nearest(), project=false, method=Iterative()) The results obtained by selecting method = Iterative() or Direct() are the same.
My objective is to obtain an interpolated convex surface and analyze a cross-section by selecting ten points. However, upon plotting the results, I observed a certain shift in the interpolated gradient positions compared to the true data points.
1201NN_mu12
The horizontal axis in the graph represents x-values, while the vertical axis corresponds to the interpolated gradient data obtained from diffr.

I am wondering if this discrepancy may be attributed to the fact that the provided gradient=model.dz was not effectively utilized during the gradient calculation. I would greatly appreciate your insights into this matter and any suggestions you may have to address this issue.

Originally posted by @WillingWeiling in #24 (comment)

Write an example comparing all the interpolants properly

I need to write an example that compares all the interpolants over several test cases. The tests need to examine

  • Differences between the heights
  • Differences between the gradients
  • Differences between the Hessians

Just need to come up with a good way for it. There are some considerations:

  • How can surface roughness best be measured? This can (maybe) be used as a proxy for measuring gradients and Hessians (but not a replacement for).
  • What is the best way to define $n$? Minimum edge length? Number of points? Median triangle area?
  • How far should we keep points away from the convex hull?
  • What's the best way for showing the visual results?

I don't plan to do a rigorous test anyway, but I need to know some of this for my actual applications.

Note that I also have a bunch of test comparisons in the tests, but nothing presentable.

Request for using my own computed derivatives in NaturalNeighbor.jl

Dear DanielVandH,

I have been exploring the capabilities of NaturalNeighbor.jl and I was wondering if it would be feasible to utilize custom derivatives as additional known information during the interpolation process. Specifically, I would like to provide my own computed derivatives to enhance the accuracy of the interpolation.
Thank you for your attention to my inquiry. I appreciate the work you have done on NaturalNeighbor.jl and I look forward to hearing your insights on this matter.

Best regards,
Weiling H

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.