You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Gekko仿真不同参数字典的ARX模型时程序挂起的问题求助

Gekko仿真不同参数字典的ARX模型时程序挂起的问题求助

大家好,我最近在用Gekko做系统辨识与仿真时碰到了一个棘手的问题,想请各位帮忙看看:

我针对两个不同的系统完成了GEKKO系统辨识,这两个系统的输入/输出数量、模型结构(系数维度)完全一致,辨识结果看起来都很理想。但当我尝试通过切换参数字典来分别仿真这两个系统时,其中一个参考APM官网示例搭建的系统能正常完成仿真,可另一个我自己构建的系统却会导致Gekko直接挂起,最后只能手动终止内核才能结束程序。

以下是我用到的完整代码:

import numpy as np
from gekko import GEKKO
import matplotlib.pyplot as plt
import json

ny = 2 # Number of outputs
nu = 2 # Number of inputs

jsonString='{"a": [[0.8303155342446392, 0.5680594837853161], [0.165159576576975, 0.42701139848983305]], "b": [[[-0.00021096098851137172, 3.645093996964678e-05], [0.0024479091118252785, -0.00044792104564900166]], [[0.0019627512690716343, 0.0029626945635920095], [-0.0025037845076475, -0.0016812552089966995]]], "c": [0.09880182193077706, 0.14760139668456007]}'
#jsonString='{"a": [[1.5903954085, 1.0030732272], [-0.59039540951, -14.955482692]], "b": [[[-0.1124849303, 0.00192948919904], [0.0070552841573, -0.001869892092]], [[0.003908541590499999, 0.081949113808], [0.009439868924125, 14.859599644]]], "c": [8.428408192, -0.0017416174455]}'
p=json.loads(jsonString)
for key in p:
    p[key]=np.array(p[key])

# Create GEKKO model
m = GEKKO(remote=False)

# Build GEKKO ARX model
y,u = m.arx(p)

# load inputs
tf = 600 # final time
u1 = np.zeros(tf+1)
u2 = u1.copy()
u1[5:] = 80.0
u2[100:] = 100.0
u[0].value = u1
u[1].value = u2

# customize names
mv1 = u[0]
mv2 = u[1]
cv1 = y[0]
cv2 = y[1]

# options
m.time = np.linspace(0,tf,tf+1)
m.options.imode = 4
m.options.nodes = 2

# simulate
m.solve()

plt.figure(1)
plt.subplot(2,1,1)
plt.plot(m.time,mv1.value,'r-',label=r'$MV_1$')
plt.plot(m.time,mv2.value,'b--',label=r'$MV_2$')
#plt.plot(m.time,mv3.value,'g--',label=r'$MV_3$')
plt.ylabel('MV')
plt.legend(loc='best')
plt.subplot(2,1,2)
plt.plot(m.time,cv1.value,'r:',label=r'$CV_1$')
plt.plot(m.time,cv2.value,'b.-',label=r'$CV_2$')
plt.ylabel('CV')
plt.xlabel('Time (sec)')
plt.legend(loc='best')
plt.show()

说明:当前启用的jsonString是会导致程序挂起的参数,注释掉的那一行是能正常运行的APM官网示例参数。

备注:内容来源于stack exchange,提问作者ht2507

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 14:53:00