Add Model Type

From SUMOwiki
Revision as of 11:57, 1 February 2008 by Kcrombec (talk | contribs)
Jump to navigationJump to search

The SUMO-Toolbox provides a number of built-in model types (Rational Functions, Support Vector Machines, ...) that already cover a wide range of problem types. However, you may have existing modeling code that you would like to plug into the toolbox since it is more suited to your particular problem. The toolbox tries to make this as easy as possible.

Before you add a new model, you should remember the following. Internally, the toolbox always works on the [-1,1] domain. Even when another range is defined in the simulator configuration, the models (and all other components of the toolbox) still function on the [-1,1] domain. This is called "model space", as opposed to "simulator space", which can have any range. If you are implementing a modeller, you can therefore assume that all samples that are used for training lie in the [-1,1] range and you can optimize your code accordingly.

There are two steps to adding a new model type (e.g., regression trees).

  • First you need to provide an "MyModelInterface" class in src/matlab/interfaces. It is this class that defines what configuration options your model type has. All you have to do is provide a constructor file ("MyModelInterface.m") that reads out the configuration objects passed to it and uses that info to instantiate a new model class. The configuration objects are built from the config specified in the XML file. See one of the other interface classes (eg: SplineInterface) for examples.

This is also the class that you will subclass to accommodate for different modeling algorithms, i.e., you might have a GeneticMyModelInterface as well.

  • Secondly: The base class for all model types is the Matlab class Model and can be found in the src/matlab/models subdirectory. Writing your own model class requires sub-classing Model and overriding the following member functions (look at the source of the other model types to get an idea how its done):
    • constructor: a "MyModel.m" constructor class that creates an object of your model type. You can choose what to use as parameters, but make sure the model can also be instantiated without any parameters (default constructor).
    • construct: given a number of samples and values you need to train your model on this data, e.g., for polynomials this is solving a least squares system, for a neural net this is training the network on the data. Here you can call any native or external codes as you please.
    • evaluateInModelSpace: given a number of samples (in model space), evaluate the model on these samples and return the values. This may also be a call to some external library.
    • freeParams: return the number of parameters in the model (eg: the number of coefficients in a polynomial model)

For a full overview of the functions you can override see Using a model.

Once you have managed these two steps the toolbox knows about your model type but can not use it yet since it does not know how to set the model parameters. For this you need to implement one or more of the modeling algorithms.