Difference between revisions of "Using a model"

From SUMOwiki
Jump to navigationJump to search
Line 9: Line 9:
 
* outputNumber: optional parameter, an integer specifying which output to plot
 
* 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.
 
* 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.
 +
  
 
<code> >> values = evaluate(model, samples);</code>
 
<code> >> values = evaluate(model, samples);</code>
  
 
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 [[Data_format|simulator configuration]]. If no range (minimum and maximum) is defined, the domain is assumed to be [-1,1].
 
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 [[Data_format|simulator configuration]]. If no range (minimum and maximum) is defined, the domain is assumed to be [-1,1].
 +
  
 
<code> >> values = evaluateInModelspace(model, samples);</code>
 
<code> >> values = evaluateInModelspace(model, samples);</code>
Line 21: Line 23:
 
<code> >> samples = getSamples(model);</code>
 
<code> >> samples = getSamples(model);</code>
  
Returns the samples that were used to fit the model
+
Returns the samples that were used to fit the model. The samples are returned in simulator space.
 +
 
  
 
<code> >> values = getValues(model);</code>
 
<code> >> values = getValues(model);</code>
  
Returns the values that correspond to the samples from getSamples()
+
Returns the values that correspond to the samples from getSamples().
 +
 
  
 
<code> >> desc = getDescription(model);</code>
 
<code> >> desc = getDescription(model);</code>
  
 
Returns a string with a user friendly description of the model.
 
Returns a string with a user friendly description of the model.
 +
  
 
<code> >> desc = getExpression(model,[outputNumber]);</code>
 
<code> >> desc = getExpression(model,[outputNumber]);</code>
  
 
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).
 
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).
 +
  
 
<code> >> n = freeParams(model);</code>
 
<code> >> n = freeParams(model);</code>
  
Returns the number of free parameters in the model
+
Returns the number of free parameters in the model.
 +
 
  
 
<code> >> fields(model);</code>
 
<code> >> fields(model);</code>
  
Returns all fields the object has
+
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.
 
Other methods differ per model type.  Inspect the corresponding model directory and constructor to see what methods and options are available.

Revision as of 14:26, 1 February 2008

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. The samples are returned in simulator space.


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