class.input: 'input' class

Description Usage Format Details Slots Make a new input object Indexing on an input object Set up a input object for a simulation Assign values to variables in a input object Assign the next empty (i.e. first non-NaN) element in a variable in an input object Assign the next empty element in a variable in an input object by transformation Get the last element in a variable in an input object To reset the values stored in a variable data and counts Examples

Description

When a simulation is run in the CAB package, the within-simulation information (i.e., the variables that are not pre-set before the simulation, e.g. the number of responses during an inter-reinforcement itnerval) are stored in an input object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
make.input(var_names)

index.input

input.show

remove.input.show()

setup.input(input, lengths)

## S4 method for signature 'input,numeric'
setup.input(input, lengths)

assign.input(input, v, indices, values, counts = NULL)

next.input(input, v, value)

transform.input(input, v, FUN, ...)

tail.input(input, v)

reset.input(input, v)

Format

An object of class character of length 1.

Details

The underlying implementation of the input class is that the input class has two slots. One slot is called info, which holds an environment. Each element in the environment is a list. For each list, one element of the list is a vector that stores the events that occurred (for example, a vector may store the response times) and the other element is a single numeric that counts the number of elements that stored in the corresponding vector. The second slot is called names, which is just for easy access of the variable names in the input object.

Before using a input object to store data or count things in a simulation, set it up with the setup.input_monitor function.

A show method for the input class has been defined for printing input objects (see below; input.show()). An associated function remove.input.show() has been defined for removing the show method.

Slots

info

An environment that contains a list, which in turn contains a vector to store events that occur in the simulation, as well as a numeric to count the events. The vector that contains the data is called data and the numeric that stores the counts is counts.

names

Stores the names of the variables held in the info slot.

Make a new input object

Before doing a simulation, a input object needs to be constructed to store the data that is generated (e.g. response times) and to count the instances of some particular event (e.g. number of responses).

Note that when input object is first constructed, each of the variables in the info slot will be a vector of NaN of size 1.

Usage

make.input( var_names )

Arguments

var_names

A vector of character strings that give names for the events to be stored. See example.

Value

A input object is returned.

Indexing on an input object

Usage

"["( x, v ) or input[v]

Arguments

x

An input object.

v

A string specifting a variable in the input object.

input

An input object.

Value

Returns the vector in the input object that is specified by v. See example.

Set up a input object for a simulation

Usage

setup.input( input, lengths )

Arguments

input

An object of class input

.

lengths

Either a list or a single numeric, giving the length of the data storage vectors. See details.

Details

If the argument for lengths is a list, the names of each element in the list should be a "vect" variable. The element associated with the name gives the length of the "vect" vector and fills it with NaN. If some "vect" variables are not given in the list, then they are set to be the length of the longest "vect" specified by the user.

If the argument is a single numeric, then all of the variables of "vect" are set to be NaN vectors of the specified length.

Value

Returns a input object with each "vect" variable being a vector filled with NaN of the specified length.

Assign values to variables in a input object

This function is for assiging the ith to jth element of a variable in an input object. See examples.

Usage

assign.input( input, v, indices, values, counts = NULL)

Arugments

input

An object of class input.

v

A character string specifying a variable in the input object.

indices

An optional argument. A numeric vector specifying which indices of the variable vector to be changed.

values

An optional argument. A vector of values to be assigned.

counts

An optional argument to change the counts associated with v

.

Details

As a side effect of the way that the assignment is done, if a value is assigned to a variable that does not exist, it will be created and put into the input environment, with the just the data vector without counts. Also as a side effect of the way that the assignment is done, if the data vector for a variable is of length 5 and a value is assigned to index 10, the intervening elements (6 to 9) will be NA.

Assign the next empty (i.e. first non-NaN) element in a variable in an input object

When conducting a simulation, it is often convenient to set the next element that is stored in an input variable without having to explicitly track where the next available element is. Because the input variables are a vector filled with NaN by default (see the above methods), this amounts to using assign.input to assign the first NaN element in an input variable to some value. Because this function is intended to be used to enter data during a simulation, the counter that is associated with the variable is automatically incremented with each call to the next.input method.

Usage

next.input( input, v, value )

Arguments

input

An object of class input.

v

A character string specifying a variable in the input object.

value

A value to place in the next available element in the data vector for v.

Details

Note that the new value for the associated counts will be incremented by 1. Hence, if additional changes are made to the data vector associated with v, say with the assign.input, then the counts will not be correct. Also, note that the next.input function finds the next available element in the vector by taking the index that is 1 larger than the associated counts. Hence, this will overwrite any stored information in the index regardless if it is NaN.

Assign the next empty element in a variable in an input object by transformation

When conducing a simulation, the next.input method can be used to set the next available index in a input variable to some value. In some cases, it may be necessary for the new value to be dependent on the most recent value. An example of this is if a simulation specifies that the ith response time must be the same as the i-1th response time. See example.

Usage

transform.input( input, v , FUN, ... )

Arguments

input

An object of class input.

v

A character string specifying a variable in the input object.

FUN

A function.

...

Additional arguments for FUN.

Details

The transform.input method takes the first unspecified argument for FUN as the most recent non-empty element in the variable v. By this, it is meant that the value before the one that is to be specified by the transform.input function. Further, the underlying implementation is that the transform.input function matches the arguments in ... with the formal arguments of the function FUN. The first unmatched argument is assigned to be the most recent non-empty element in the v vector. Then, the next.input function is called. Hence, all of the cautions that must be applied with next.input should also be applied to transform.input.

Get the last element in a variable in an input object

To extract the last element, by which we mean the index that corresponds to the value of the associated counts, use the tail.input() function.

Usage

tail.input( input, v )

Arguments

input

An object of class input.

v

A character string specifying a variable in the input object.

To reset the values stored in a variable data and counts

The reset.input() function is for resetting the values in the data to NaN and counts to zero for a variable in an input object.

Usage

reset.input( input, v )

Arguments

input

An object of class input.

v

A character string specifying a variable in the input object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#### Create an "input" for storing the variables: "time_input", "resp_time", "rft_time", "rft_setup", and to count the events: "resp_counter", "rft_counter". ####
var_names = c( "time_input", "vect", "resp_time", "rft_time", "rft_setup" )
my_input = make.input( var_names )
my_input

#### Indexing on an "input" object ####
# Extract the response times
response_times = my_input[ v = "resp_time" ]
# Remember that for a newly created "input" object, the variable contains a single \code{NaN} in the \code{data} vector and a zero in the \code{counts} vector.

#### Set up an "input" object ####
# Set the "input" to hold a maximum of 10 response times, 11 reinforcement times, and 20 "time_input". Note that the length for "rft_setup" is not specified, so it becomes the specified maximum (20).
length_list = list( resp_time = 5, rft_time = 11, time_input = 20 )
setup.input( my_input, length_list )
my_input

# Set up "input" to hold 50 elements for all variables
setup.input( my_input, 50 )
my_input

# Set the first element of the "time_input" variable to 0, set the fifth element of the "time_input" variable to 1, and set the associated "counts" to 100.
assign.input( my_input, v = "time_input", indices = c(1, 5), values = c(0, 1 ), counts = 100 )

# Store a sequence of "1" in the "resp_time" vector. Also, note the value of the associated "counts"
next.input( my_input, "resp_time", 1 )
my_input
next.input( my_input, "resp_time", 1 )
my_input
next.input( my_input, "resp_time", 1 )
my_input

#Set the "resp_time" values to be twice larger than the previously specified "resp_time_value"
fx = function( x, y ) x * y
transform.input( my_input, "resp_time", fx, y = 2 )
my_input
transform.input( my_input, "resp_time", fx, y = 2 )
my_input
# Set the "resp_time" values to be thrice larger
transform.input( my_input, "resp_time", fx, y = 3 )
my_input

#Get the last element in an "input" variable data vector
tail.input( my_input, "resp_time" )

#Reset
reset.input( my_input, "resp_time" )
my_input

Don-Li/CAB_original documentation built on May 6, 2019, 2:53 p.m.