UQWorld

Using Parameters in MODEL Objects

Someone recently asked how to bring additional arguments to a MODEL object evaluated using uq_evalModel. The computational model under evaluation is a MATLAB ODE and these arguments were used to modify the call to the solver (incl., changing the solver itself). These arguments were, strictly speaking, not the input variables of the model.

This is a nice opportunity to revisit the Parameters property of the UQLab MODEL object[1].

Parameters in MODEL object revisited

Parameters is a documented feature in the MODEL module user manual (see Section 2.1.4, Advanced Parameter Options). The example used in the manual is to pass additional numerical arguments to the computational model outside the so-called input variables (which are, in the context of UQ, modeled probabilistically). For instance, in the Ishigami function:

f(\mathbf{x}) = \sin{x_1} + a \sin^2{x_2} + b x_3^4 \sin{x_1}

\mathbf{x} is the input variables and a and b are the parameters of the model. To create a parametrized version of the Ishigami function in UQLab, specify the Parameters configuration option of the default MODEL object:

f = @(X, P) 'sin(X(:,1)) + P.a * (sin(X(:,2))ˆ2) + P.b * (X(:,3)ˆ4) * sin(X(:,1))'; 
ModelOpts.mHandle = f;
ModelOpts.Parameters.a = 7;
ModelOpts.Parameters.b = 0.1;
myModel = uq_createModel(ModelOpts);

when uq_evalModel is called, the Parameters struct is also passed to the model.

As a reminder, UQLab connects with an arbitrary MATLAB function having the following signature:

function [Y1,...,Ym] = myWrapper(X,Parameters)

To change the value of the parameters after the MODEL is created, directly change the value of Parameters property of myModel:

myModel.Parameters.a = 10;
myModel.Parameters.b = 0.5;

In the next call to uq_evalModel, the new values for the parameters are used.

And, as mentioned in the User Manual, Parameters is a struct and allowed to contain arbitrary fields with different values and types.

Back to the question

The questioner[2] asked if they could use different solvers in an ODE model wrapped as a UQLab MODEL without creating new models. The questioner thought of (adamantly themselves) using global; this is not necessary[3] as we can use Parameters instead.

For the sake of illustration, let’s use the vpd1 function (Van Der Pol ODE for mu = 1 shipped with MATLAB) as our underlying computational model modified such that it accepts one additional input (mu).

function dydt = vdpX(t, y, X)
...
dydt = [y(2); X*(1-y(1)^2)*y(2)-y(1)];
...
end

This ODE is further wrapped by the call to a solver that should accept additional parameters related to that solver. To facilitate passing parameters into such model, we can define our wrapper for UQLab as follows:

function Y = solve_vdpX(X,P)

solver = P.Solver;      % Selected solver
ts = P.ts;              % Time interval
y0 = P.y0;              % Initial condition
options = P.Options;    % Other arguments passed to the ODE solver

[~,Y] = solver(@(t,y) vdpX(t, y, X), ts, y0, options);

Y = min(min(Y));  % Grab a scalar value (illustration purpose)

end

A MODEL object can be then defined as follows:

ModelOpts.mFile = 'solve_vdpX';
ModelOpts.Parameters.Solver = @ode15s;
ModelOpts.Parameters.ts = [0 3000];
ModelOpts.Parameters.y0 = [2 0];
ModelOpts.Parameters.Options = {};
ModelOpts.isVectorized = false;

myModel = uq_createModel(ModelOpts);

ODE solvers in MATLAB are implemented as functions and functions can be passed around as handles, including to Parameters. After the object is created, the parameters can be adjusted to, for instance, use a different solver and add additional options (say, the tolerance) to the solver:

myModel.Parameters.Solver = @ode23s;
myModel.Parameters.Options = {'Reltol', 1e-13, 'AbsTol', 1e-14};

Summary

In this example, parameters are used to specify the ODE) solver as well as all additional arguments in the call to the solver (time interval, initial condition, etc.) inside a computational model.

As illustrated above, the Parameters configuration option and property (after creation) of the MODEL object can indeed contain an arbitrary number of fields, each of which contains arbitrary values and types (incl. function handles). It is your choice within the wrapper function how to use such parameters.

Have you ever used parameters in a UQLab MODEL? I’d be glad to know your use case!


  1. specifically, of the default type ↩︎

  2. or is it asker? ↩︎

  3. and possibly a no-good practice anyhow ↩︎

3 Likes