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

Query Regarding Gradient Discrepancy in Natural Neighbours Interpolation #25

Closed
WillingWeiling opened this issue Dec 4, 2023 · 5 comments

Comments

@WillingWeiling
Copy link

          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)

@DanielVandH
Copy link
Owner

The Nearest() interpolant is a piecewise-constant interpolant, and so it is not expected to match the gradient at the data points - I would not recommend you use it for what you are trying to do. Can you maybe try Sibson(1), Farin(), or Hiyoshi(2)?

@WillingWeiling
Copy link
Author

The Nearest() interpolant is a piecewise-constant interpolant, and so it is not expected to match the gradient at the data points - I would not recommend you use it for what you are trying to do. Can you maybe try Sibson(1), Farin(), or Hiyoshi(2)?

Yes, I tried the remaining methods, and the results were consistent.I did not apply the Hiyoshi(2) method because it cannot accommodate the given gradient information.
1201NN_mu12
1201NN_mu11
1201NN_mu13

@DanielVandH
Copy link
Owner

DanielVandH commented Dec 4, 2023

I'd probably need the data itself to take a better look at this for you if you would like, along with the code to reproduce your plots. You can attach that here, or if you prefer to keep it private you can email me at danj.vandenheuvel gmail com.

@WillingWeiling
Copy link
Author

I'd probably need the data itself to take a better look at this for you if you would like, along with the code to reproduce your plots. You can attach that here, or if you prefer to keep it private you can email me at danj.vandenheuvel gmail com.

Thank you once again for your kindness!!

1.first I construct a model like this

using DelaunayTriangulation
using NaturalNeighbours
using StableRNGs

Gsx = Gs[:,1]     #x
Gsy = Gs[:,2]     #y
Gsz = Gs[:,3]     #z
dz = [(row[4], row[5]) for row in eachrow(Gs)]    #dz 
# The above data is given. Maybe I can email you

itpF = NaturalNeighbours.interpolate(model.Gsx, model.Gsy, model.Gsz; gradient=model.dz)
diffr = differentiate(itpF, 1)

2.To verify if the interpolated gradient information is close to the actual values, I selected a straight line where
ϕA+ϕB = 0.86,ϕA in 0.015:0.01:0.715 as an example with an interval of 0.01.

F_itp = []
muA_itp = []
muB_itp = []
A = []
B = []
for ϕA in 0.015:0.01:0.715
    ϕB = 0.86-ϕA 
    F_La = itpF(ϕA,ϕB,method=Farin(1),project=false)
    tuple = diffr(ϕA,ϕB,interpolant_method = Farin(1), project = false, method =  Iterative())
    muA = tuple[1]
    muB = tuple[2]
    push!(A,ϕA)
    push!(B,ϕB)
    push!(F_itp,F_La)
    push!(muA_itp,muA)
    push!(muB_itp,muB)
end
itpline = hcat(A,B,F_itp,muA_itp,muB_itp)
  1. the actual discrete data points on this line is listed below.
Gsline = 
[
0.01  0.85  -23.3783  71.0061  72.0787
0.11  0.75  -23.3712  72.604   72.2529
0.21  0.65  -23.3454  72.4506  72.3374
0.31  0.55  -23.3527  72.0401  72.3021
0.41  0.45  -23.3958  71.5197  72.0987
0.51  0.35  -23.4622  70.9379  71.6422
0.61  0.25  -23.524   70.317   70.7598
0.71  0.15  -23.5236  69.6688  69.0057] 
# 8×5 Matrix{Float64},row1 for ϕA,row2 for ϕB row3 for F,row4 for muA (the differentiate of ϕA),row5 for muB(the differentiate of ϕB)

1201NN86

I merged these interpolated data matrices with the actual discrete data points and created several plots.

itpline_all =vcat(itpline,Gsline)
sorted_indices = sortperm(itpline_all[:, 1])
itpFarinline = itpline_all[sorted_indices, :]

Plots.plot(itpFarinline[:, 1],itpFarinline[:, 3], label="Farin(1)", xlabel="ϕA", ylabel="Free-Energy", title="phiA + phiB = 0.86")
Plots.scatter!(Gsline[:, 1], Gsline[:, 3], label="real Data", xlabel="ϕA", ylabel="Free-Energy", title="phiA + phiB = 0.86")

1201NN_11

From this plot, we can observe that the curve of Free -energy with respect to ϕ A after interpolation is smooth and passes through the actual discrete data points.
However, the curve of muA with respect to ϕ A after interpolation is consistently shifted upward compared to the actual discrete data points. Similarly, the curve of muB with respect to ϕ B exhibits a certain amount of upward shift.

Plots.scatter(Gsline[:, 1], Gsline[:, 4], label="real Data", xlabel="ϕA", ylabel="μA", title="phiA + phiB = 0.86")
Plots.plot!(itpFarinline[:, 1],itpFarinline[:, 4], label="Farin(1)", xlabel="ϕA", ylabel="μA", title="phiA + phiB = 0.86")
Plots.scatter(Gsline[:, 2], Gsline[:, 5], label="real Data", xlabel="ϕB", ylabel="μB", title="phiA + phiB = 0.86")
Plots.plot!(itpFarinline[:, 2],itpFarinline[:, 5], label="itp_Farin(1)Data", xlabel="ϕB", ylabel="μB", title="phiA + phiB = 0.86")

1201NN_mu11
1201NN_mu21

@DanielVandH
Copy link
Owner

Thanks @WillingWeiling. Once you email the data I'll try and take a look at some point this week.

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