Add Model Type

From SUMOwiki
Revision as of 15:35, 10 May 2007 by Dgorissen (talk | contribs)
Jump to navigationJump to search

The M3-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.

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: LSSVMInterface) for examples.

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

  • 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. As a parameter it should take an instance of MyModelInterface which contains all the model parameters, their default values, etc.
    • 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.
    • evaluate: given a number of samples, 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)

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.