Applications include
cogeneration (power and heat),
drilling automation, severe slugging control, solar thermal energy production,
solid oxide fuel cells, flow assurance,
Enhanced oil recovery,
Essential oil extraction, and
Unmanned Aerial Vehicles (UAVs). There are many other references to APMonitor and GEKKO as a sample of the types of applications that can be solved. GEKKO is developed from the National Science Foundation (NSF) research grant #1547110 and is detailed in a Special Issue collection on combined scheduling and control. Other notable mentions of GEKKO are the listing in the Decision Tree for Optimization Software, added support for
APOPT and BPOPT solvers, projects reports of the online Dynamic Optimization course from international participants. GEKKO is a topic in online forums where users are solving optimization and optimal control problems. GEKKO is used for advanced control in the Temperature Control Lab (TCLab) for process control education at 20 universities.
Machine learning One application of
machine learning is to perform regression from training data to build a correlation. In this example,
deep learning generates a model from training data that is generated with the function 1-\cos(x). An
artificial neural network with three layers is used for this example. The first layer is linear, the second layer has a hyperbolic tangent activation function, and the third layer is linear. The program produces parameter weights that minimize the sum of squared errors between the measured data points and the neural network predictions at those points. GEKKO uses gradient-based optimizers to determine the optimal weight values instead of standard methods such as
backpropagation. The gradients are determined by automatic differentiation, similar to other popular packages. The problem is solved as a constrained optimization problem and is converged when the solver satisfies
Karush–Kuhn–Tucker conditions. Using a gradient-based optimizer allows additional constraints that may be imposed with domain knowledge of the data or system. from gekko import brain import numpy as np b = brain.Brain() b.input_layer(1) b.layer(linear=3) b.layer(tanh=3) b.layer(linear=3) b.output_layer(1) x = np.linspace(-np.pi, 3 * np.pi, 20) y = 1 - np.cos(x) b.learn(x, y) The neural network model is tested across the range of training data as well as for extrapolation to demonstrate poor predictions outside of the training data. Predictions outside the training data set are improved with hybrid machine learning that uses fundamental principles (if available) to impose a structure that is valid over a wider range of conditions. In the example above, the hyperbolic tangent activation function (hidden layer 2) could be replaced with a sine or cosine function to improve extrapolation. The final part of the script displays the neural network model, the original function, and the sampled data points used for fitting. import matplotlib.pyplot as plt xp = np.linspace(-2 * np.pi, 4 * np.pi, 100) yp = b.think(xp) plt.figure() plt.plot(x, y, "bo") plt.plot(xp, yp[0], "r-") plt.show()
Optimal control Optimal control is the use of
mathematical optimization to obtain a policy that is constrained by differential \left(\frac{d\,x_1}{d\,t}=u\right), equality \left(x_1(0) = 1\right), or inequality \left(-1 \le u(t) \le 1\right) equations and minimizes an objective/reward function \left(\min_u \frac{1}{2} \int_0^2 x_1^2(t) \, dt\right). The basic optimal control is solved with GEKKO by integrating the objective and transcribing the differential equation into algebraic form with orthogonal collocation on finite elements. from gekko import GEKKO import numpy as np import matplotlib.pyplot as plt m = GEKKO() # initialize gekko nt = 101 m.time = np.linspace(0, 2, nt) • Variables x1 = m.Var(value=1) x2 = m.Var(value=0) u = m.Var(value=0, lb=-1, ub=1) p = np.zeros(nt) # mark final time point p[-1] = 1.0 final = m.Param(value=p) • Equations m.Equation(x1.dt() == u) m.Equation(x2.dt() == 0.5 * x1 ** 2) m.Minimize(x2 * final) m.options.IMODE = 6 # optimal control mode m.solve() # solve plt.figure(1) # plot results plt.plot(m.time, x1.value, "k-", label=r"$x_1$") plt.plot(m.time, x2.value, "b-", label=r"$x_2$") plt.plot(m.time, u.value, "r--", label=r"$u$") plt.legend(loc="best") plt.xlabel("Time") plt.ylabel("Value") plt.show() == See also ==