Contenuto principale

Fill Tables from Optimization Results

After analyzing your optimization results, you can fill lookup tables with the results selecting one of these approaches depending on whether the optimization is single or multiobjective and how the operating points relate to table inputs:

You can also export optimization results to a new or existing data set. See Exporting to a Data Set.

Lookup Table Filling from Optimization Results Wizard

In a single objective optimization, there is only one solution for each operating point, so you can fill lookup tables with your results. In a multiobjective optimization there is more than one solution per point, and you must first select the preferred solutions before you can use the Lookup Table Filling wizard. To collect your preferred solutions you must use the Selected Solution Slice, then you can use this wizard to fill lookup tables with the selected solutions. Modal and multistart optimizations also have multiple solutions per point but CAGE automatically selects solutions for you, so you do not have to select solutions before lookup table filling.

In the Optimization output view, you can use the Lookup Table Filling wizard as follows.

  1. At the Optimizationname_Output node, select Solution > Fill Lookup Tables, or click the toolbar button .

    The Lookup Table Filling wizard appears.

    Note

    If your tables have been filled before, CAGE remembers all your fill settings between optimization runs and saves the settings with the CAGE project.

  2. Select the tables to fill, and click the button to add them to the list of tables to be filled. Click Next.

    Wizard window for filling CAGE lookup tables from optimization results, showing two lists: available tables on the left and selected tables on the right.

  3. Select or change filling factors for the tables.

    CAGE automatically populates the filling factors for the tables if you created your tables using the Create Lookup Tables from Model wizard, and left the defaults to add all your new tables to a tradeoff.

    View the Tradeoff column to see if a table is associated with a tradeoff. CAGE does not populate the fill factor if a table belongs to more than one tradeoff and there are different fill factors.

    Note

    If you create your tables using the Create Lookup Tables from Model wizard, you can add all your new tables to a tradeoff. The tradeoff can be useful for specifying fill factors for tables, and for investigating optimization results. See Create Lookup Tables from a Model.

    If your tables are not in a tradeoff and you have not filled them before, select filling factors for your tables as follows:

    1. Select a CAGE table to be filled in the Table values to be filled list.

    2. Select the correct variable or model output from the list of Optimization Results and click the button to match the result to the table.

      Your selected filling factor appears in the Fill with column.

      Repeat for other tables.

    Wizard window for selecting optimization results to fill CAGE lookup tables, showing lists of tables, tradeoff options, and normalizer inputs.

    Verify the Normalizer inputs show the correct inputs. You might need to specify the Normalizer inputs to match with optimization results, if you are filling tables with different inputs to your optimization operating points. See Lookup Table Filling When Optimization Operating Point Inputs Differ from Table Inputs.

    Click Next.

  4. Select a Fill Method.

    • Extrapolate Fill — Uses the optimization results to fill the whole table by extrapolation.

    • Direct Fill — Fills only those table cells whose breakpoints exactly match the optimization points.

    • Clip Fill (column-based) — Fills table with direct optimization results. Clips the boundary results along the table column.

    • Clip Fill (row-based) — Fills table with direct optimization results. Clips the boundary results along the table row.

    • Custom Fill — You can write your own table filling algorithm and use the file browser to select it. See Custom Fill Function Structure.

    Wizard window for configuring lookup table fill algorithm, showing fill method options, filter rules for tables, and filter rule inputs.

  5. Use acceptable solutions only — Leave this check box selected to use only optimization results marked as 'acceptable'. See View Your Optimization Results.

  6. Update tradeoffs — Select this check box to update tradeoffs with the optimal values from your optimization. You must update your tradeoff to populate it with optimization results. If you do not update the tradeoff, table values and tradeoff values do not match.

    For best results, you need a table for each model input (free and fixed, except normalizer variables) to fill simultaneously from the optimization results. You can automatically create a tradeoff with all these tables by using the Create Tables from Model wizard. Evaluation of models in tradeoff uses the variable set points for any variables that do not have a tradeoff table.

  7. Use the two check boxes on the right to incrementally fill lookup tables from the results of multiple optimizations with smooth interpolation through existing table values. CAGE can extrapolate the optimization results to pass smoothly through table masks and locked cells. Use these features when you want to use separate optimizations to fill different regions of a lookup table.

    • Use locked table values in extrapolation— When this check box is selected, CAGE smoothly fills the table between fixed table values and optimization results.

      If your calibration tables have fixed values for some table cells, use locked cells for the table cells with fixed values. Such cells often appear on the edge of a table.

    • Use existing extrapolation mask in fill— When this check box is selected, CAGE smoothly fills the table between the values in the mask (from previous lookup table filling) and the current optimization results.

      Select this check box when you want to fill the same table from multiple optimizations that provide solutions at different operating points. Complex calibration problems can require different optimizations for different regions of a table. The toolbox automatically adds filled cells to the table mask.

      If you use the wizard to repeatedly fill a table, CAGE adds to any existing extrapolation mask. As an example, consider filling multiple zones of a table using results from different optimizations. All zones are cumulatively added to the mask. If there is overlap with previous fills, cells are overwritten unless they are locked. Locked cells are never altered by lookup table filling.

  8. (Optional) Specify Filter Rules to select part of the optimization results for lookup table filling. Specify a filter rule with a logical expression using any input or model available for use in lookup table filling. You can specify an operating mode (for modal optimizations) or any valid expression as a filter. For an example, see Filling Tables for Operating Modes.

  9. Click Finish to fill the tables.

    A dialog box shows which tables have been successfully filled. Switch to the Tables view to examine the tables.

    Note

    Lookup tables automatically update after an optimization is rerun.

Lookup Table Filling When Optimization Operating Point Inputs Differ from Table Inputs

For some optimization problems, you want to optimize at operating points in different variables to the tables you want to fill, and use response models as normalizer inputs to tables. For example, your problem requires running an optimization at torque and speed operating points, but you want to fill lookup tables on axes of mainfuel (a response model) and speed. If all the response model input variables are in your optimization, you can fill tables with that response model as a normalizer input.

  1. Create your tables using the Create Lookup Tables from Model wizard, and select a response model as an input to your tables. For example, using the example project DieselPointByPoint.cag in the mbctraining folder, create tables from the MAINFUEL model, and select MAINFUEL as the Y-axis normalizer input, as shown.

    Dialog for creating tables from a model, showing Y-axis input as SPEED, X-axis input as MAINFUEL, and normalizer tables with input-output values.

    You must specify the breakpoints for your model input normalizer. Edit breakpoints by clicking the button after Table columns, and enter a number of points and the range to space the breakpoints over. If you do not do this, model inputs are spaced over 0-1, because CAGE cannot determine the range automatically as happens with variables. After you create your tables with a model input, in the Variable Dictionary you can view a new variable named modelname_input with the range you specified. CAGE uses this input variable to match to model names when you fill lookup tables from optimization results.

  2. When you are ready to fill lookup tables with optimization results, open the Lookup Table Filling from Optimization Results Wizard, select your tables with the response model normalizer input, e.g., MAINFUEL_norm, and click Next.

    Wizard window for selecting CAGE tables to fill from optimization results, showing available tables on the left and selected tables on the right.

  3. On the Optimal Result Selection screen, CAGE looks for matches by name among the variables and response models in the Optimization Results list. Verify the Normalizer Input column shows the input you want. If CAGE cannot find a match, the Input column is empty. To select or change an input, select an item in the Optimization Results list and click the button to select the optimization result for normalizer input.

    Wizard window for selecting optimization results to fill CAGE tables, showing lists of tables with fill and tradeoff columns, normalizer inputs, and optimization results.

  4. Click Next and Finish to fill your tables.

Filling Tables Via Data Sets

The alternative method of filling tables with optimization output uses Data Sets. This can be useful to see the optimization results and the filled table surface on the same plot. In Data Sets you can also manually edit the results before filling, and compare results with external data.

  1. From the optimization Output node, click (Export to Data Set) in the toolbar (or select Solution > Export to Data Set). The Export to Data Set dialog box appears. See Exporting to a Data Set for instructions.

  2. Go to the Data Sets view (click the Data Sets button in the Data Objects pane) to see that the table of optimization results is contained in the new data set.

    You can now use this data set (or any optimization results) to fill lookup tables, as you can with any data set.

  3. Select the data set and click (Fill Table from Data Set) in the toolbar.

  4. Clear the check box to Show table history after fill.

  5. Choose to fill a table with the desired optimization output by selecting them in the two lists, then click the button Fill Table at the bottom right.

  6. Right-click the display and select Surface to see the filled table surface and the optimization output values.

See also Fill Lookup Tables from Data for an example showing how to use data sets to fill lookup tables.

Custom Fill Function Structure

It is useful to create your own function to fill lookup tables from the results of an optimization, for example, to implement alternative fill methods, smoothing strategies, or to customize output.

The input/output structure of a custom fill function resembles that of the MATLAB® interpolation routines INTERP1 and INTERP2. To see the structure of the function, it is best to look at an example:

  1. Locate and open the file griddataTableFill.m in the mbctraining folder.

  2. Type this at the command line to open the example:

    edit griddataTableFill

All 2-D custom fill functions must take these six inputs:

InputDescription

col

Column coordinate of optimization results (NF-by-1)

row

Row coordinate of optimization results (NF-by-1)

filldata

Optimized results at (row, col) points (NF-by-1)

colaxis

Column breakpoints of table to be filled (1-by-NCOL)

rowaxis

Row breakpoints of table to be filled (NROW-by-1)

currtabdata

Existing table values of table to be filled (NROW-by-NCOL)

The function must pass three output arguments back to CAGE, to allow CAGE to fill the table:

OutputDescription
okBoolean flag to indicate success of the table fill (TRUE or FALSE)
tabvalNew table values of table to be filled (NROW-by-NCOL)
fillmaskLogical matrix to indicate cells to be added to the extrapolation mask as a consequence of the table being filled (NROW-by-NCOL)

In the above specifications:

  • NF is the number of points from the optimization results that are used to fill your tables.

  • NCOL is the number of column breakpoints in the table.

  • NROW is the number of row breakpoints in the table.

Your function should handle the cases when the table fill is successful or not. In griddataTableFill, this is handled using the try-catch construct around the call to griddata. If griddata should fail, then the ok flag is set to false and the function returns.

Custom Fill Function for 1–D Tables

You can also write custom fill functions to fill 1–D tables. In this case the input and output specifications are as follows:

InputDescription
row Row coordinate of optimization results (NF-by-1)
filldataOptimized results at (row, col) points (NF-by-1)
rowaxisRow breakpoints of table to be filled (NROW-by-1)
currtabdataExisting table values of table to be filled (NROW-by-1)

OutputDescription
ok Boolean flag to indicate success of the table fill (TRUE or FALSE)
tabvalNew table values of table to be filled (NROW-by-1)
fillmaskLogical matrix to indicate cells to be added to the extrapolation mask as a consequence of the table being filled (NROW-by-1)

Exporting to a Data Set

You can export the optimization output results to new or existing data sets.

To export to a data set:

  1. Select Solution > Export to Data Set or use the toolbar button. The Export to Data Set dialog box appears.

    Export To Data Set dialog box with the data set Optim_fmincon selected.

  2. If exporting to a New data set (the default), you can edit the name in the edit box.

  3. If you want to overwrite or add to an existing data set:

    1. Click the option button Modify existing.

    2. Select the desired data set in the list.

    3. Choose from Action list:

      • Append adds the data to the chosen data set.

      • Overwrite replaces all data in the data set with the new data.

  4. By default, the check box Use acceptable solutions only is selected. Optimization results with selected Accept check boxes are exported. Clear the Use acceptable solutions only check box if you want to export all the optimization results.

  5. Click OK and the data is exported to the data set.

This table summarizes the export rules.

Export rules

All fixed and optimization variables are exported where possible.

No models are exported to the data set. If you want to evaluate a model at the variable values, add the model to the data set in the Data Sets view.

When appending, the rules are the same as when merging data sets:

  • Columns of inputs are appended to columns with names that match in the data set you are appending to.

  • Outputs (models) and any other columns without matching names are not appended.

  • The values for any unmatched columns in the data are set to the set point if possible, or zero otherwise.

See Also