Evaluating a Surrogate Model
This example demonstrates how to evaluate a trained surrogate model. NearestPointSurrogate is used as the example surrogate model. See Creating a surrogate model for details on how this surrogate is created. See Training a surrogate model for details on how to train a surrogate model.
Overview
In general, a SurrogateModel object takes in training data in the form of .rd
files or the name of the training object itself. The former performs training and evaluating in two separate steps, the latter performs them both in a single step. Since most practical applications perform training once and evaluation in multiple instances, this example focuses on the two step method. Every SurrogateModel object has a public member function, evaluate
, that gives the surrogate's estimate to a quantity of interest with the parameters as input. Some specialized surrogates, like PolynomialChaos, have more functions for computing statistics. However, this example will focus on the simple NearestPointSurrogate, which only uses the evaluate
function.
Model Problem
This example uses a one-dimensional heat conduction problem as the full-order model which has certain uncertain parameters. The model equation is as follows:
The quantities of interest are the average and maximum temperature:
Parameter Uncertainty
For demonstration, each of these parameters will have two types of probability distributions: Uniform () and Normal (). Where and are the max and minimum bounds of the uniform distribution, respectively. And and are the mean and standard deviation of the normal distribution, respectively.
The uncertain parameters for this model problem are:
Parameter | Symbol | Uniform | Normal |
---|---|---|---|
Conductivity | |||
Volumetric Heat Source | |||
Domain Size | |||
Right Boundary Temperature |
Analytical Solutions
This simple model problem has analytical descriptions for the field temperature, average temperature, and maximum temperature:
With the quadratic feature of the field temperature, using quadratic elements in the discretization will actually yield the exact solution.
Input File
Below is the input file used to solve the one-dimensional heat conduction model.
(contrib/moose/modules/stochastic_tools/examples/surrogates/sub.i)With this input the uncertain parameters are defined as:
Materials/conductivity/prop_values
Kernels/source/value
Mesh/xmax
BCs/right/value
These values in the sub.i
file are arbitrary since the stochastic master app will be modifying them.
Evaluation
This section shows how to set up an input file to load and evaluate a surrogate model. The training data was created with the steps from Training a surrogate model. To demonstrate the usefulness of a surrogate model, the model will be evaluated using Monte Carlo sampling with parameter distributions described in the previous section. The results of this sampling will be used to compute statistical moments and produce probability distributions.
Omitting Solve
Any input file in MOOSE needs to include a Mesh, Variables, and Executioner block. However, the stochastic master app does not actually create or solve a system. So the StochasticToolsAction builds a minimal model to satisfy these requirements:
(contrib/moose/modules/stochastic_tools/examples/surrogates/nearest_point_uniform.i)Surrogate Model
The surrogate model is loaded by inputting the training data file with the "filename" parameter. In this example, two surrogates are loaded with two different training data files for average temperature and maximum temperature.
(contrib/moose/modules/stochastic_tools/examples/surrogates/nearest_point_uniform.i)Defining a Sampler
In this example, the surrogate is evaluated at points given by a sampler. Here we use the MonteCarloSampler to generate random points defined by a Uniform or a Normal distribution for each parameter. See Example 1: Monte Carlo for more details on setting up this sampler.
Uniform distribution for each parameter
(contrib/moose/modules/stochastic_tools/examples/surrogates/nearest_point_uniform.i)Normal distribution for each parameter
(contrib/moose/modules/stochastic_tools/examples/surrogates/nearest_point_normal.i)Sampling Surrogate
Evaluating a surrogate model occurs within objects that obtain the surrogate object's reference and call the evaluate
function. In this example, we will use EvaluateSurrogate to evaluate the surrogate. EvaluateSurrogate takes in a sampler and the surrogate model as inputs, and evaluates the surrogate at the points given by the sampler.
The results of evaluating the surrogate can then be used to compute statistics like mean and standard deviation:
(contrib/moose/modules/stochastic_tools/examples/surrogates/nearest_point_uniform.i)Results
The results of the of inputs from the previous sections produce csv files of the evaluation data. These files can then be used to produce probability distributions like in Figure 1 and Figure 2. Even for this simple model problem, evaluating the surrogate was orders of magnitude faster with significantly less memory consumption.
Figure 1: Temperature distributions with uniform parameter distribution
Figure 2: Temperature distributions with normal parameter distribution