示例#1
0
- current color (red, blue, green, brown)
- current word (red, blue, green, brown)
- congruency (congruent, incongruent): factor dependent on color and word.
- correct response (up, down, left right): factor dependent on color.
- response transition (repetition, switch). factor dependent on response:

design:
- counterbalancing color x word x response transition
- no more than 7 response repetitions in a row
- no more than 7 response switches in a row

"""

# DEFINE COLOR AND WORD FACTORS

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]))
- coherence of colors (0.3 0.53, 0.76, 1.0)
- coherence of motion (0.3 0.53, 0.76, 1.0)
- response color (-1, 1)
- response motion (-1, 1)
- congruency (congruent, incongruent): factor dependent on dominant color and dominant motion.

design:
- counterbalancing dominant color x dominant motion x color coherence x motion coherence

"""

print("GENERATING EXPERIMENT SEQUENCE WITH SWEETPEA...")

# 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]))
示例#3
0
***********************
factors (levels):
- reward (rewarded, non-rewarded)
- response (left, right)
- response transition (repetition, switch). factor dependent on response:
- congruency (congruent, incongruent, neutral)
- congruency transition (congruent-congruent, congruent-incongruent, congruent-neutral, incongruent-congruent, incongruent-incongruent, incongruent-neutral, neutral-congruent, neutral-incongruent, neutral-neutral)

design:
- counterbalancing reward x response x response_transition x congruency_transition

"""

# DEFINE REWARD, RESPONSE and CONGRUENCY FACTORS

reward      = factor("reward", ["rewarded", "non-rewarded"])
response    = factor("response",   ["building", "house"])
congruency  = factor("congruency",  ["congruent", "incongruent", "neutral"])

# DEFINE CONGRUENCY TRANSITION FACTOR

def con_con(congruency):
    return congruency[0] == "congruent" and congruency[1] == "congruent"
def con_inc(congruency):
    return congruency[0] == "congruent" and congruency[1] == "incongruent"
def con_ntr(congruency):
    return congruency[0] == "congruent" and congruency[1] == "neutral"
def inc_con(congruency):
    return congruency[0] == "incongruent" and congruency[1] == "congruent"
def inc_inc(congruency):
    return congruency[0] == "incongruent" and congruency[1] == "incongruent"
示例#4
0
factors (levels):
- target direction (1, -1)
- flanker direction (1, -1), factor dependent on target response and congruency
- correct response (left, right), factor dependent on target response
- response transition (repetition, switch). factor dependent on response
- congruency (congruent, incongruent)
- congruency transition (congruent-congruent, congruent-incongruent, congruent-neutral, incongruent-congruent, incongruent-incongruent, incongruent-neutral, neutral-congruent, neutral-incongruent, neutral-neutral)

design:
- counterbalancing reward x response x response_transition x congruency_transition

"""

# DEFINE REWARD, RESPONSE and CONGRUENCY FACTORS

target_direction = factor("target direction", ["1", "-1"])
congruency = factor("congruency", ["congruent", "incongruent"])

# DEFINE CONGRUENCY TRANSITION FACTOR


def con_con(congruency):
    return congruency[0] == "congruent" and congruency[1] == "congruent"


def con_inc(congruency):
    return congruency[0] == "congruent" and congruency[1] == "incongruent"


def inc_con(congruency):
    return congruency[0] == "incongruent" and congruency[1] == "congruent"
示例#5
0
from acceptance import assert_no_repetition
from sweetpea.primitives import factor, derived_level, within_trial, transition
from sweetpea.constraints import exclude
from sweetpea.encoding_diagram import print_encoding_diagram
from sweetpea import fully_cross_block, synthesize_trials_non_uniform, print_experiments
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]
示例#6
0
- congruency (congruent, incongruent): dependent factor.
- task transition (repetition, switch). dependent factor of task:
- response transition (repetition, switch). dependent factor of correct response:

constraints:
- counterbalancing congruency x response x task x task-transition x response-transition x color x motion
- no more than 7 task repetitions in a row
- no more than 7 task switches in a row
- no more than 7 response repetitions in a row
- no more than 7 response switches in a row

vv --> does that come from the counterbalancing above?
Total number of trials: we want to have at least 20 instances of each combination of task-transition x congruency
"""

color  = factor("color",  ["red", "blue", "green"])
motion = factor("motion", ["up", "down"])
task   = factor("task",   ["color", "motion"])

"""
          correct response (left, right): dependent factor.
if task == color & current color == red then correct response =  left
if task == motion & current motion == up then correct response =  left
.
if task == color & current color == blue then correct response =  right
if task == motion & current motion == down then correct response =  right
"""

def response_left(task, color, motion):
    if (task == "color" and color == "red") or (task == "motion" and motion == "up"):
        return True
示例#7
0
import pytest

from sweetpea.primitives import factor, derived_level, within_trial, transition
from sweetpea.constraints import at_most_k_in_a_row
from sweetpea import fully_cross_block, print_experiments, synthesize_trials_non_uniform
from acceptance import assert_atmostkinarow, shuffled_design_sample

# Simple Factors
color = factor("color", ["red", "blue"])
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):
示例#8
0
from sweetpea.primitives import factor, derived_level, within_trial, transition, window
from sweetpea.constraints import at_most_k_in_a_row, at_most_k_in_a_row
from sweetpea import fully_cross_block, synthesize_trials_non_uniform, print_experiments
import operator as op

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
#
示例#9
0
import operator as op
import pytest

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]))
示例#10
0
# 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)
import operator as op
import pytest

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
from sweetpea.sampling_strategies.guided import GuidedSamplingStrategy
from sweetpea import fully_cross_block, synthesize_trials
from sweetpea.tests.test_utils import get_level_from_name

# Basic setup
color_list = ["red", "blue"]
color = factor("color", color_list)
text = 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])

design = [color, text, con_factor]
crossing = [color, text]
constraints = []

block = fully_cross_block(design, crossing, constraints)


def test_guided_sampling_works():
    trials = synthesize_trials(block,
                               5,
                               sampling_strategy=GuidedSamplingStrategy)
示例#12
0
import pytest

from itertools import permutations

from sweetpea import fully_cross_block, synthesize_trials_non_uniform, print_experiments
from sweetpea.constraints import at_most_k_in_a_row, exclude
from sweetpea.encoding_diagram import print_encoding_diagram
from sweetpea.primitives import factor, derived_level, window
from sweetpea.tests.test_utils import get_level_from_name

# Basic setup
color_list = ["red", "blue"]
color = factor("color", color_list)
text = factor("text", color_list)

# congruent 'bookend' factor. (color and text in first and last trial are congruent)
congruent_bookend = factor("congruent bookend?", [
    derived_level(
        "yes", window(lambda color, text: color == text, [color, text], 1, 3)),
    derived_level(
        "no", window(lambda color, text: color != text, [color, text], 1, 3))
])


@pytest.mark.parametrize('design',
                         permutations([color, text, congruent_bookend]))
def test_correct_solution_count_when_unconstrained(design):
    crossing = [color, text]
    constraints = []

    block = fully_cross_block(design, crossing, constraints)
示例#13
0
******************************
factors (levels):
- left (0000, 0001 ......, 1111)
- right (0000, 0001 ......, 1111)
- congruent stimilus (congruent, incongruent): factor dependent on first and second letter of left and right.
- congruent context (congruent, incongruent): factor dependent on third and fourth letter of left and right.
- four_case (stimulus, context)

design:
- counterbalancing left x four_case x right

"""

# DEFINE FOUR FACTORS

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]))
import pytest
import operator as op

from itertools import permutations

from sweetpea.primitives import factor, derived_level, within_trial, transition
from sweetpea.constraints import at_most_k_in_a_row
from sweetpea.encoding_diagram import print_encoding_diagram
from sweetpea import fully_cross_block, synthesize_trials_non_uniform, print_experiments
from sweetpea.tests.test_utils import get_level_from_name

direction = factor("direction", ["up", "down"])

color_list = ["red", "blue"]
color = factor("color", color_list)
text = factor("text", color_list)

congruent_factor = factor("congruent?", [
    derived_level("con", within_trial(op.eq, [color, text])),
    derived_level("inc", within_trial(op.ne, [color, text]))
])

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]))
])


@pytest.mark.parametrize('design',