diff --git a/py/.editorconfig b/py/.editorconfig new file mode 100644 index 0000000..5345e9e --- /dev/null +++ b/py/.editorconfig @@ -0,0 +1,6 @@ +[*] +charset=utf-8 +end_of_line=lf +insert_final_newline=true +indent_style=space +indent_size=4 diff --git a/py/.editorconfig b/py/.editorconfig new file mode 100644 index 0000000..5345e9e --- /dev/null +++ b/py/.editorconfig @@ -0,0 +1,6 @@ +[*] +charset=utf-8 +end_of_line=lf +insert_final_newline=true +indent_style=space +indent_size=4 diff --git a/py/even_random_generator.py b/py/even_random_generator.py index e69de29..ffa3c8a 100644 --- a/py/even_random_generator.py +++ b/py/even_random_generator.py @@ -0,0 +1,41 @@ + +class EvenRandomGenerator: + """Generate even random sequences according to a predefined TL ration (Ralph, 2014)""" + + def __init__(self, choices, trials=64, tl=1): + self.tl, self.trials, self.choices = tl, trials, choices + + def generate(self): + seq = self._generate_initial_sequence() + return self._optimize_sequence(seq) + + def _generate_initial_sequence(self): + """ + Generates initial sequence of items based on choices and number of desired trials. + In EvenRandom sequences, all stimuli have same number of appearances. + """ + num_of_each_choice = int(self.trials / len(self.choices)) + seq = [] + for c in self.choices: + seq.append([c for t in range(num_of_each_choice)]) + + # if it's too short, add some new items + if len(seq) < self.trials: + seq += [self.choices[-1] for t in range(self.trials-len(seq))] + + return seq + + def _optimize_sequence(self, seq): + """Optimize a sequence based on a desired tl ratio""" + # TODO optimize sequence according to the fitness function w/ Branch&Bound or evolutionary algorithms. + return seq + + @staticmethod + def calculate_tl_ratio(seq): + """Calculates the T:L ratio of a sequence.""" + # TODO + targets = 0 + for index, item in seq: + if item == seq[index-2]: + targets += 1 + return 1.0