As a potential solution to this question, how could one coerce GEKKO
's m.bspline
method which builds 2D B-splines in the form z = f(x, y)
to build 1D B-splines in the form z = f(x)
?
More specifically, the 2D method takes in the following arguments:
Essentially, I want to trick the method into ignoring the y independent variable completely.
Try using a zero (or some other nominal) value for y
in creating the b-spline.
from gekko import GEKKO
import numpy as np
m = GEKKO(remote=False)
xgrid = np.linspace(-1, 1, 50)
ygrid = np.linspace(-1e-5,1e-5,50)
xg,yg = np.meshgrid(xgrid,ygrid)
z_data = xg**2
x = m.Var(0.2,lb=-0.8,ub=0.8)
y = m.Param(0)
z = m.Var(0.1)
m.bspline(x,y,z,xgrid,ygrid,z_data)
m.Minimize(z)
m.options.SOLVER=3
m.solve(disp=False)
print(f'x={x.value[0]}')
print(f'y={y.value[0]}')
There is also an option to inject the knots and coefficients directly if they are already fit with another function. If this is the case, just keep the value of y
as a parameter so it is not adjustable.