Ejemplo n.º 1
0
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"

Ejemplo n.º 2
0
# 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
])
Ejemplo n.º 3
0
def inc_con(congruency):
    return congruency[0] == "incongruent" and congruency[1] == "congruent"
def inc_inc(congruency):
    return congruency[0] == "incongruent" and congruency[1] == "incongruent"
def inc_ntr(congruency):
    return congruency[0] == "incongruent" and congruency[1] == "neutral"
def ntr_con(congruency):
    return congruency[0] == "neutral" and congruency[1] == "congruent"
def ntr_inc(congruency):
    return congruency[0] == "neutral" and congruency[1] == "incongruent"
def ntr_ntr(congruency):
    return congruency[0] == "neutral" and congruency[1] == "neutral"


congruency_transition = factor("congruency_transition", [
    derived_level("congruent-congruent", transition(con_con, [congruency])),
    derived_level("congruent-incongruent", transition(con_inc, [congruency])),
    derived_level("congruent-neutral", transition(con_ntr, [congruency])),
    derived_level("incongruent-congruent", transition(inc_con, [congruency])),
    derived_level("incongruent-incongruent", transition(inc_inc, [congruency])),
    derived_level("incongruent-neutral", transition(inc_ntr, [congruency])),
    derived_level("neutral-congruent", transition(ntr_con, [congruency])),
    derived_level("neutral-incongruent", transition(ntr_inc, [congruency])),
    derived_level("neutral-neutral", transition(ntr_ntr, [congruency]))
])

# DEFINE RESPONSE TRANSITION FACTOR

def response_repeat(responses):
    return responses[0] == responses[1]
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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", [
Ejemplo n.º 7
0

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


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


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


congruency_transition = factor("congruency transition", [
    derived_level("congruent-congruent", transition(con_con, [congruency])),
    derived_level("congruent-incongruent", transition(con_inc, [congruency])),
    derived_level("incongruent-congruent", transition(inc_con, [congruency])),
    derived_level("incongruent-incongruent", transition(inc_inc,
                                                        [congruency])),
])


# 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)
        return False


"""
btw, this is the same as:
def response_left(task, color, motion):
    return (task == color && color == red) || (task == motion && motion == up)
"""


def response_right(task, color, motion):
    return not response_left(task, color, motion)


response = Factor("response", [
    derived_level("left", WithinTrial(response_left, [task, color, motion])),
    derived_level("right", WithinTrial(response_right, [task, color, motion]))
])
"""
          congruency (congruent, incongruent): dependent Factor.
if current color == red  & current motion == up then response = congruent
if current color == blue & current motion == down then response = congruent
.
if current color == red & current  motion == down then response = incongruent
if current color == blue & current  motion == up then response = incongruent
"""


def congruent(color, motion):
    return ((color == "red") and (motion == "up")) or ((color == "blue") and
                                                       (motion == "down"))
Ejemplo n.º 9
0
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]))
])
Ejemplo n.º 10
0
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
Ejemplo n.º 11
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)
Ejemplo n.º 12
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
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)
Ejemplo n.º 13
0
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)
    experiments = synthesize_trials_non_uniform(block, 100)

    assert len(experiments) == 24
Ejemplo n.º 14
0
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)