Building models using the toolkit

Overview

A number of facilities are provided to allow easy creation of new models. These off-load most of the work involved in having tunable persistent parameters in your models and in being able to generate and parse command-line options in your executables.

To allow this, a computational model is defined as a managed collection of ModelComponent derivative objects. These objects are instantiated as a hierachical collection that varies from model to model and may also vary within one model through run-time selection of certain components or behaviors. ModelComponent provides a basic facility for building such hierarchies. In addition, it provides facilities for holding a number of ModelParam data members. These are persistent parameters, in the sense that their values can be saved to a file and later re-loaded from that file (using a ParamMap structure). ModelParam objects typically are private to a model component and the hierarchical file format used to store them ensures that no conflict between identical parameters across several components should occur. Finally, ModelComponent objects may request that some command-line option be created for some of their ModelParam members, so that the ModelParam values may be set via the command-line. Because typically those options may be shared among a variety of ModelComponents (e.g., radius of the focus of attention, or verbosity level), there is a single namespace for all the ModelParam names that may become valid command-line options (see ModelOptionDef.C). So, in order to be exportable as a command-line option, a ModelParam should have its name registered in a global list of all possible command-line options. When the command-line is parsed, all ModelParam objects with maching name will be updated to the value supplied in the command-line.

The bottom-up view

The following classes are available to implement the above functionality.

Below we walk through a typical use of these facilities to build and run a computational model that is composed of a run-rime selectable collection of ModelComponent derivatives.

The top-down view and building models

Typically, building a new model entails the following sequence of actions (for a fuller yet simple example, see test-audioGrab.C):

int main(const int argc, const char **argv)
{
ModelManager manager("My cool model");
SharedPtr<MyComponent> mycomp(new MyComponent(manager));
manager.registerComponent(mycomp);
// Note: this is optional; if you don't do this call explicitly, it
// will be made automatically (exporting ALL options) just before
// we start parsing the command line:
manager.exportOptions(OPTEXP_ALL);
mycomp->doRequestOption("MyParamName", true, true, true);
if (manager.parseCommandLine(argc, argv, "<input.ppm> <output.ppm>",
                               2, 2) == false) return(1);
int numargs = manager.numExtraArgs();
std::string infilename = manager.getExtraArg(0);
std::string outfilename = manager.getExtraArg(1);
// Note: This call is optinal too, and if you don't make it
// explicitly, it will be made from within start():
manager.saveConfig();
manager.start();
manager.reset();

to reset your model. But check that your various model components indeed do implement reset(), as reset() has been implemented only on a few components to date (since most programs run only one simulation and hence to not need any reset() capability).

manager.stop();
return 0;
}
Generated on Sun May 8 08:43:02 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3