Using a model

From SUMOwiki
Revision as of 15:53, 30 January 2008 by Dgorissen (talk | contribs) (New page: This page explains what you can do with a model once you have loaded it into the Matlab workspace. == Available methods == Once the model is lo...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This page explains what you can do with a model once you have loaded it into the Matlab workspace.

Available methods

Once the model is loaded you can invoke a number methods on it.

>>[figureHandle options] = plotModel(model,[outputNumber],[options])

This plots the model

  • outputNumber: optional parameter, an integer specifying which output to plot
  • options: optional parameter, a struct containing a number of options you can set. To see the list of available options, simply call plotModel with 2 output arguments and only one input argument.

>> values = evaluate(model, samples);

This evaluates the model on the given samples

>> samples = getSamples(model);

Returns the samples that were used to fit the model

>> values = getValues(model);

Returns the values that correspond to the samples from getSamples()

>> desc = getDescription(model);

Returns a string with a user friendly description of the model.

>> desc = getExpression(model,[outputNumber]);

Returns the symbolic mathematical expression of this model (e.g., 3*x1^2 - 2*x2 +5). Note that not all model types implement this (yet).

>> n = freeParams(model);

Returns the number of free parameters in the model

>> fields(model);

Returns all fields the object has

Other methods differ per model type. Inspect the corresponding model directory and constructor to see what methods and options are available.

Optimization

As a further tip, say you want to optimize the model. In this case Matlab requires a function handle to the objective function (=the model object). You can construct a function handle from the model object as follows (example for the 3D case):

handle = @(x,y,z) evaluate( model, [x,y,z] );

Afterwards, you can pass that handle to your optimization procedure, or use it through feval:

fmincon( handle, ... ); feval( handle, 0, 1, -1 );