def factor_variables_for_trial(self, f: Factor, t: int) -> List[int]: if not f.applies_to_trial(t): raise ValueError('Factor does not apply to trial #' + str(t) + ' f=' + str(f)) previous_trials = sum( map(lambda trial: 1 if f.applies_to_trial(trial + 1) else 0, range(t))) - 1 initial_sequence = list( map(lambda l: self.first_variable_for_level(f, l), list(filter(lambda l: (f, l) not in self.exclude, f.levels)))) offset = 0 if f.has_complex_window(): offset = len(f.levels) * previous_trials else: offset = self.variables_per_trial() * previous_trials return list(map(lambda n: n + offset + 1, initial_sequence))
def __trials_required_for_crossing(self, f: Factor, crossing_size: int) -> int: trial = 0 counter = 0 while counter != crossing_size: trial += 1 if f.applies_to_trial(trial): counter += 1 return trial
def factor_variables_for_trial(self, f: Factor, t: int) -> List[int]: """Given a factor and a trial number (1-based) this function will return a list of the variables representing the levels of the given factor for that trial. The variable list is also 1-based. """ if not f.applies_to_trial(t): raise ValueError('Factor does not apply to trial #' + str(t) + ' f=' + str(f)) previous_trials = sum(map(lambda trial: 1 if f.applies_to_trial(trial + 1) else 0, range(t))) - 1 initial_sequence = list(map(lambda l: self.first_variable_for_level(f, l), list(filter(lambda l: (f, l) not in self.exclude, f.levels)))) offset = 0 if f.has_complex_window: offset = len(f.levels) * previous_trials else: offset = self.variables_per_trial() * previous_trials return list(map(lambda n: n + offset + 1, initial_sequence))
def test_factor_applies_to_trial(): assert color.applies_to_trial(1) == True assert color.applies_to_trial(2) == True assert color.applies_to_trial(3) == True assert color.applies_to_trial(4) == True with pytest.raises(ValueError): color.applies_to_trial(0) assert color_repeats_factor.applies_to_trial(1) == False assert color_repeats_factor.applies_to_trial(2) == True assert color_repeats_factor.applies_to_trial(3) == True assert color_repeats_factor.applies_to_trial(4) == True f = Factor('f', [DerivedLevel('l', Window(op.eq, [color], 2, 2))]) assert f.applies_to_trial(1) == False assert f.applies_to_trial(2) == True assert f.applies_to_trial(3) == False assert f.applies_to_trial(4) == True assert color3.applies_to_trial(1) == True
def __trials_required_for_crossing(self, f: Factor, crossing_size: int) -> int: """Given a factor ``f``, and a crossing size, this function will compute the number of trials required to fully cross ``f`` with the other factors. For example, if ``f`` is a transition, it doesn't apply to trial 1. So when the ``crossing_size`` is ``4``, we'd actually need 5 trials to fully cross with ``f``. This is a helper for :class:`.MultipleCrossBlock.trials_per_sample`. """ trial = 0 counter = 0 while counter != crossing_size: trial += 1 if f.applies_to_trial(trial): counter += 1 return trial
def variables_for_factor(self, f: Factor) -> int: trial_list = range(1, self.trials_per_sample() + 1) return reduce( lambda sum, t: sum + len(f.levels) if f.applies_to_trial(t) else sum, trial_list, 0)
def variables_for_factor(self, f: Factor) -> int: """Indicates the number of variables needed to encode this factor.""" trial_list = range(1, self.trials_per_sample() + 1) return reduce( lambda sum, t: sum + len(f.levels) if f.applies_to_trial(t) else sum, trial_list, 0)