-
Notifications
You must be signed in to change notification settings - Fork 19
Object Orientated programming with OpenCossan
OpenCossan uses MATLABs object orientated programming capabilities for the storage and manipulation of its data.
Classes are at the core of Object Orientated programming. A class is a blueprint for a object, and defines the properties and methods of a particular object.
- Properties: A collection of values a particular object can have.
- Methods: The functions associated with the object.
For example a class may be dogs, which defines the properties that all dogs will have. For example, all dogs will have a name (a String), a breed (a String) and a weight(a Number); and may have associated methods run() and eat(). This is the abstract definition of all dogs. A instance of the dogs class, a particular dog, is created when when these properties are given values.
Objects can be manipulated in code like usual variables.
OpenCossan uses objects to define it's variables. Take for example the random variable object:
Rv1 = RandomVariable('Sdescription','my first random variable','Sdistribution','normal', 'mean',10, 'std',2);
This is the constructor for the RandomVariable class, which defines the properties of this particular random variable. The above command creates a normal random variable with mean 10 and standard deviation 2, and gives it a description "my first random variable". OpenCossan uses keywords in the definition of its objects, for example 'mean' tells the function that the next argument passed with be the value of the mean, 10. OpenCossan uses a particular naming convention for its keywords. For example the S in-front of 'Sdescription' tells the constructor that the argument is a string. Objects may also have other objects as properties! In OpenCossan, if an object is passed to the constructor, the keyword argument must begin with an 'X'. A list of the cossan naming convention may be found at the end of this page.
The RandomVariable class has the sample() method, which generates a sample from the random variable. A classes method may be called like this:
samp = sample(Rv1)
- A – anonymous function / function handle
- C – cell array
- CS - cell array of strings
- CX - cell array of COSSAN-X objects
- CCX - cell array of cell arrays of COSSAN-X objects. REQUIRED by GUI-ENGINE integration
- H – Figure handle
- L – logical variable (true or false)
- M – matrix (e.g. Mcorr ... correlation matrix); also if the data structure can be a matrix or a vector (sometimes the case)
- N – indicates length of some list (e.g. Nsim ... # of simulations, Nvars ... # of variables) Integer >=0
- P - Polymorphic object/data structure
- S – string
- T – structure
- V – vector
- X – COSSAN-X objects (e.g. 'Evaluator' or 'ProbabilisticModel')