使用B样条方法,形式为z = f(x, y),拟合z = f(x)。

huangapple go评论63阅读模式
英文:

Using B-spline method of the form z = f(x, y) to fit z = f(x)

问题

作为对这个问题的潜在解决方案,如何强制GEKKOm.bspline方法,该方法构建2D B样条,形式为z = f(x, y),以构建形式为z = f(x)的1D B样条?

更具体地说,2D方法接受以下参数:

  • x, y = 独立的Gekko参数或变量,作为z的预测变量
  • z = 依赖的Gekko变量,其中z = f(x, y)
  • x_data = x节点的1D列表或数组,大小为(nx)
  • y_data = y节点的1D列表或数组,大小为(ny)
  • z_data = c系数的2D列表或矩阵,大小为(nx-kx-1)*(ny-ky-1)
  • kx = x方向样条的阶数,默认为3
  • ky = y方向样条的阶数,默认为3

基本上,我想要欺骗该方法完全忽略y独立变量。

英文:

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:

  • x,y = independent Gekko parameters or variables as predictors for z
  • z = dependent Gekko variable with z = f(x,y)
  • x_data = 1D list or array of x knots, size (nx)
  • y_data = 1D list or array of y knots, size (ny)
  • z_data = 2D list or matrix of c coefficients, size (nx-kx-1)*(ny-ky-1)
  • kx = degree of spline in x-direction, default=3
  • ky = degree of spline in y-direction, default=3

Essentially, I want to trick the method into ignoring the y independent variable completely.

答案1

得分: 1

尝试在创建B样条时为 y 使用零(或其他名义值)。

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]}')

如果已经使用其他函数拟合了 结点和系数,也有一种选项可以将它们直接注入。如果是这种情况,请将 y 的值保持为参数,以便不可调整。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月15日 05:43:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定