color = factor("color", ["red", "blue", "green", "brown"]) word = factor("motion", ["red", "blue", "green", "brown"]) # DEFINE CONGRUENCY FACTOR def congruent(color, word): return color == word def incongruent(color, word): return not congruent(color, word) conLevel = derived_level("con", within_trial(congruent, [color, word])) incLevel = derived_level("inc", within_trial(incongruent, [color, word])) congruency = factor("congruency", [conLevel, incLevel]) # DEFINE RESPONSE FACTOR def response_up(color): return color == "red" def response_down(color): return color == "blue"
from sweetpea.tests.test_utils import get_level_from_name color = factor("color", ["red", "blue", "green"]) word = factor("motion", ["red", "blue"]) def illegal_stimulus(color, word): return color == "green" and word == "blue" def legal_stimulus(color, word): return not illegal_stimulus(color, word) stimulus_configuration = factor("stimulus configuration", [ derived_level("legal", within_trial(legal_stimulus, [color, word])), derived_level("illegal", within_trial(illegal_stimulus, [color, word])) ]) constraints = [ exclude(stimulus_configuration, get_level_from_name(stimulus_configuration, "illegal")) ] design = [color, word, stimulus_configuration] crossing = [color, word] def test_no_solutions_without_override_flag(): block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 500)
# DEFINE STIMULUS FACTORS colorCoherence = factor("color coherence", ["0.3", "0.53", "0.76", "1.0"]) motionCoherence = factor("motion coherence", ["0.3", "0.53", "0.76", "1.0"]) color = factor("color direction", ["red", "blue"]) motion = factor("motion direction", ["up", "down"]) # DEFINE RESPONSE FACTORS def leftResponse(stimulusDimension): return (stimulusDimension == "red" or stimulusDimension == "up") def rightResponse(stimulusDimension): return (stimulusDimension == "blue" or stimulusDimension == "down") leftColorResponseLevel = derived_level("-1", within_trial(leftResponse, [color])) rightColorResponseLevel = derived_level("1", within_trial(rightResponse, [color])) leftMotionResponseLevel = derived_level("-1", within_trial(leftResponse, [motion])) rightMotionResponseLevel = derived_level("1", within_trial(rightResponse, [motion])) colorResponse = factor("correct color response", [ leftColorResponseLevel, rightColorResponseLevel ]) motionResponse = factor("correct motion response", [ leftMotionResponseLevel, rightMotionResponseLevel ])
]) # DEFINE FLANKER RESPONSE FACTOR def flanker_left(target_direction, congruency): return ((target_direction == "1" and congruency == "congruent") or (target_direction == "-1" and congruency == "incongruent")) def flanker_right(target_direction, congruency): return not flanker_left(target_direction, congruency) flanker_direction = factor("flanker direction", [ derived_level("1", within_trial(flanker_left, [target_direction, congruency])), derived_level("-1", within_trial(flanker_right, [target_direction, congruency])) ]) # DEFINE CORRECT RESPONSE def response_left(target_direction): return target_direction == "1" def response_right(target_direction): return not response_left((target_direction)) correct_response = factor("correct response", [
if task == color & current color == red then correct response = left if task == motion & current motion == up then correct response = left if task == size & current size == large then correct response = left . if task == color & current color == blue then correct response = right if task == motion & current motion == down then correct response = right if task == size & current size == small then correct response = right """ def response_left(task, color, motion, size): return (task == "color" and color == "red") or (task == "motion" and motion == "up") or (task == "size" and size == "large") def response_right(task, color, motion, size): return not response_left(task, color, motion, size) response = Factor("response", [derived_level("left", within_trial(response_left, [task, color, motion, size])), derived_level("right", within_trial(response_right, [task, color, motion, size]))]) """ congruency (congruent, incongruent): dependent factor. if current color == red & current motion == up & size = large then response = congruent if current color == blue & current motion == down & size = small then response = congruent otherwise incongruent """ def congruent(color, motion): return ((color == "red") and (motion == "up") and (size == "large")) or ((color == "blue") and (motion == "down") and (size == "small")) def incongruent(color, motion): return not congruent(color, motion)
motion = factor("motion", ["up", "down"]) task = factor("task", ["color", "motion"]) # Response Definition def response_left(task, color, motion): return (task == "color" and color == "red") or \ (task == "motion" and motion == "up") def response_right(task, color, motion): return not response_left(task, color, motion) response = factor("response", [ derived_level("left", within_trial(response_left, [task, color, motion])), derived_level("right", within_trial(response_right, [task, color, motion])) ]) # Congruency Definition def color_motion_congruent(color, motion): return ((color == "red") and (motion == "up")) or \ ((color == "blue") and (motion == "down")) def color_motion_incongruent(color, motion): return not color_motion_congruent(color, motion) congruency = factor("congruency", [
from sweetpea.primitives import factor, derived_level, within_trial, transition from sweetpea.constraints import at_most_k_in_a_row, exactly_k_in_a_row, exclude from sweetpea.sampling_strategies.uniform_combinatoric import UniformCombinatoricSamplingStrategy from sweetpea import multiple_cross_block, synthesize_trials_non_uniform, synthesize_trials from sweetpea.tests.test_utils import get_level_from_name from acceptance import shuffled_design_sample # Basic setup color_list = ["red", "blue"] color = factor("color", color_list) text = factor("text", color_list) mix = factor("text", color_list) # Congruent factor con_level = derived_level("con", within_trial(op.eq, [color, text])) inc_level = derived_level("inc", within_trial(op.ne, [color, text])) con_factor = factor("congruent?", [con_level, inc_level]) # Repeated color factor repeated_color_factor = factor("repeated color?", [ derived_level("yes", transition(lambda colors: colors[0] == colors[1], [color])), derived_level("no", transition(lambda colors: colors[0] != colors[1], [color])) ]) # Repeated text factor repeated_text_factor = factor("repeated text?", [ derived_level("yes", transition(lambda texts: texts[0] == texts[1], [text])), derived_level("no", transition(lambda texts: texts[0] != texts[1], [text])) ])
text = factor("text", ["red", "blue"]) color = factor("color", ["28", "45"]) motion = factor("motion", ["up", "down"]) response = factor("response", ["👈", "👉"]) def congruent(color, motion): return ((color == "red") and (motion == "up")) or ((color == "blue") and (motion == "down")) def some_func(color0, text0, color1, text1, color2): return None derived_level("con", within_trial(op.eq, [color, text])) derived_level("con", transition(congruent, [color, motion])) #derived_level("con", window(some_func, [[color, text], [color, text], [color]], 2, stride=2)) k = 1 #TODO this value should change to the intended value from the writing of the original code at_most_k_in_a_row(k, conLevel) Balance(congruentFactor) # congruent : 3 (red, red) (g, g) (b,b) # incongruent : 6 # # 2 of each congruent --> 6 congruent # matches the 6 incongruent # without rep should be a keyword # balance which figures out the 2-to-1 ratio
# Make SweetPea visible regardless of whether it's been installed. import sys sys.path.append("..") import operator from sweetpea.primitives import factor, derived_level, within_trial, transition from sweetpea import fully_cross_block, synthesize_trials_non_uniform, print_experiments, at_most_k_in_a_row, exclude color_list = ["red", "green", "blue"] color = factor("color", color_list) word = factor("word", color_list) congruent = derived_level("con", within_trial(operator.eq, [color, word])) incongruent = derived_level("inc", within_trial(operator.ne, [color, word])) congruence = factor("congruence", [congruent, incongruent]) one_con_at_a_time = at_most_k_in_a_row(1, (congruence, congruent)) def one_diff(colors, words): if (colors[0] == colors[1]): return words[0] != words[1] else: return words[0] == words[1] def both_diff(colors, words): return not one_diff(colors, words)
left = factor("left", ["0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"]) right = factor("right", ["0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"]) # ALL POSSIBLE COMBINATIONS # DEFINE CONGRUENCY FACTOR def congruent_stimulus(left, right): return left[0] == right[0] and left[1] == right[1] def incongruent_stimulus(left, right): return not congruent_stimulus(left, right) cong_stimulus = derived_level("cong_stimulus", within_trial(congruent_stimulus, [left, right])) incong_stimulus = derived_level("incong_stimulus", within_trial(incongruent_stimulus, [left, right])) stimulus = factor("stimulus", [ cong_stimulus, incong_stimulus ]) # DEFINE CONGRUENCY FACTOR def congruent_context(left, right): return left[2] == right[2] and left[3] == right[3] def incongruent_context(left, right): return not congruent_context(left, right)