Difference between revisions of "Add Model Type"

From SUMOwiki
(Adding a model factory)
(Adding a model factory)
Line 31: Line 31:
 
* createModel
 
* createModel
 
* createInitialModels
 
* createInitialModels
  +
* getBounds
   
 
Already with those two methods your model type will be able to work with most model builders.
 
Already with those two methods your model type will be able to work with most model builders.

Revision as of 18:13, 8 February 2009

Introduction

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 continue please ensure you are familiar with Object Oriented Programming in Matlab.

Models, Model builders, and Factories

It is very important to first grasp the difference between Model builders, Model Factories and Models. Remember that each model type as a set of parameters that control the complexity of the model. For example a polynomial model has a degree parameter, an SVM has a kernel function, Kriging has theta parameters, etc. In order to generate a good model you need to search for a good set of model parameters (with respect to a Measure). In essence this is an optimization problem in model parameter space (= hyperparameter space).

So a Model is just the model itself with a particular model parameter assignment. This is where the difficulty usually lies. Setting good values for the model parameters requires finding the right balance between the bias/variance tradeoff and in many cases this is more of an art than a science. Finding the best model parameters given the data can be seen as a (constrained) optimization problem over the parameter space. This is where the Model Builder comes in. A Model Builder is the implementation of an optimization algorithm (pattern search, GA, simulated annealing, NSGA-II,...) that can be used to optimize the model parameters. For information on how to add a new Model Builder see Add a Model Builder.

Factories, then are in between the two. A Model Factory object sits in between the Model Builder and the model and is responsible for reading the configuration options and creating basic model objects according to the demands of the Model Builder. So each Model Builder will contain a Model Factory (as you can see from the XML configuration). For example, a GeneticModelBuilder can contain an ANNFactory. The GeneticModelBuilder will run a GA and ask the ANNFactory object to generate an ANNModel object representing a particular individual in the population. This may all seem pretty abstract, but it is really quite simple. Walk through the SplineFactory and SplineModel objects for a simple example.

Adding a model type

So first you must provide the implementation of the model itself. This requires subclassing from the base class Model and overriding its abstract methods. You may override any of the other public (non final) methods if you wish. For example you will probably want to override 'constructInModelSpace' since that method takes care of actually training the model on a given set of data. Again, you can use the SplineModel class as a simple example to follow.

Before you start remember this: 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. The toolbox will take of converting between model space and simulator space so you typically only have to worry about the xxxxInModelSpace methods.

Also remember that your model should always contain a no-argument constructor (ie, it should be constructable without any arguments).

For a list of methods available to a Model see Using a model.

Adding a model factory

Now that you have a model type you have to add a ModelFactory. In this case you must Subclass from BasicFactory. If you want to support the GeneticModelBuilder with a custom population type (ie, like ANNFActory does) you must subclass from GeneticFactory.

Again you simply have to provide an implementation for the abstract methods which should be pretty self-explanatory. Typically the methods you would want to implement are:

  • createModel
  • createInitialModels
  • getBounds

Already with those two methods your model type will be able to work with most model builders.

You then just have to make sure your constructor reads the options set in the configuration file (you choose your own options and toolbox will take care you only get the options belonging to you). The SplineFactory can serve as an example.

Having created your Factory you can now add an XML tag to the toolbox configuration file and you should be able to use your model type with any ModelBuilder. Thus you should be good to go :)