I am trying this tutorial for
raidal basis function
using
ADCME.jl
package.
When I execute the code, I get a method error:
using ADCME
# use centers on a uniform grid
n = 5
h = 1/n
xc = Float64[]
yc = Float64[]
for i = 1:n+1
for j = 1:n+1
push!(xc, (i-1)*h)
push!(yc, (j-1)*h)
# by default, c is initialized to Variable(ones(...))
# eps is initialized to ones(...) and no linear terms are used
rbf = RBF2D(xc, yc)
x = rand(100)
y = rand(100)
f = @. 1+y^2/(1+x^2)
fv = rbf(x, y)
loss = sum((f-fv)^2)
sess = Session(); init(sess)
BFGS!(sess, loss)
Error observed for fv = rbf(x, y)
line:
MethodError: no method matching load_op_and_grad(::Missing, ::String)
Closest candidates are:
load_op_and_grad(!Matched::Union{String, PyCall.PyObject}, ::String; multiple, verbose) at C:\Users\user\.julia\packages\ADCME\7qIYe\src\extra.jl:160
(::RBF2D)(::Array{Float64,1}, ::Array{Float64,1}) at rbf.jl:64
top-level scope at test-functions.jl:23
Please suggest on the possible cause of this error and how may i resolve this issue?
Thanks in advance!!
I tried a tutorial using surrogates.jl
, however my code is throwing an error, saying that in sample()
sample not defined.
using Surrogates
using Plots
default()
g(x) = log(x)*x^2 + x^3
n_samples = 30
lower_bound = 5
upper_bound = 25
x = sample(n_samples, lower_bound, upper_bound, SobolSample())
y = g.(x)
scatter(x, y, label="Sampled Points", xlims=(lower_bound, upper_bound), legend=:top)
plot!(f, label="True function", scatter(x, y, label="Sampled Points", xlims=(lower_bound, upper_bound), legend=:top)
radial_surrogate = RadialBasis(x, y, lower_bound, upper_bound)
val = radial_surrogate(5.4)
Error
UndefVarError: sample not defined
top-level scope at test-functions.jl:39
May i know what is the cause of this error?
Thanks !!!
Apologies, that is my mistake. I will fix that now.
Btw Surrogates.sample
works!!!
@ChrisRackauckas Thanks !
I will run the test and post update on my implementation.
It does not throw any warnings just an error saying that it is not define. The error result is presented in highlight:
UndefVarError: sample not defined
top-level scope at test-functions.jl:39
@ChrisRackauckas I figured out the issue, why was i getting the error for sample
, it is due to the ADCME.jl
package.
The ADCME.sample
is creating a conflict with Surrogates.sample
identifier. This I resolved it by removing the precompilation of the package.
I ran the tutorial for Surrogates
and below is the example code:
using Surrogates
using Plots
default()
g(x) = log(x)*x^2 + x^3
n_samples = 30
lower_bound = 5
upper_bound = 25
x = sample(n_samples, lower_bound, upper_bound, SobolSample())
y = g.(x)
radial_surrogate = RadialBasis(x, y, lower_bound, upper_bound)
plot(x, y, seriestype=:scatter, label="Sampled points", xlims=(lower_bound, upper_bound), legend=:top)
plot!(g, label="True function", xlims=(lower_bound, upper_bound), legend=:top)
plot!(radial_surrogate, label="Surrogate function", xlims=(lower_bound, upper_bound), legend=:top)
I would like to know, how may I implement various functions for rbf
like multiquadratic
, gaussian
etc?
mdsa3d:
I would like to know, how may I implement various functions for rbf
like multiquadratic
, gaussian
etc?
What do you mean?
Apologies, for the pixelated snippet,
Reference for above: scipy.interpolate.Rbf — SciPy v1.6.1 Reference Guide
There are various functions
which are used for operating rbf
as listed in the documentation. however, this documentation is for scipy
python. Do we have something like this which we can implement in Surrogates
? I couldn’t find something similar for julia.
I build the surrogate model
for kriging
function, here is my code:
using Surrogates
using Plots, DataFrames
default()
f(x) = sin(x)
n_samples = 10
lower_bound = 0.0
upper_bound = 9
x = sample(n_samples, lower_bound, upper_bound, SobolSample())
y = f.(x)
scatter(x, y, label="Sampled points")
kriging_surrogate = Surrogates.Kriging(x, y, lower_bound, upper_bound, p=1.9);
@show surrogate_optimize(f, SRBF(), lower_bound, upper_bound, kriging_surrogate, SobolSample())
result = []
arr = 0:1:10
for i in arr
interpolated = kriging_surrogate(i)
push!(result, interpolated)
plot!(result, label="kriging", legend=:bottomright) #, title="Percentage Error", xlabel="Values", ylabel="Percentage")
Plot for the code:
I am quite confused why the julia model is not accurate as compared to the python?
import numpy as np
from scipy.interpolate import Rbf, InterpolatedUnivariateSpline
import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
# setup data
x = np.linspace(0, 10, 9)
y = np.sin(x)
xi = np.linspace(0, 10, 101)
# use RBF method
rbf = Rbf(x, y)
fi = rbf(xi)
plt.plot(x, y, 'bo')
plt.plot(xi, fi, 'g')
plt.plot(xi, np.sin(xi), 'r')
plt.title('Interpolation using RBF (scipy) - multiquadrics')
plt.tight_layout()
plt.show()
Plot for the python:
May i know why is there offset in the datapoints?
Thanks in advance!
Thanks for the suggestion,
I have open an issue : Incorrect predicted values for kriging function · Issue #250 · SciML/Surrogates.jl (github.com)
Looking forward to positive response.