Using a model

From SUMOwiki
Revision as of 12:00, 1 February 2008 by Kcrombec (talk | contribs)
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. The samples should be provided in simulator space. Simulator space is defined by the range in the simulator configuration. If no range (minimum and maximum) is defined, the domain is assumed to be [-1,1].

>> values = evaluateInModelspace(model, samples);

This evaluates the model on the given samples. The samples should lie in the [-1,1] range (model space).


>> 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 );