Lookup Table
The lookup table feature allows users to perform interpolation with predefined data during optimization modeling. It is suitable for data-driven modeling scenarios, such as modeling aircraft performance based on wind-tunnel test data. Currently, one-dimensional, two-dimensional, and three-dimensional lookup tables are supported.
Before use, you need to import the relevant module:
from optimake.extension import *
The lookup table feature depends on the scipy library. Make sure that scipy version 1.14.0 or later is installed.
Modeling
Defining Lookup Tables
Below are examples of defining one-dimensional and two-dimensional lookup tables:
# Define a one-dimensional lookup table
M2 = [0, 0.4, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8]
etatab = [0.54, 0.54, 0.54, 0.75, 0.79, 0.78, 0.89, 0.93, 0.93]
lt_eta = lookup_table(name='eta', points=M2, values=etatab, method='cubic', bc_type='natural', interp_func=None)
# Define a two-dimensional lookup table
Mtab = np.array(
[0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8])
alttab = 304.8 * np.array(
[0, 5, 10, 15, 20, 25, 30, 40, 50, 70])
Ttab = 4448.222* np.array(
[[24.2, 24.0, 20.3, 17.3, 14.5, 12.2, 10.2, 5.7, 3.4, 0.1], # M = 0
[28.0, 24.6, 21.1, 18.1, 15.2, 12.8, 10.7, 6.5, 3.9, 0.2], # M = 0.2
[28.3, 25.2, 21.9, 18.7, 15.9, 13.4, 11.2, 7.3, 4.4, 0.4],
[30.8, 27.2, 23.8, 20.5, 17.3, 14.7, 12.3, 8.1, 4.9, 0.8],
[34.5, 30.3, 26.6, 23.2, 19.8, 16.8, 14.1, 9.4, 5.6, 1.1],
[37.9, 34.3, 30.4, 26.8, 23.3, 19.8, 16.8, 11.2, 6.8, 1.4],
[36.1, 38.0, 34.9, 31.3, 27.3, 23.6, 20.1, 13.4, 8.3, 1.7],
[36.1, 36.6, 38.5, 36.1, 31.6, 28.1, 24.2, 16.2, 10.0, 2.2],
[36.1, 35.2, 42.1, 38.7, 35.7, 32.0, 28.1, 19.3, 11.9, 2.9],
[36.1, 33.8, 45.7, 41.3, 39.8, 34.6, 31.1, 21.7, 13.3, 3.1]])
lt_T = lookup_table(name='T', points=[Mtab.tolist(), alttab.tolist()], values=Ttab.tolist(), method='cubic', interp_func=None)
Use the lookup_table interface to define a lookup table. Its parameters are as follows:
name: Lookup table namepoints: Input points of the lookup table. The points in each dimension must be strictly increasing- For a one-dimensional lookup table, this is a list
- For a two-dimensional lookup table, this is a list containing two lists, representing the points of the two input variables respectively
- For a three-dimensional lookup table, this is a list containing three lists, representing the points of the three input variables respectively
values: Output values of the lookup table- For a one-dimensional lookup table, this is a list
- For a two-dimensional lookup table, this is a two-dimensional list. Each row corresponds to one point of the first input variable, and each column corresponds to one point of the second input variable
- For a three-dimensional lookup table, this is a three-dimensional list. Each layer corresponds to one point of the first input variable, each row corresponds to one point of the second input variable, and each column corresponds to one point of the third input variable
method: Interpolation method. Available values arecubic,pchip,akima,makima, anduser. The default iscubicbc_type: Boundary condition type. This is valid only whenmethodiscubicandpointsis one-dimensional. Available values arenatural,clamped, andnot-a-knot. The default isnaturalinterp_func: User-defined interpolation function. This is valid only whenmethodisuser. It must be a function object of order 3, with the lookup table input points as input and the lookup table output values as output
The interpolation functionality above is implemented based on the scipy.interpolate library. The supported interpolation methods and boundary condition types are consistent with those in scipy.interpolate. You can refer to the scipy.interpolate documentation for more information about interpolation methods and boundary condition types.
Using Lookup Tables for Interpolation
Using a defined lookup table, you can perform interpolation in optimization modeling through the interpolation interface. Its parameters are as follows:
lookup_table: A lookup table defined through thelookup_tableinterface*args: Input variables of the lookup table, either expressions in terms of optimization variable or constants
For example, below is an example of using defined lookup tables for interpolation:
eta = interpolation(lt_eta, Mach)
Thrust = interpolation(lt_T, Mach, h)
When the input variables of the lookup table are constants, the interpolation function returns a constant value. Otherwise, when the input variables of the lookup table are expressions in terms of optimization variable , the interpolation function returns an expression in terms of optimization variable , which can be used for modeling as an objective function or constraint.
For example, below is an example of minimizing the lookup table output as an objective function:
prob.objective((Thrust - Thrust_ref) ** 2)