I am trying to approximate one function and then use it in the dynamic GEKKO simulation. I could not find any information on how to do this with multiple variables (such as a,b,d function parameters). Here is the example of the code:
from gekko import brain
import numpy as np
import matplotlib.pyplot as plt
b = brain.Brain(remote = False)
b.input_layer(1)
b.layer(linear=2)
b.layer(tanh=5)
b.layer(linear=2)
b.output_layer(1)
x = np.linspace(-2,2,100)
a = np.linspace(0,1,10)
b = np.linspace(0,0.5,10)
d = np.linspace(-1,0,10)
def function(x,a,b,d):
y = 0.0001*x + a*b*x + d
return y
b.learn(x,function(x)) # Not sure here how to implement, does not allow multiple variables in x
xp = np.linspace(-2,2,100)
yp = b.think(xp)
plt.figure()
# plt.plot(x,y,'bo')
plt.plot(xp,yp[0],'r-')
plt.show()
Does anybody know how can I train the model for this?
Also is there any method to save the model so that I dont need to train it every time, and I would simply insert it into the dynamic simulation (GEKKO IMODE 4 or 7).
Finally I am struggling to get a certain value after training the model. I have to specify x = np.linspace(0,0.000001,100) (the same form of x as for training) to get y at point x = 0. Is there any simpler method just to write y = b.think(0) and get one value at x = 0? Or y = b.think(0,0.1,...,...) with multiple variables .
I would really appreciate to get an answer for at least of some questions :).
