Since R2023a
If your model contains some parameters you want to sample across a grid and others from which you want to draw random samples, you can combine gridded and random parameter spaces.
This example uses the sdoCSTR
model discussed in detail in Design Exploration Using Parameter Sampling (Code). Open the model.
Among the parameters in this model are the reactor cylinder area A
, height h
, and the feed temperature and concentration, FeedCon0
and FeedTemp0
. Suppose that you want to explore the sensitivity of your design constraint to these four parameters, sampling across a grid of A
and h
values while drawing FeedCon0
and FeedTemp0
from random distributions.
First, define a gridded parameter space for A
and h
. Use sdo.getParameterFromModel
to create an array of param.Continuous
objects representing A
and h
. Then, specify values for the grid, and create the parameter space.
Next, define a random parameter space for FeedCon0
and FeedTemp0
. Create an array of param.Continuous
objects and specify the probability distributions for each parameter. For this example, assign both variables a normal distribution where the mean is the current parameter value in the model and the variance is 5% of the mean. Then, create the parameter space.
Finally, combine the two parameter spaces into a new parameter space.
cspace =
GriddedSpace with properties:
ParameterValues: {{1x5 cell} {1x3 cell} [1x1 prob.NormalDistribution] [1x1 prob.NormalDistribution]}
Notes: []
Spaces: {[1x1 sdo.GriddedSpace] [1x1 sdo.ParameterSpace]}
ParameterNames: {'A' 'h' 'FeedCon0' 'FeedTemp0'}
Options: [1x1 sdo.GriddingOptions]
The combined space is represented by a sdo.GriddedSpace
object. The property cspace.Spaces
shows that cspace
contains the two subspaces, one gridded space and one random parameter space. The property cspace.ParameterValues
shows that the space includes the finite grid for A
and H
, and the probability distributions for the random variables FeedCon0
and FeedTemp0
.
You can now use sdo.sample
to draw sets of sampled values from the combined space. By default, the samples are exhaustive over the grid, meaning every possible combination of grid values is included in the sampled set. Suppose that for each combination, you want to sample the random parameters ten times. Provide that value to sdo.sample
in the NumSample
argument.
evalues=150×4 table
A h FeedCon0 FeedTemp0
___ ___ ________ _________
0.2 0.5 10.269 275.09
0.6 0.5 10.269 275.09
1 0.5 10.269 275.09
1.4 0.5 10.269 275.09
1.8 0.5 10.269 275.09
0.2 1.5 10.269 275.09
0.6 1.5 10.269 275.09
1 1.5 10.269 275.09
1.4 1.5 10.269 275.09
1.8 1.5 10.269 275.09
0.2 2.5 10.269 275.09
0.6 2.5 10.269 275.09
1 2.5 10.269 275.09
1.4 2.5 10.269 275.09
1.8 2.5 10.269 275.09
0.2 0.5 10.917 339.77
⋮
Here, for each of the fifteen combinations of (A
, h
) values, sdo.sample
assigns ten random values for (Feedcon0
, FeedTemp0
), resulting in 150 sets of (A
, h
, FeedCon0
, FeedTemp0
) samples.
You can also have sdo.sample
choose only one random (FeedCon0
,FeedTemp0
) value for each (A
,h
) pair. To do so, set the sampling method of cspace
to sequential. Note that in this case, you created cspace
using a gridded space gspace
that had gspace.Options.Method = 'exhaustive'
. Thus, when you sample cspace
, the (A
,h
) pairs are still exhaustive.
svalues=15×4 table
A h FeedCon0 FeedTemp0
___ ___ ________ _________
0.2 0.5 9.5682 296.27
0.6 0.5 10.039 273
1 0.5 9.3929 284.05
1.4 0.5 9.4432 279.34
1.8 0.5 9.9966 329.67
0.2 1.5 10.766 285.92
0.6 1.5 9.6152 306.03
1 1.5 10.186 292.16
1.4 1.5 9.8872 308.11
1.8 1.5 10.559 283.72
0.2 2.5 9.4555 274.32
0.6 2.5 10.016 274.02
1 2.5 10.276 302.2
1.4 2.5 10.55 292.38
1.8 2.5 10.772 292.11
Use values
with sdo.evalute
to evaluate your design objectives at each of the sampled parameter values. For instance, if you have defined a cost function design
, you can use values
in a call to sdo.evluate
as follows.
[yR,infoR] = sdo.evaluate(@design,p,values);