Description Usage Details The CAB.model class The model_constructor function See Also Examples
The Computational Analysis of Behaviour (CAB) software package is a general purpose software package for implementing computational models of behaviour. A model is implemented in the CAB.model
class. The CAB.model
is a parent class that contains a slot organism
that contains all the parameters that are necessary for the functions that are required to operate the model. In order to create a model, create a parent class that inherits from CAB.model
with slots for each of the functions that are associated with that model.
1 2 3 4 | ## S4 method for signature 'CAB.model'
show(object)
set_derived(model, derived_params)
|
For constructing a model:
Make a constructor function with the model_constructor()
function.
Use the constructor to make a model object.
CAB.model
classThe CAB.model
is the parent class for specific model objects.
organism
An environment
that contains all the parameters needed for the model.
derived_params
An expression
for calculating parameters that require values from the organism
slot.
event_record
A event_record
for storing data.
model_constructor
functionmodel_constructor
is a function returns another function. The returned function contains all of the information that is required to construct the desired model.
model_constructor( model_name, slot_names )
model_name
A character string giving the name of the model class to be constructed
slot_names
Names of the sub-functions required for the model
The model_constructor
returns a function with the arguments organism_params
, ...
, derived_params
, and event_record
. organism_params
takes a list with the names of each element specifying the model parameters. ...
takes named arguments with the names of the arguments being slot_names
in the constructor function and the argument values being functions for the associated model sub-function. derived_params
takes an expression that is used to calculate values using variables in organism_params
, defaults to NULL
if no derived parameters are needed. See example for notes on writing the expression
for derived_params
. event_record
takes an object of class event_record
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Make a model called "good_times"
# First set up the function to construct "good_time" models
# Give the model two subfunctions: "plus_happy" and "minus_happy"
make_good_times = model_constructor( model_name = "good_times", slot_names = c( "plus_happy", "minus_happy" ) )
# Let the "good_times" model have 3 parameters: happiness level and set it to 100, plus and set to 10, minus and set to 1
organism_parameters = list( happiness_level = 100, plus = 10, minus = 1 )
# Define the "plus_happy" and "minus_happy" functions
plus_happy_fx = function( happiness_level, plus ){
happiness_level + plus
}
minus_happy_fx = function( happiness_level, minus ){
happiness_level - minus
}
# Add a derived parameter:
# The expression must have either curly bracers or the formal <- assignment operator:
indifference = expression({ indifference = plus - minus })
# or
indifference = expression( indifference <- plus - minus )
# Make a "good_times" model:
good_times_model = make_good_times( organism_params = organism_parameters, plus_happy = plus_happy_fx, minus_happy = minus_happy_fx, derived_params = indifference )
good_times_model
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.