Main Content

Estimate Constrained Values of a Lookup Table

Objectives

This example shows how to estimate constrained values of a lookup table in the Parameter Estimator. Apply monotonically increasing constraints to the lookup table output values, and use the Parameter Estimator to estimate the table values.

About the Data

In this example, use lookup_increasing.mat, which contains the measured I/O data for estimating the lookup table values. The MAT file includes the following variables:

  • xdata1 — Input data consisting of 602 uniformly sampled data points in the range [-5,5].

  • ydata1 — Output data corresponding to the input data samples.

  • time1 — Time vector.

Use the I/O data to estimate monotonically increasing output values of the lookup table in the lookup_increasing Simulink® model.

Lookup Table Increasing Constraints Models

Open the lookup table model.

open_system('lookup_increasing.slx')

This command opens the Simulink® model, and loads the estimation data in the MATLAB® workspace.

Simulink model with Lookup Table

Lookup Table Output

View the table output values by double-clicking the Lookup Table block.

Lookup Table block parameters dialog box

The table contains 11 output values at breakpoints [-5:5], specified in the Function Block Parameters dialog box. To learn more about how to specify the table values, see Enter Breakpoints and Table Data.

The Table data field shows that the table output values are the cumulative sum of the values stored in variable ydelta. Thus, if yn are the 11 table output values, ydelta is (y1, y2y1, y3y2, ..., y11y10). The initial ydelta values are loaded from lookup_increasing.mat.

The initial table output values are not monotonically increasing. To ensure monotonically increasing table output values, the difference between adjacent table output values should be positive. To do so, estimate ydelta in the Parameter Estimator using the measured I/O estimation data, and constrain ydelta(2:end) to be positive during estimation.

Estimate the Monotonically Increasing Table Values Using Default Settings

  1. 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 session with the name lookup_increasing in the Parameter Estimator.

    Parameter Estimator app main window. Parameter Estimation toolstrip is on the top. Parameters, Experiments, Results, and Preview panes are on the left, from top to bottom.

  2. Create an experiment and import the I/O data.

    On the Parameter Estimation tab, click New Experiment. Type [time1,ydata1] in Outputs and [time1,xdata1] in Inputs of the Edit Experiment dialog box. Click OK. A new experiment with name Exp is created in the Experiments area of the app. Rename the experiment EstimationData by right-clicking the default experiment name, Exp, and selecting Rename. For more information, see Import Data for Parameter Estimation.

    Edit Experiment dialog box with Outputs, Inputs, Initial States, and Parameters sections

  3. Run an initial simulation to view the measured data, simulated model values, and the initial table values by typing the following commands at the MATLAB® prompt.

    sim('lookup_increasing')
    figure(1)
    plot(xdata1,ydata1,'m*',xout,yout,'b^')
    hold on
    plot(-5:5,cumsum(ydelta),'k','LineWidth',2)
    xlabel('Input Data')
    ylabel('Output Data')
    legend('Measured data',...
        'Initial simulated data',...
        'Initial table output')

    Data plot

    The initial table output values and simulated data do not match the measured data.

  4. Select parameter for estimation.

    On the Parameter Estimation tab, click Select Parameters. The Edit: Estimated Parameters dialog box opens. In the Parameters Tuned for all Experiments panel, click Select parameters to open the Select Model Variables dialog box. Check the box next to ydelta, and click OK.

    Select model variables dialog box with variable ydelta selected

    The ydelta values are selected for estimation by default in the Edit: Estimated Parameters dialog box.

    Edit: Estimated Parameters dialog box with Estimate box selected for ydelta

  5. Apply a monotonically increasing constraint on the table output values. For more details about the table, see Lookup Table Output.

    In the Edit: Estimated Parameters dialog box, click the arrow next to the ydelta values. In the expanded menu, set Minimum ydelta values to [-Inf,zeros(1,10)]. Thus, while the first value in ydelta can by anything, subsequent values which are the difference between adjacent table output values, must be positive.

    Edit: Estimated Parameters dialog box with minimum values specified for ydelta

  6. Select EstimationData experiment for estimation.

    On the Parameter Estimation tab, click Select Experiment. By default, EstimationData is selected for estimation. If not, check the box under the Estimation column, and click OK.

    Select Experiments dialog box with the Estimation box against EstimationData checked

  7. Estimate the table values using default settings.

    On the Parameter Estimation tab, click Estimate.

    The Parameter Trajectory plot shows the change in the parameter values at each iteration.

    Parameter Trajectory plot

    The Estimation Progress Report shows the iteration number, number of times the objective function is evaluated, and value of the cost function at the end of each iteration.

    Estimation Progress Report

    The estimated parameters are saved in a new variable, EstimatedParams, in the Results area of the app. To view the estimated parameters, right-click EstimatedParams and select Open.

    View Result: EstimatedParams dialog box showing the Estimation results

    The estimated ydelta(2:end) values are positive. Thus, the output of the table, which is the cumulative sum of the values stored in ydelta, is monotonically increasing.

Validate the Estimation Results

After you estimate the table values, as described in Estimate the Monotonically Increasing Table Values Using Default Settings, you use another measured data set to validate and check that you have not over-fit the model. You can plot and examine the following plots to validate the estimation results:

  • Residuals plot

  • Measured and simulated data plots

  1. Create an experiment to use for validation and import the validation I/O data.

    On the Parameter Estimation tab, click New Experiment. Type [time2,ydata2] in Outputs and [time2,xdata2] in Inputs of the Edit Experiment dialog box. Name the experiment ValidationData by right-clicking the default experiment name, Exp, in the Experiments area of the app, and selecting Rename. For more information, see Import Data for Parameter Estimation.

  2. Select the experiment for validation.

    Click Select Experiments on the Parameter Estimation tab. The ValidationData experiment is selected for estimation by default. Clear Estimation and select the box for Validation.

    Select Experiments dialog box with the Estimation box against EstimationData and the Validation box against ValidationData checked

  3. Select the results to validate.

    On the Validation tab, click Select Results to Validate. Clear Use current parameter values, select EstimatedParams, and click OK.

    Select Results dialog box with EstimatedParams selected

  4. Select the plots to display during validation.

    The Parameter Estimator displays the experiment plot after validation by default. Add the residuals plot by selecting the corresponding box on the Validation tab.

    Plot Measured & Simulated Data and Plot Residuals options selected on the Validation tab

    Click Validate.

  5. Examine the plots.

    1. The experiment plot shows the data simulated using estimated parameters agrees with the measured validation data.

      ValidationData plot showing measured data and simulated data

    2. To view the residuals plot, click Residual plot: ValidationData tab.

      Residual Plot

      The residuals, which show the difference between the simulated and measured data, lie within 15% of the maximum output variation. This indicates a good match between the measured and simulated table data values.

    3. Plot and examine the validation data, simulated data, and estimated table values.

      sim('lookup_increasing')
      figure(2); plot(xdata2,ydata2,'m*',xout,yout,'b^')
      hold on; plot(-5:5,cumsum(ydelta),'k','LineWidth', 2)
      xlabel('Input Data'); ylabel('Output Data');
      legend('Validation data','Simulated data','Table output values');

      Data plot

      The table output values match both the measured data and the simulated table values. The table output values cover the entire range of input values, which indicates that all the lookup table values have been estimated.

Related Topics