英文:
How to avoid creating many binary switching variables in GEKKO
问题
我正在通过在GEKKO
中使用IMODE = 3
来最小化数千个方程的顺序来求解14个变量。
每个方程都是真实响应与P-spline模型(即惩罚B-spline)的预测之间的平方误差:
eq[i] = m.Minimize((y_true[i] - spline(coeffs, knots, vars)[i]) ** 2)
。
这些样条模型由它们的系数和节点组成(这些节点是先前计算的),以及要优化的14个变量。
在构建用于GEKKO
的P-spline模型时,我需要检查变量的值位于哪些节点之间。我尝试使用m.if2
和m.if3
来实现这一点;然而,这两个逻辑函数都会创建许多额外的二进制切换变量,特别是对于具有许多片段的样条。最终,我得到了成千上万个二进制切换变量。这些超过了方程的数量,导致自由度小于0。
问题:我如何避免使用m.if2
或m.if3
来构建我的样条?
注意:我知道GEKKO
有预先构建的对象m.bspline
;然而,似乎它只能处理具有两个独立变量的2D B样条,而我的样条可以具有超过十个独立变量。
英文:
I am solving for 14 variables by minimizing on the order of thousands of equations with IMODE = 3
in GEKKO
.
Each equation is the squared error between the true response and the prediction of a P-spline model (i.e., penalized B-spline):
eq[i] = m.Minimize((y_true[i] - spline(coeffs, knots, vars)[i]) ** 2)
.
The spline models are constituted of their coefficients and knots (which are previously calculated) along with the 14 variables to optimize.
When building the P-spline models for GEKKO
, I need to check in-between which knots the value of a variable lies. I tried using both m.if2
and m.if3
to achieve this; however, both of these logical functions create many additional binary switching variables, especially for splines with many pieces. In the end, I end up with tens of thousands of binary switching variables. These outnumber the equations, resulting in the number of degrees of freedom being less than 0.
Question: How can I avoid using m.if2
or m.if3
to build my splines?
Note: I am aware that GEKKO
has the prebuilt object m.bspline
; however, it appears that it can only do 2D B-splines with two independent variables, while my splines can have over ten independent variables.
答案1
得分: 1
The m.if2()
function uses MPCCs instead of binary variables. Additional slack variables and equations are created when the m.if2()
function is used. The m.if2()
function can be numerically unreliable. The m.if3()
function is typically more reliable, but it requires the additional binary variables and an MINLP solver (APOPT) to find the solution. Negative degrees of freedom
is a warning and may still solve because inequality constraints may not be active at the solution.
One additional thing to consider is the spline(coeffs, knots, vars)[i]
is not re-evaluated during the solution. The Gekko model is compiled into byte-code and there are no call-backs into the original functions. Because the spline is evaluated once during the model initialization, could the position be determined either before or after the solve?
A final suggestion is to use a machine learned model such as a Neural Network, Gaussian Processes, Support Vector Regressor, or similar form that can be imported into Gekko with ML functions after it has been trained with sklearn or tensorflow / keras.
英文:
The m.if2()
function uses MPCCs instead of binary variables. Additional slack variables and equations are created when the m.if2()
function is used. The m.if2()
function can be numerically unreliable. The m.if3()
function is typically more reliable, but it requires the additional binary variables and an MINLP solver (APOPT) to find the solution. Negative degrees of freedom
is a warning and may still solve because inequality constraints may not be active at the solution.
One additional thing to consider is the spline(coeffs, knots, vars)[i]
is not re-evaluated during the solution. The Gekko model is compiled into byte-code and there are no call-backs into the original functions. Because the spline is evaluated once during the model initialization, could the position be determined either before or after the solve?
A final suggestion is to use a machine learned model such as a Neural Network, Gaussian Processes, Support Vector Regressor, or similar form that can be imported into Gekko with ML functions after it has been trained with sklearn or tensorflow / keras.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论