Created
March 26, 2019 07:27
-
-
Save aa25desh/265dd40baba7df2ede22644b3a127f71 to your computer and use it in GitHub Desktop.
RBF fitting on ODE data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min_x=f(x_err) | |
min_y=f(y_err) | |
rbf_x = UniformRBFE(t,min_x, normalize=true) | |
rbf_y = UniformRBFE(t,min_y, normalize=true) | |
bfa_x = BasisFunctionApproximation(x,t,rbf_x,1) | |
bfa_y = BasisFunctionApproximation(y,t,rbf_y,1) | |
x_hat_new = bfa_x(t) | |
y_hat_new = bfa_y(t) | |
scatter(t,x, lab="x") | |
scatter!(t,x_hat_new, lab="x_hat_new") | |
scatter!(t,y,lab="y") | |
scatter!(t,y_hat_new, lab="y_hat_new") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x=Vector{Float64}(undef,400) | |
y=Vector{Float64}(undef,400) | |
for i in range(1,stop=400) | |
x[i]=data[1,i] | |
end | |
for i in range(1,stop=400) | |
y[i]=data[2,i] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BasisFunctionExpansions | |
rbf = UniformRBFE(t,10, normalize=true) | |
bfa_x = BasisFunctionApproximation(x,t,rbf,1) | |
bfa_y = BasisFunctionApproximation(y,t,rbf,1) | |
x_hat = bfa_x(t) | |
y_hat = bfa_y(t) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sol = solve(prob,Tsit5()) | |
t = collect(range(0,stop=10,length=400)) | |
using RecursiveArrayTools | |
randomized = VectorOfArray([(sol(t[i])) for i in 1:length(t)]) | |
data = convert(Array,randomized) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Plots | |
scatter(t,x, lab="x") | |
scatter!(t,x_hat, lab="x_hat") | |
scatter!(t,y,lab="y") | |
scatter!(t,y_hat, lab="y_hat") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nv=2:100 | |
lcurve_x = map(nv) do n | |
rbf = UniformRBFE(t, n, normalize = true) | |
bfa = BasisFunctionApproximation(x,t,rbf,1) | |
(x-bfa(t)) | |
end | |
lcurve_y = map(nv) do n | |
rbf = UniformRBFE(t, n, normalize = true) | |
bfa = BasisFunctionApproximation(y,t,rbf,1) | |
(y-bfa(t)) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i=1 | |
j=1 | |
x_err = Array{Float64}(undef, 99) | |
for i in range(1,stop=99) | |
d=0 | |
for j in range(1,stop=400) | |
if lcurve_x[i][j]>0 | |
d=lcurve_x[i][j]+d | |
else | |
d=-lcurve_x[i][j]+d | |
end | |
x_err[i]=d | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y_err = Array{Float64}(undef, 99) | |
for i in range(1,stop=99) | |
d=0 | |
for j in range(1,stop=400) | |
if lcurve_y[i][j]>0 | |
d=lcurve_y[i][j]+d | |
else | |
d=-lcurve_y[i][j]+d | |
end | |
y_err[i]=d | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scatter(nv,x_err,lab="x_err") | |
scatter!(nv,y_err,lab="y_err") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f(d) | |
i=1 | |
j=2 | |
h=999 | |
for i in range(1,stop=99) | |
if d[i]<=h | |
h=d[i] | |
j=i | |
end | |
end | |
return j | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DifferentialEquations | |
function f(du,u,p,t) | |
du[1] = dx = p[1]*u[1] - u[1]*u[2] | |
du[2] = dy = -3*u[2] + u[1]*u[2] | |
end | |
u0 = [1.0;1.0] | |
tspan = (0.0,10.0) | |
p = [1.5] | |
prob = ODEProblem(f,u0,tspan,p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment