estimate lookup table values from data
objectives
this example shows how to estimate lookup table values from time-domain input-output (i/o) data in the parameter estimator.
about the data
in this example, use the i/o data in lookup_regular.mat
to estimate the
values of a lookup table. the mat-file includes the following variables:
xdata1
— consists of 63 uniformly-sampled input data points in the range [0,6.5]ydata1
— consists of output data corresponding to the input data samplestime1
— time vector
use the i/o data to estimate the lookup table values in the
lookup_regular
simulink® model. the lookup table in the model contains ten values, which are stored in the
matlab® variable table
. the initial table values comprise a vector of
0s. to learn more about how to model a system using lookup tables, see .
lookup table estimation model
open the lookup table model.
open_system('lookup_regular.slx')
this command opens the simulink® model, and loads the estimation data into the matlab® workspace.
open a parameter estimation session
to estimate the lookup table values, open a parameter estimation session.
in the simulink model, select parameter estimator from the apps tab, in the gallery, under control systems to open a new session with name lookup_regular in the parameter estimator.
estimate the table values using default settings
use the following steps to estimate the lookup table values.
create a new experiment by clicking new experiment on the parameter estimation tab. name it
estimationdata
. then import the i/o data,xdata1
andydata1
, and the time vector,time1
, into the experiment. to do this open the experiment editor by right-clickingestimationdata
and selecting edit.... type[time1,ydata1]
in the output dialog box and[time1,xdata1]
in the input dialog box in the experiment editor. for more information, see . after you import the data the experiment looks as follows:run an initial simulation to view the i/o data, simulated output, and the initial table values. to do so, type the following commands at the matlab prompt:
sim('lookup_regular') figure(1); plot(xdata1,ydata1, 'm*', xout, yout,'b^') hold on; plot(linspace(0,6.5,10), table, 'k', 'linewidth', 2); legend('measured data','initial simulation data','initial table values');
the x-axis and y-axis of the figure represent the input and output data, respectively. the figure shows the following plots:
measured data — represented by the magenta stars (*).
initial table values — represented by the black line.
initial simulation data — represented by the blue deltas (δ).
you can see that the initial table values and simulated data do not match with the measured data.
to select the table values to estimate, on the parameter estimation tab, click the select parameters button to open the edit:estimated parameters dialog. in the parameters tuned for all experiments panel, click select parameters to launch the select model variables dialog. check the box next to table, and click ok.
the edit:estimated parameters window now looks as follows. the table values are selected for estimation by default.
on the parameter estimation tab, click select experiments.
estimationdata
is selected for estimation by default. if not, check the box under the estimation column, and click close.to estimate the table values using the default settings, on the parameter estimation tab, click estimate to open the parameter trajectory plot and estimation progress report window. the parameter trajectory plot shows the change in the parameter values at each iteration.
after the estimation converges, the parameter trajectory plot looks like this:
the estimation progress report shows the iteration number, number of times the objective function is evaluated, and the value of the cost function at the end of each iteration. after the estimation converges, the estimation progress report looks like this:
the estimated parameters are saved in
estimatedparams
in the results section of the data browser pane on the left. to view the results, right-click onestimatedparams
and then select open. the report resembles the following.this report includes the estimated parameter values, the final value of the cost function, and other optimization results. you can see that the optimization stopped when the size of the gradient, 1.18e-14 was less than the criteria value, 1e-3.
validate the estimation results
after you estimate the table values, as described in estimate the table values using default settings, you must use another data set to validate that you have not over-fitted the model. you can plot and examine the following plots to validate the estimation results:
residuals plot
measured and simulated data plots
to validate the estimation results:
create a new experiment to use for validation. name it
validationdata
. import the validation i/o data,xdata2
andydata2
, and time vector,time2
in thevalidationdata
experiment. to do this open the experiment editor by right-clickingvalidationdata
and selecting edit.... then, type[time2,ydata2]
in the output dialog box and[time2,xdata2]
in the input dialog box in the experiment editor. for more information, see .to select the experiment for validation, on the parameter estimation tab, click select experiments. the
validationdata
experiment is selected for estimation by default. deselect the box for estimation and check it for validation.to select results to use, on the validation tab, click select results to validate. deselect
use current parameter values
and selectestimatedparams
, and click ok.the parameter estimator, by default, displays the experiment plot after validation. add the residuals plot by checking the corresponding box on the validation tab.
to start validation, on the validation tab, click validate.
examine the plots
experiment plot
you can see that the data simulated using the estimated parameters agrees with the measured validation data.
click residual plot: validationdata to open the residuals plot.
the residuals, which show the difference between the simulated and measured data, lie in the range [-0.15,0.15]— within 15% of the maximum output variation. this indicates a good match between the measured and the simulated table data values.
plot and examine the estimated table values against the validation data set and the simulated table values by typing the following commands at the matlab prompt.
sim('lookup_regular') figure(2); plot(xdata2,ydata2, 'm*', xout, yout,'b^') hold on; plot(linspace(0,6.5,10), table, 'k', 'linewidth', 2)
the plot shows that the table values, displayed as the black line, match both the validation data and the simulated table values. the table data values cover the entire range of input values, which indicates that all the lookup table values have been estimated.