sweetpea.derivation_processor module

This module provides functionality for processing derivations.

class sweetpea.derivation_processor.DerivationProcessor

Bases: object

static generate_derivations(block)

Usage:

>>> import operator as op
>>> color = Factor("color", ["red", "blue"])
>>> text  = Factor("text",  ["red", "blue"])
>>> conLevel  = DerivedLevel("con", WithinTrial(op.eq, [color, text]))
>>> incLevel  = DerivedLevel("inc", WithinTrial(op.ne, [color, text]))
>>> conFactor = Factor("congruent?", [conLevel, incLevel])
>>> design = [color, text, conFactor]
>>> crossing = [color, text]
>>> block = fully_cross_block(design, crossing, [])
>>> DerivationProcessor.generate_derivations(block)
[Derivation(derivedIdx=4, dependentIdxs=[[0, 2], [1, 3]]), Derivation(derivedIdx=5, dependentIdxs=[[0, 3], [1, 2]])]

In the example above, the indicies of the design are:

idx

level

0

color:red

1

color:blue

2

text:red

3

text:blue

4

conFactor:con

5

conFactor:inc

So the tuple (4, [[0,2], [1,3]]) represents the information that the derivedLevel con is true iff (color:red && text:red) || (color:blue && text:blue) by pairing the relevant indices together.

Return type

returns a list of tuples. Each tuple is structured as: (index of the derived level, list of dependent levels)

Parameters

block (sweetpea.blocks.Block) –

static generate_argument_list(level, tup)
Parameters
Return type

List

static shift_window(indices, window, trial_size)

This is a helper function that shifts the indices of DerivationProcessor.generate_derivations().

E.g., if it’s a Transition(op.eq, [color, color]) (i.e., “repeat” color transition) then the indices for the levels of color would be like (0, 0), (1, 1), but actually, the window size for a transition is 2, so what we really want is the indices (0, 5), (1, 6) (assuming there are 4 levels in the design).

So this helper function shifts over indices that were meant to be interpreted as being in a subsequent trial.

Parameters
Return type

List[List[int]]