01-06-2022, 08:45 AM
In Experiment Builder, the modulo operator (%) is a powerful tool for controlling when actions occur. For example, you can use it to perform a drift check only after a specific number of trials have passed.
What is a Modulo?
The modulo operator calculates the remainder of a division operation. For example:
How to Use It in a Conditional Node
The modulo operator is most effective when used inside a Conditional node to direct the flow of your experiment.
Example: Performing a Drift Check Every 10 Trials
Imagine you want to run a drift check after every 10 completed trials (i.e., at the beginning of trials 11, 21, 31, and so on).
To do this, you would use the following equation in your Conditional node's attribute field:
Note: Indexing starts at 0 in python, hence the "-1" in the equation above to make sure the values align.
The "True" path from this node would lead to your Drift Check sequence, while the "False" path would bypass it and go straight to the Recording sequence.
What is a Modulo?
The modulo operator calculates the remainder of a division operation. For example:
- 10 % 10 equals 0 (because 10 divides into 10 evenly).
- 12 % 10 equals 2 (because 10 goes into 12 once, with a remainder of 2).
- 24 % 6 equals 0 (because 24 divides into 6 evenly).
How to Use It in a Conditional Node
The modulo operator is most effective when used inside a Conditional node to direct the flow of your experiment.
- Set the Attribute: In the Conditional node, input your modulo equation as the attribute. This equation should reference a dynamic value, such as the current trial number (trial_iteration.value).
- Set the Comparison: Set the comparator to EQUALS
- Set the Value: set the value to 0.
Example: Performing a Drift Check Every 10 Trials
Imagine you want to run a drift check after every 10 completed trials (i.e., at the beginning of trials 11, 21, 31, and so on).
To do this, you would use the following equation in your Conditional node's attribute field:
Code:
=(trial_iteration.value - 1) % 10
Note: Indexing starts at 0 in python, hence the "-1" in the equation above to make sure the values align.
The "True" path from this node would lead to your Drift Check sequence, while the "False" path would bypass it and go straight to the Recording sequence.