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

Request for using my own computed derivatives in NaturalNeighbor.jl #23

Closed
WillingWeiling opened this issue Nov 13, 2023 · 2 comments
Closed

Comments

@WillingWeiling
Copy link

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

@DanielVandH
Copy link
Owner

Hi @WillingWeiling , thanks for your interest. The interpolate constructor also allows you to pass in your own gradients instead of relying on generating them with derivatives=true. Here is an example:

using NaturalNeighbours 
f = (x, y) -> x^2 + y^2 
df = (x, y) -> (2x, 2y)
x = rand(100)
y = rand(100)
z = f.(x, y)
∇z = df.(x, y) 
itp = interpolate(x, y, z; gradient=∇z)
julia> itp
Natural Neighbour Interpolant
    z: [0.34236037959410437, 0.6409391417100012, 0.2792694577044466, 0.40633019736493853, 0.0014825003910995446, 1.8705036885166058, 0.2833796685769481, 1.4593246638262931, 0.21883478954176305, 0.7157193513420117  …  1.0233750284009104, 0.5668896793818932, 0.7024901459842816, 1.7006307147816409, 0.7477708129900137, 1.09722701646297, 0.21527150358380945, 1.2723403302477225, 0.28273056436535154, 1.281013490332372]
    ∇: [(0.8350983284258899, 0.8197879605341261), (1.6006824475600536, 0.03965184627682539), (0.9765198636683925, 0.4043349931416407), (0.7002460373519068, 1.0653526536470006), (0.07126290698397475, 0.029182180394746737), (1.9119086977347501, 1.9561748095690823), (1.0644855459563665, 0.01972807030017587), (1.5441834861498966, 1.858170071981336), (0.6009112957223604, 0.7171086199735199), (0.8953492854012941, 1.4356974132801934)  …  (0.854979376605338, 1.833714912188694), (1.4897516651971912, 0.21954200866751927), (0.4152962082594305, 1.6240349883369096), (1.6916324673982732, 1.985170636084111), (0.028283158342867543, 1.7292435672611903), (1.6686166433054623, 1.2667385537418099), (0.8963693911208481, 0.24001651817505776), (1.1382351633665064, 1.9477633413397308), (1.0622364857876907, 0.050753381393001895), (1.8755837106400375, 1.267375124306626)]    
    H: nothing

See that the gradient is now in the interpolant, so you can now use e.g. Farin() or Sibson(1). Does that help you?

@WillingWeiling
Copy link
Author

Hi@DanielVandH
thank you so much for your assistance. I am grateful to have received your guidance and am confident that it will make a significant difference in my work! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants