Last active
February 5, 2019 02:18
-
-
Save drautb/86194d72a789351094328caefc81fef6 to your computer and use it in GitHub Desktop.
SweetPea Window Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SweetPea Window Examples | |
# Derived Levels are defined by three things: | |
# - A Derivation Function | |
# - An Argument List | |
# - A Window | |
# | |
# Windows in turn are defined by a width and a stride. WithinTrial and | |
# Transition are just shorthand for Windows with widths of 1 and 2 | |
# respectively, and both with a stride of 1. | |
# | |
# Here's an example of a Window with width 1 and stride 1: | |
con_factor = Factor("congruent?", [ | |
DerivedLevel("con", WithinTrial(lambda color, text: color == text, [color, text])), | |
DerivedLevel("inc", WithinTrial(lambda color, text: color != text, [color, text])) | |
]) | |
# And here's an example of a Window with width 2 and stride 1: | |
repeated_color_factor = Factor("color repeats?", [ | |
DerivedLevel("yes", Transition(lambda colors: colors[0] == colors[1], [color])), | |
DerivedLevel("no", Transition(lambda colors: colors[0] != colors[1], [color])) | |
]) | |
# Notice how the derivation function for the repeated color factor receives | |
# a _list_ of color values. (colors[0], colors[1], etc) | |
# | |
# In contrast, notice how the congruent factor receives just a color and text | |
# value directly. | |
# | |
# For all Windows with a width of 1, the derivation function receives the value | |
# for each factor directly, rather than a list, because there is only one value | |
# when the width is 1. | |
# | |
# On the other hand, when the width is greater than 1, the derivation function | |
# receives a _list_ of values for each factor, where the number of values for | |
# each factor corresponds to the width of the Window. | |
# Here's a slightly more complicated example: | |
congruent_bookend = Factor("congruent bookend?", [ | |
DerivedLevel("yes", Window(lambda color, text: color == text, [color, text], 1, 3)), | |
DerivedLevel("no", Window(lambda color, text: color != text, [color, text], 1, 3)) | |
]) | |
# This Window has a width of 1, and a stride of 3. Because the width is 1, the | |
# function receives factor values directly, not lists. This factor takes the | |
# 'yes' level whenever every third trial (starting with the first) is congruent. | |
# Consider another example, where we want to identify whether or not the first | |
# and third trials in a sliding window have the same level. We can define such | |
# a factor like this: | |
first_third_match = Factor("first and third match?", [ | |
DerivedLevel("yes", Window(lambda colors: colors[0] == colors[2], [color], 3, 1)), | |
DerivedLevel("no", Window(lambda colors: colors[0] != colors[2], [color], 3, 1)) | |
]) | |
# This window has a width of 3, and a stride of 1. Notice again how, because | |
# the width is greater than 1, the derivation function receives a _list_ of | |
# values for each factor. The nth value in the list corresponds to the factor's | |
# value in the nth trial of the Window. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment