## Generate Parameter Samples for Sensitivity Analysis

This topic shows how to generate parameter samples for sensitivity analysis.

You can perform global sensitivity analysis using Simulink® Design Optimization™ software. Using techniques such as design of experiments (DOE) (also referred to as experimental design), you can choose a parameter set for sensitivity analysis.

You generate parameter samples by varying the value of the Simulink model parameters and states of interest according to a specified probability distribution. These parameters and states are collectively referred to as parameters. Each combination of generated parameter values is referred to as a sample or sample point. A collection of samples is referred to as a design space, sample space, or parameter set.

After generating a parameter set, you define a cost function by creating design requirements on the model signals. You then evaluate the cost function for each sample in the parameter set. Then, you analyze the relation between the parameters and requirement to understand how the parameters influence the cost function.

You can generate two kinds of parameter values: random parameter values or gridded parameter values.

### Generate Random Parameter Values

When generating random parameter values, you specify the following characteristics of the parameter space:

You can specify the characteristics of the parameter space either in the Sensitivity Analyzer or at the command line.

#### Number of Samples

Choose enough samples to yield useful results. However, each model evaluation has a computational expense and can be time intensive. As the number of parameters increases, the number of samples required to explore the design space generally increases. For correlation or regression analysis, consider using 10Np samples, where Np is the number of parameters.

#### Sampling Method

Specify the method used to generate the samples. You can choose from the following methods:

• Random — Random samples are drawn from the probability distributions specified for the parameters.

If you specify correlation between parameters, the software uses the Iman-Conover algorithm to impose the parameter correlations.

• Latin hypercube— Latin hypercube samples are drawn from the probability distributions specified for the parameters. Use this option for a more systematic space-filling approach than random sampling. The Sobol and Halton quasirandom sampling methods are more space-filling than the Latin hypercube method.

If you specify correlation between parameters, the software uses the Iman-Conover algorithm to impose the parameter correlations.

• Sobol — Requires Statistics and Machine Learning Toolbox™ software. Sobol quasirandom sequences are drawn from the probability distributions specified for the parameters. Use this method for highly systematic space-filling.

The figure shows 20 samples for two parameters. The samples are generated from a uniform distribution, in the interval from 0 to 1. Random sampling can result in large gaps between some samples, and close clustering of other samples. Sobol and Halton quasirandom sampling methods avoid gaps and clustering of samples. If you have many parameters in your parameter set, Sobol sets gives more systematic space filling than Halton quasirandom sets. For more information, see Generating Quasi-Random Numbers (Statistics and Machine Learning Toolbox).

If you specify correlation between parameters, the software uses the Iman-Conover algorithm to impose the parameter correlations.

• Halton — Requires Statistics and Machine Learning Toolbox software. Halton quasirandom sequences are drawn from the probability distributions specified for the parameters. Like the Sobol method, you can use Halton method for highly systematic space-filling. However, Sobol method gives more systematic space filling if you have many parameters in your parameter set. For more information, see Generating Quasi-Random Numbers (Statistics and Machine Learning Toolbox).

If you specify correlation between parameters, the software uses the Iman-Conover algorithm to impose the parameter correlations.

• Copula— Requires Statistics and Machine Learning Toolbox software. Random samples are drawn from a copula. Use this option to impose correlations between the parameters using copulas.

You can use either a Gaussian copula (default) or a t copula. Use t copulas when the probability of extreme parameter values is not negligible (distribution is heavy-tailed), and specify the degrees of freedom. As you increase the degrees of freedom, the t copula converges to the Gaussian copula, and the probability of extreme parameter values becomes negligible. The following figure shows 1000 samples drawn for two parameters in the interval from 0 to 1 using the Gaussian and t copulas.

In comparison to the Gaussian copula, the t copula has more samples that represent the extreme values of the parameters. As the degrees of freedom are increased, the t copula converges to the Gaussian copula.

Specify the correlation type as either Spearman’s rank correlation or Kendall’s rank correlation.

#### Probability Distribution

Specify the probability distribution function and related distribution characteristics for each parameter. Use your knowledge of the system (empirical or theoretical) to choose the probability distributions.

Note

Simulink Design Optimization software allows you to specify uniform (default), normal, multinomial, piecewise linear, and triangular distributions. For other distributions, you need Statistics and Machine Learning Toolbox software.

Consider the following characteristics of your parameters when choosing a distribution:

Parameter CharacteristicsApplicable Distributions

Extends from -$\infty$ to $\infty$

• Normal

• Extreme value

• Generalized extreme value — Single-ended or from -$\infty$ to $\infty$, depending on distributional parameter values.

• Logistic — heavy tailed compared to normal distribution.

• t location-scale — heavy tailed compared to normal distribution.

Bounded at both ends

• Uniform

• Beta

• Binomial — discrete distribution

• Multinomial— discrete distribution

• Piecewise linear

• Triangular

Extends from 0 to $\infty$

• Birnbaum-Saunders

• Burr

• Exponential

• Gamma

• Generalized extreme value — Single-ended or from -$\infty$ to $\infty$, depending on parameter values.

• Inverse Gaussian

• Log-logistic

• Log-normal

• Nakagami

• Negative binomial— discrete distribution

• Poisson— discrete distribution

• Rayleigh

• Rician

• Weibull

Custom distribution

Piecewise linear

#### Parameter Correlations

Specify the correlation between parameters. The algorithm used to impose the parameter correlations depends on the sampling method. For more information, see Sampling Method.

#### Generate Random Parameter Values in the App

In the Sensitivity Analyzer, after you have selected the parameters in the parameter set, click Generate Values and, select Generate Random Values.

In the Generate Random Parameter Values dialog box, specify the number of samples, probability distributions, parameter bounds and correlations, and sampling method. For information about how to specify the fields in the dialog box, click Help.

The generated parameter set and the corresponding parameter set table are displayed in the app. The number of rows in the parameter set table correspond to the number of samples you specified.

After generating the parameter values, plot them to check if generated parameter values match the intended specifications. This is relevant if you generate a small number of random samples for each parameter set. For more information, see Inspect the Generated Parameter Set.

For an example, see Identify Key Parameters for Estimation (GUI).

This functionality is not supported in Simulink Online™.

#### Generate Random Parameter Values at the Command Line

At the command line, use `sdo.ParameterSpace` to define the parameter space. This object specifies the probability distributions and correlations for the parameters. Use this object as an input to `sdo.sample` for generating parameter values from the specified parameter space.

To generate the random parameter values:

• Specify the number of samples as the second input argument of `sdo.sample`.

• Specify the method used to generate these samples using the `Method` property of an `sdo.SampleOptions` object. Use this object as an input to `sdo.sample` to specify the sampling options.

If the method chosen is `'sobol'` or `'halton'`, specify the `MethodOptions` property of `sdo.SampleOptions`.

If the method chosen is `'copula'`, specify the choice of copula using the `MethodOptions` property of `sdo.SampleOptions`. Also specify the `RankCorrelation` property of the `sdo.ParameterSpace` object.

• Specify the probability distribution of a parameter using the `ParameterDistributions` property of an `sdo.ParameterSpace` object.

• Specify correlation between parameters, using the `RankCorrelation` property of the `sdo.ParameterSpace`.

After generating the parameter values, plot the generated values to check if they match the desired specifications. This is relevant if you generate a small number of random samples for each parameter set. For more information, see Inspect the Generated Parameter Set.

For an example, see Identify Key Parameters for Estimation (Code).

#### Generate Custom Parameter Values at the Command Line

This example shows how to generate random parameter values with a custom distribution when performing sensitivity analysis at the command line. Generate a 1000 samples of a model parameter, `R`, in the 5% range of its nominal value, 10. `R` is a resistor. Resistors of 1% tolerance are removed by the manufacturer, so do not generate `R` values in the 1% range of its nominal value.

1. Construct a `param.Continuous` object.

`R = param.Continuous('R',10);`
2. Create a customized probability distribution, `pdR`, to configure the parameter space.

```x = [0.95 0.99 1.01 1.05]*R.Value; F = [0 0.5 0.5 1]; pdR = makedist('PiecewiseLinear','x',x,'Fx',F); x = linspace(0.9*R.Value,1.1*R.Value,1e3); plot(x,pdf(pdR,x)); ```

`makedist` specifies a piecewise linear distribution for the resistor value, with a “hole” in the 1% range.

3. Specify `pdR` as the probability distribution for the `R` parameter in an `sdo.ParameterSpace` object.

`ps = sdo.ParameterSpace(R,pdR);`
4. Generate 1000 samples.

```Ns = 1000; x = sdo.sample(ps,Ns);```
5. (Optional) Use `sdo.scatterPlot` to visualize the samples and validate the sample space.

### Generate Gridded Parameter Values

You can generate gridded parameter values in the Sensitivity Analyzer or at the command line.

#### Generate Gridded Parameter Values in the Sensitivity Analyzer

You can generate gridded parameters in the app after you have created a parameter set.

1. Create a parameter set.

In the Sensitivity Analyzer, in the Sensitivity Analysis tab, click Select Parameters.

In the Select Parameters dialog box, select all the parameters you want to include in your parameter set, and click OK.

A `ParamSet` variable is created in the Parameter Sets area of the app. The current value for each parameter in the parameter set is displayed in a table.

2. Specify the starting parameter values and gridding method for grid generation.

In the Sensitivity Analysis tab, click Generate Values, and select Generate Gridded Values from the drop-down menu.

In the Generate Gridded Parameter Values dialog box, specify the gridding method as All Combinations. The app generates all possible combinations of the values specified in Values.

Specify the starting parameter values in Values. The values you enter here determine the parameter space. To see the other ways to specify starting parameter values and gridding methods, click Help.

3. Generate the parameters.

Click Overwrite. The parameter set table updates with the generated gridded parameter values.

You can also append the generated values to previously generated random or gridded parameter values in the parameter set table. To do so, click Append.

4. (Optional) Plot the generated values.

In the Parameter Sets area of the app, select ParamSet. In the Plots tab of the app, select Scatter Plot from the plots gallery.

Plots are generated with histograms of the distribution of the parameter values shown on the diagonals. The off-diagonal plots display the scatter plots between pairs of parameters. To learn more about the plots, see Interact with Plots in the Sensitivity Analyzer.

This functionality is not supported in Simulink Online.

#### Generate Gridded Parameter Values at the Command Line

This example shows how to create a table of gridded parameter values at the command line.

Generate a grid of samples for two model parameters, `A` and `B`. Vary `A` between `[2,3,4]` and `B` between `[20,30,40]`.

1. Construct a `param.Continuous` object.

```A = param.Continuous('A',1); B = param.Continuous('B',10);```
2. Specify the parameter values for grid generation.

```Avals = [2 3 4]; Bvals = [20 30 40];```
3. Create a table of gridded parameter values. Specify one column for each parameter, and one row for each sample. The column names must be the same as the parameter names.

```[Agrid,Bgrid] = meshgrid(Avals,Bvals); x = table(Agrid(:),Bgrid(:),'VariableNames',{'A','B'});```
```x = A B _ __ 2 20 2 30 2 40 3 20 3 30 3 40 4 20 4 30 4 40```