Random Variables

In some kinds of experiments it is desirable to randomly vary some aspect of the stimulus -- the speed or direction of a pursued target, the duration of a fixation epoch prior to the initiation of pursuit, and so on. Prior to Version 3.3.0, researchers could randomize a trial segment's duration by specifying a maximum duration M greater than the minimum duration m; the actual segment duration for a particular trial presentation is then randomly selected from a uniform distribution over [m..M]. To randomize another parameter like target window velocity, one had to create a large set of trials in which the parameter is set to a different value in each trial, then present the trial set in the Randomized sequencer mode; of course, this approach merely randomized the order of presentation of the trials, and thus, the order in which the pre-selected list of window velocities was presented to the subject.

As of Version 3.3.0, Maestro offers a more powerful and flexible way to introduce "randomness" into a single trial: random variables (RV). For our purposes, a random variable is a quantity that can take on any value from a range of real numbers in accordance with a defined probability distribution. Four types of distributed RVs are supported in a trial object:

    • Uniform(A, B): Values are uniformly distributed over the range [A .. B], where the lower bound A must be strictly less than the upper bound B.

    • Normal(μ, σ, S): A Gaussian distribution with mean μ and standard deviation σ > 0. For practical purposes, we also define a maximum spread S that must be at least 3 standard deviations. Any value will outside [μ-S .. μ+S] will be rejected, and another value generated in its place; note that over 99% of the values generated will lie within +/-3σ of the mean.

    • Exponential(λ, S): An exponential distribution with rate λ > 0. This distribution has a mean and standard deviation = 1/λ, and it generates only non-negative real values. Again, we also specify a maximum cutoff S >= 3 standard deviations. Any value exceeding S is rejected and another value generated until the maximum cutoff is satisfied.

    • Gamma(κ, θ, S): The gamma distribution with shape parameter κ > 0 and scale parameter θ > 0. It generates only non-negative values, has a mean κθ and a variance of κθ2. Again, a maximum cutoff S is specified; it must be at least 3 standard deviations beyond the mean, i.e., S >= θ*(κ + 3*κ0.5).

In addition to these distributed RV types, you can also define an RV as a function of other RVs. Suppose you design a trial in which you would like the direction of target motion to be normally distributed over repeated presentations of that trial, while the target speed remains constant. To do so, you could define a random variable x0 normally distributed with mean 0, standard deviation 60, and a maximum spread of 180; this would generate a direction angle normally distributed over [-180 .. 180] degrees. Then define two function-type RVs: x1=10*cos(x0*pi/180) and x2=10*sin(x0*pi/180). Assign x1 to the target's horizontal velocity component during the segment in which motion occurs, and assign x2 to the target's vertical component. Present that single trial over and over again, and the target's direction of motion will vary normally over the trial sequence!

Each trial has its own set of 10 random variables; you can define and use any subset of those RVs (unlike perturbation and target objects, RVs are not "shared" with other trial objects in the experiment document). Any of the following segment table parameters may be assigned to an RV: minimum and maximum segment duration; target window position, velocity, or acceleration; and target pattern velocity or acceleration. For segment duration, both the minimum and maximum values are, by design, assigned to the same RV, and that RV governs the actual segment duration used for each successive trial presentation.

The trial's list of random variables is displayed and edited on the Random Variables tab pane in the Trial Editor. As illustrated in the screenshot above, the only widget in this tab pane is a grid control displaying the trial's 10 random variables, x0 - x9. Columns 1-6 in the grid show the defining parameters for each RV:

    • Type. The variable type - UNUSED, UNIFORM, NORMAL, EXPON, GAMMA, or FUNCTION. If the type is UNUSED, that RV is undefined and must not be assigned to any parameter in the segment table.

    • Seed. The initial seed for the random number engine that drives the generation of random variates in accordance with the RV's specified distribution. It can take on any non-negative integer value (up to 8 digits). If you want "repeatability" -- that is, if you want two separate sequences of 100 repetitions of the same trial to cycle through the same exact sequence of RV values --, you must set the RV's seed to a non-zero value. Conversely, if the seed is 0, then when a trial sequence begins, the RV's random number generator is initialized with a randomly selected seed value -- so each trial sequence should be unique (WRT the values generated for that RV).

    • Param1, 2, 3. Parameters defining a distributed RV. Their meaning depends on the RV type. For Uniform(A, B), p1 is the lower bound A and p2 is the upper bound B; for Normal(μ, σ, S), p1 = μ, p2 = σ, and p3 = S; for Exp(λ, S), p1 = λ and p2 = S; for Gamma(κ, θ, S), p1=κ, p2 = θ, and p3 = S. Observe that, if any parameter is not applicable to the distribution, the corresponding cell in the grid is blank with a gray background. To confirm the meaning of a particular parameter, simply click once on the corresponding cell and a parameter label will appear briefly in a pop-up "tool-tip".

    • Formula. This is the formula string for a FUNCTION-type RV and is applicable only to that type. An RV is referenced in the function using its variable name, x0 - x9. In addition to these variables, the formula can contain integer or floating-point numeric constants; the named constant pi; the four standard arithmetic binary operators -, +, *, /; the unary - operator (as in "-2*x1"); left and right parentheses for grouping; and three named mathematical functions - sin(a), cos(a), and pow(a,b). Note that the pow() function includes a comma operator to separate its two arguments. Standard operator precedence rules are observed.

To edit any parameter in the grid, simply double-click on the corresponding grid cell. An appropriate "in-place" cell editor will appear -- a combo box to choose the variable type, a numeric edit field to edit the seed or any of the three distribution parameters, and a plain text field for the function formula. Select or enter the desired value, then press Enter to confirm the change. When you change an RV's type, the entire row is refreshed to reflect a valid definition for the selected variable type. If you change a parameter that has a side effect on another parameter, the other parameter is automatically corrected and its new value reflected in the grid. If you enter an invalid parameter value -- e.g., σ = 0 for a normally distributed RV, or a function formula string that cannot be parsed --, the change is rejected and the in-place editor reappears. If you decide not to make a change, you can hit the ESCape key to extinguish the editor. In addition, if you extinguish the editor with a Ctrl-arrow or TAB key, any validated change is saved and editing continues on the cell implied by the arrow or TAB key.

Note that a FUNCTION-type variable can depend on one or more other random variables. However, it cannot depend on itself -- x1 = 5*sin(x1) is not allowed --, nor on any other FUNCTION-type variable. All independent random variables appearing in the function formula must be distributed-type RVs. Conversely, any attempt to change the type of a distributed random variable xN to UNUSED or FUNCTION will be rejected if xN appears as an independent variable for another FUNCTION-type RV.

Finally, please note that the introduction of this new feature has no impact whatsoever on trials in experiment documents created prior to the release of Maestro 3.3.0. When you open such a document in V3.3.0 or later and load a trial into the Trial Editor, the trial's definition is unchanged; it will have a list of 10 random variables, but all 10 will be UNUSED. Users not interested in this new feature can continue to run their pre-3.3.0 trials in Maestro 3.3.0 without alteration.