Model-Based Calibration Toolbox

Gasoline Case Study Design of Experiment

This example shows how to design an experiment for the gasoline case study problem using the command-line interface to Model-Based Calibration Toolbox™. The gasoline case study describes how to systematically develop a set of optimal steady-state engine calibration tables using Model-Based Calibration Toolbox™ software.

Create Project and Test Plan

project = mbcmodel.CreateProject('GasolineCaseStudy');
% Define Inputs for test plan
localInputs = mbcmodel.modelinput(...
    'Symbol', 'S',...
    'Name', 'SPARK',...
    'Range', [0 50]);
globalInputs = mbcmodel.modelinput(...
    'Symbol', {'N','L','ICP','ECP'},...
    'Name',   {'SPEED','LOAD','INT_ADV','EXH_RET'},...
    'Range',  {[500 6000],[0.0679 0.9502],[-5 50],[-5 50]});
% Create test plan
TP = CreateTestplan( project, {localInputs,globalInputs} );

Create Space-Filling Design

CreateDesign defaults to creating a design for the outer (global) level.

sfDesign = CreateDesign(TP, ...
    'Type', 'Latin Hypercube Sampling',...
    'Name', 'Space Filling');

Add Boundary Constraints

Load boundary constraints from another project file and add to design.

otherProject = mbcmodel.LoadProject( [matlabroot,'\toolbox\mbc\mbctraining\Gasoline_project.mat']);
boundaryConstraints = otherProject.Testplans(1).BoundaryModel('global');
% Design constraints are specified as an array of
% mbcdoe.designconstraint objects.
sfDesign.Constraints = boundaryConstraints;

Change Selection Criteria of LHS Design

Get the design properties and change the SelectionCriteria to 'minimax'. Putting the changed properties back into the design causes the design to update.

designGenerator = sfDesign.Generator;
% Use "minimax"
designGenerator.SelectionCriteria = 'minimax'
sfDesign.Generator = designGenerator;
 
designGenerator = 
Latin Hypercube Sampling design generator
                Style: 'Space-filling'
                 Type: 'Latin Hypercube Sampling'
       NumberOfInputs: 4
               Limits: [4x2 double]
       NumberOfPoints: 100
    SelectionCriteria: 'minimax'
             Symmetry: 1

 

Get Required Number of Points for a Constrained Design.

As in the Design Editor, when a design has constraints it is hard to achieve the number of points you require. In the design editor you try different numbers of points and regenerate. At the command line you can use the ConstrainedGenerate method to do this.

Generate Design

Use ConstrainedGenerate to make a 200 point design.

sfDesign = ConstrainedGenerate( sfDesign, 200, 'UnconstrainedSize', 800, 'MaxIter',10  );

% How did we do?
finalNumberOfPoints = sfDesign.NumberOfPoints
% How many points did we need in total?
totalNumberOfPoints = sfDesign.Generator.NumberOfPoints
finalNumberOfPoints =

   203


totalNumberOfPoints =

   852

Generate Design for Parked Cam Phasers

Make another design for some points with parked cam phasers. These points are important because you need an accurate model when cams are parked.

parkedCamsDesign = sfDesign.CreateDesign( 'Name', 'Parked' );
parkedCamsDesign = ConstrainedGenerate( parkedCamsDesign, 10, 'UnconstrainedSize', 40, 'MaxIter',10  );

% Explicitly set ECP and ICP to 0 - this changes the 'Type' to 'Custom'
designTypeBefore = parkedCamsDesign.Type
parkedCamsDesign.Points(:,3:4) = 0;
designTypeAfter = parkedCamsDesign.Type
% Merge with first design to create a new design
mainDesign = Merge( sfDesign, parkedCamsDesign );
mainDesign.Name = 'Main Design';
designTypeBefore =

Latin Hypercube Sampling


designTypeAfter =

Custom

Plot Design Points

Scatter2D is a method of mbcdoe.design.

designPoints = mainDesign.Points;
inputs = mainDesign.Inputs;
subplot(2,1,1)
Scatter2D( mainDesign, 1, 2 );
subplot(2,1,2)
Scatter2D( mainDesign, 3, 4 );

Add the Designs to the Test Plan

Testplans have a Design property that is a cell array (one cell for each stage). Here you add the designs to the 2nd stage.

TP.Design{2} = [sfDesign parkedCamsDesign mainDesign];
get(TP)
                Name: 'Two-Stage'
             Project: [1x1 mbcmodel.project]
                Data: []
              Levels: 2
              Inputs: {[1x1 mbcmodel.modelinput]  [4x1 mbcmodel.modelinput]}
    InputSignalNames: {5x1 cell}
      InputsPerLevel: [1 4]
       DefaultModels: {[1x1 mbcmodel.localmodel]  [1x1 mbcmodel.linearmodel]}
             Designs: {[1x0 mbcdoe.design]  [1x3 mbcdoe.design]}
          BestDesign: {[]  []}
           Responses: [0x1 double]
            Boundary: []

Set the BestDesign

Testplans also have a BestDesign property (also a cell array). Set the Best Design for the 2nd stage.

TP.BestDesign{2} = mainDesign
 
TP = 
mbcmodel.testplan: Two-Stage
   Stages:2
   Dataset: <none> 
   Validation Data: <none>
   Design: Main Design
   Boundary Model: <none>
   
 

Create Validation Design

Make another space-filling design for collecting validation data.

validationDesign = sfDesign.CreateDesign( 'Name', 'Validation' );
validationDesign = ConstrainedGenerate( validationDesign, 25, 'UnconstrainedSize', 100, 'MaxIter',10  );

% Add the parked cams point.
validationDesign.Points(end+1,:) = [3500 0.5 0 0];
% Add this to testplan as well - when you add one design only, using
% AddDesign is more convenient. By default this adds the design to 2nd
% stage.
% Note: alternatively, you could add the design to TP.Design{2} directly.
TP.AddDesign(validationDesign);
% The list of designs for the 2nd stage
allDesigns = TP.Design{2}
allDesigns = 

  1x4 design array with properties:

    Style
    Type
    NumberOfPoints
    NumberOfInputs
    Name
    Points
    PointTypes
    Inputs
    Generator
    Constraints
    Model