Use a Surrogate Model Training study node (
![](images/comsol_ref_solver.34.009.01.png)
) to add functionality for training a
surrogate model. A surrogate model is a simpler and computationally cheaper model, which you can use to approximate the behavior of a more complex and computationally expensive model (the full finite element model). In COMSOL apps, for example, faster model evaluation using the surrogate model provides users of the apps with a more interactive user experience. You create surrogate models by training a
deep neural network (DNN), for example. The surrogate model training is typically based on output data from a large parametric sweep of the model for which you want to create a surrogate model. The training of a surrogate model needs a number of inputs and outputs, where the outputs are considered as functions of the inputs, which replace the full finite element solution. A large number of data points are needed in order to fully describe how the inputs map to the outputs. The outputs can be captured using domain point probes, for example.
To add an Surrogate Model Training study, right-click a
Study node and choose
Surrogate Model Training. You can only have one
Surrogate Model Training node in each study.
Click the Compute button (
![](images/comsol_ref_solver.34.009.03.png)
) to initiate the surrogate model training and create a surrogate model.
If you choose Show Default Solver from the
Study node, the
Surrogate Model Training study generates and sets up a
Design Of Experiments job and its subsequence node (see the
Uncertainty Quantification Module User’s Guide). The
Design Of Experiments job is controlled by and synchronized to the
Surrogate Model Training study. If you click
Compute from the
Study node, the
Surrogate Model Training study identifies and runs its
Design Of Experiments job if it exists; else it first creates a
Design Of Experiments job.
The Settings window for the
Surrogate Model Training study include the following sections:
From the Compute actions list, choose one of the following options:
Compute and build surrogate model (the default) or
Improve and build surrogate model.
Compute and build surrogate model will discard data from the previous run (if the same table is used) or start a new run using a new table.
Improve and build surrogate model will add more data to an existing table, which can be useful if you realize after having examined the trained SM function that it does not seem accurate enough. The
Surrogate Model Training study outputs training data tables and trained surrogate models for each quantity of interest. If you choose
Design of experiments (No surrogate model) for the surrogate model in the
Surrogate model list below, a training data table will be the only result.
From the Solution to use list, choose
Automatic (the default),
Summation,
Minimum,
Maximum,
Use first, or
Use last. The
Automatic solution to use will be the last solution for time-dependent and parametric solutions, while for eigenvalue and eigenfrequency solutions, it will be the first solution. You can override this mechanism by selecting any of the other methods. For
Summation, the quantity of interest (QoI) is defined as the summation of the
Expression over all the solutions. For
Maximum (or
Minimum), the QoI is defined as the maximum (or minimum) of the expression taken over all the solutions. Also note that evaluation operators like
at() and
with() can be used in the expression, making it possible to evaluate even more general quantities from dynamic solutions.
From the Surrogate model list, choose
None (Design of Experiments) (the default) to use a DOE model, or choose
Gaussian process,
Polynomial chaos expansion, or
Deep neural network:
Gaussian process and
Polynomial chaos expansion require a license for the Uncertainty Quantification Module.
•
|
For None (Design of Experiments), also, from the Output table group list, choose New to create a new output table group or choose any existing table group. A Design of Experiments table group is created automatically.
|
•
|
For Gaussian process, also specify a covariance and a mean. From the Covariance list, choose Squared exponential, Matérn 3/2 (the default), Matérn 5/2, Neural network, or Spectral mixture. From the Mean list, choose Constant (the default), Linear, or Quadratic. Also, from the Gaussian process function list, choose New to create a new Gaussian Process function or choose any existing Gaussian Process function.
|
•
|
For Polynomial chaos expansion, also specify Automatic (the default) or Manual. If you chose Manual, specify a value in the Maximum polynomial degree field (default value: 30), which terminates the increase of order for the PCE construction. You can also specify a value in the q-norm field (default: 0.5), which determines the truncation level of the polynomial basis. Also, from the PCE function list, choose New to create a new Polynomial Chaos Expansion function or choose any existing Polynomial Chaos Expansion function.
|
•
|
For Deep neural network, under Layers, define the layers in the DNN. In the Type column, choose Dense (the default). In the Settings column the current layer, you can see its settings. You can edit the table using the buttons under the table: Use the Move Up ( ![](images/comsol_ref_solver.34.009.04.png) ), Move Down ( ![](images/comsol_ref_solver.34.009.05.png) ), and Delete ( ![](images/comsol_ref_solver.34.009.06.png) ) buttons and the fields under tables to edit the table contents. Or right-click a table cell and select Move Up, Move Down, or Delete. The Add button ( ![](images/comsol_ref_solver.34.009.07.png) ) adds a new layer to the list. Use the Clear Table button ( ![](images/comsol_ref_solver.34.009.08.png) ) to clear the entire table. Underneath the table of layers, in the Output features field, specify the number of output features, which are the neural networks (default: 1). Choosing the number of layers and nodes in a neural network is often an iterative process that involves a combination of knowledge about the specific problem and data, empirical testing, and a bit of trial and error.
|
You can also specify an activation function using the Activation list. An activation function in a DNN defines how the weighted sum of the input is transformed into an output from a node or nodes in a layer of the network. The default activation is
tanh, for a hyperbolic tangent function, which is an S-shaped function. You can also choose
Linear (none) for a linear (that is, no) activation function;
ReLU for a rectified linear unit, an activation function defined as the positive part of its argument;
ELU for an exponential linear unit; or
Sigmoid for a sigmoid function. The default activation,
tanh, is usually a good choice.
ELU and
ReLU are less smooth than the other functions, so avoid them if the trained function later needs to be differentiated. Choosing
None is only useful for the last layer.
Finally, from the DNN function list, choose
New to create a new
Deep Neural Network function or choose any existing
Deep Neural Network function.
In the table under Quantities of interest (Outputs), define the outputs from the surrogate model (quantities of interest), which could be defined as point probe expressions, for example.
In the Expression column, type the expression for the output (
comp1.ppb1, for example, for a
Point Probe Expression 1 in
Component 1). In the
Description column, type a description for the output (
Temperature, for example). In the Individual solution to use column, the default is
From "Solution to use" to use the solution specified in the
Solution to use list above. You can also choose
Automatic,
Summation,
Minimum,
Maximum,
Use first, or
Use last. Use the
Move Up (
![](images/comsol_ref_solver.34.009.09.png)
),
Move Down (
![](images/comsol_ref_solver.34.009.10.png)
), and
Delete (
![](images/comsol_ref_solver.34.009.11.png)
) buttons and the fields under tables to edit the table contents. Or right-click a table cell and select
Move Up,
Move Down, or
Delete. The
Add button (
![](images/comsol_ref_solver.34.009.12.png)
) adds a new output to the list. Use the
Clear Table button (
![](images/comsol_ref_solver.34.009.13.png)
) to clear the entire table.
For the input parameters, in the Parameters column, choose the parameter from a list of all global parameters in the model. In
Source type column, choose
Analytic (the default) or
Data.
If you chose Analytic, you can define the following properties for the selected parameter underneath the table:
•
|
In the Distribution list, choose the distribution for the input parameter: Uniform (the default), Normal(μ,σ), LogNormal(μ,σ), Gamma(k,θ), Beta(α,β), Weibull(λ,k), or Gumbel(μ,β). All distributions except the uniform distribution have two distribution parameters shown under the Distribution list, such as the Mean and Standard deviation for a normal distribution and Shape and Scale for a gamma distribution. You specify the distribution parameters in the corresponding text field. All distributions except the uniform distribution and beta distribution have CDF-Lower, CDF-Upper shown under the Distribution list.
|
•
|
In the CDF-Lower list, choose the cumulative distribution function level for your lower bound: 30%, 10%, 1%, 0.1% (the default), 1E-4, 1E-5, 1E-6, 1E-7, or Manual. These bounds automatically compute a lower bound by using the inverse cumulative distribution function.
|
•
|
In the CDF-Upper list, choose the cumulative distribution function level for your upper bound: 70%, 90%, 99%, 99.9% (the default), 1-1E-4, 1-1E-5, 1E-6, 1-1E-7, or Manual. These bounds automatically compute an upper bound by using the inverse cumulative distribution function.
|
If you chose Data in the
Source type column, you can instead specify the following properties:
•
|
From the Data source list, choose Specified values (the default), or choose Result table to take the data from the Design of Experiments results table.
|
•
|
If you chose Specified values, specify the values to use in the Specified values field. Click the Range button ( ![](images/comsol_ref_solver.34.009.14.png) ) to define a range of values.
|
•
|
If you chose Result table, specify the column to use from the Column list.
|
If the source type for the parameter is Analytic, you can add correlations groups. Doing so allows sampling of parameters that are not statistically independent by specifying a correlation matrix. You could select a subset of all input parameters in the same correlation group, and set the correlation matrix to specify the correlation between each pair of two parameters. Multiple correlation groups can be added in one study, and one parameter can only appears in one correlation group. The correlation matrix is a symmetric semidefinite matrix where all the diagonal elements equal to 1 and all the off-diagonal elements are between
[−1, 1
].
Under Input parameters sampling settings, specify the following setting if the source type is
Analytic:
•
|
From the Number of input points type list, choose Manual (the default), or choose Automatic if the Surrogate model list is set to Gaussian process or Polynomial chaos expansion.
|
•
|
If Number of input points type is set to Manual, then in the Number of input points field, if Compute action is set to Compute and build surrogate model, or Number of input points for improve, if Compute action is set to Improve and build surrogate model, specify the number of input points to use (default: 20 or 10). You may want to use a larger number to train the surrogate model to a sufficient degree of accuracy. The number of input points must be chosen empirically.
|
•
|
From the Random seed type list, choose Automatic (the default), Manual, or Current computer time. If you chose Manual, enter a seed in the Initial random seed field. The random seed affects which sampling points you get from the Latin hypercube sampling.
|
•
|
In general, use the Move Up ( ![](images/comsol_ref_solver.34.009.15.png) ), Move Down ( ![](images/comsol_ref_solver.34.009.16.png) ), and Delete ( ![](images/comsol_ref_solver.34.009.17.png) ) buttons and the fields under tables to edit the table contents. Or right-click a table cell and select Move Up, Move Down, or Delete.
|
•
|
The Add button ( ![](images/comsol_ref_solver.34.009.18.png) ) adds a new input parameter to the list.
|
•
|
Use the Clear Table button ( ![](images/comsol_ref_solver.34.009.19.png) ) to clear the entire table.
|
Select the Accumulated probe table check box to add accumulated probe tables for the result from the surrogate model training. From the
Output table list, choose
New to create a new table, or choose any existing table. The
Use all probes check box is selected by default to accumulate all the model probes in the table. If you clear this check box, the probes selected from the
Probes list are used.
From the Error handling list, choose
Stop immediately (the default) or
Skip problematic parameters.
From the Keep model evaluations in memory list, choose
Only last (the default) to only keep the last model evaluation in memory, or choose
All to keep all model evaluations.
From the Default solver sequence generation list choose
Using global parameters (the default) or
Using each parameter tuple. Use this setting to control whether a solver sequence should be generated using global parameters or each parameter tuple.
Select the Reuse the solution from the previous step check box if you want the surrogate model training algorithm to reuse the solution from the previous step. It is useful if you are using an iterative solver and the solutions for different parameter values are similar enough so that it is faster to start from the previous solution instead of starting the solver from scratch.
Select the Distribute model evaluation check box if you are running the COMSOL software on a multiprocessor system and want to distribute the model evaluation to each compute node for improved performance.
|
In order for the Distribute model evaluation check box to function, you must start COMSOL with a setup for running COMSOL on clusters or other multicore system using, for example, comsol -nn 2 -nnhost 2 on Linux ® or mpiexec -n 2 comsolcluster.exe -nnhost 2 on Windows ® to start 2 compute nodes. You can also run COMSOL with a distributed parametric sweep from the command line. See Running COMSOL in Parallel on Clusters for more information.
|
From the Surrogate model training log list, choose
Minimal,
Normal (the default), or
Detailed as desired.