MCPcopy Create free account
hub / github.com/brain-workshop/brainworkshop / generate_stimulus

Function generate_stimulus

brainworkshop.py:4146–4359  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4144player2 = get_pyglet_media_Player()
4145# responsible for the random generation of each new stimulus (audio, color, position)
4146def generate_stimulus():
4147 # first, randomly generate all stimuli
4148 positions = random.sample(range(1,9), 4) # sample without replacement
4149 for s, p in zip(range(1, 5), positions):
4150 mode.current_stim['position' + repr(s)] = p
4151 mode.current_stim['vis' + repr(s)] = random.randint(1, 8)
4152
4153 #mode.current_stim['position1'] = random.randint(1, 8)
4154 mode.current_stim['color'] = random.randint(1, 8)
4155 mode.current_stim['vis'] = random.randint(1, 8)
4156 mode.current_stim['audio'] = random.randint(1, 8)
4157 mode.current_stim['audio2'] = random.randint(1, 8)
4158
4159
4160 # treat arithmetic specially
4161 operations = []
4162 if cfg.ARITHMETIC_USE_ADDITION: operations.append('add')
4163 if cfg.ARITHMETIC_USE_SUBTRACTION: operations.append('subtract')
4164 if cfg.ARITHMETIC_USE_MULTIPLICATION: operations.append('multiply')
4165 if cfg.ARITHMETIC_USE_DIVISION: operations.append('divide')
4166 mode.current_operation = random.choice(operations)
4167
4168 if cfg.ARITHMETIC_USE_NEGATIVES:
4169 min_number = 0 - cfg.ARITHMETIC_MAX_NUMBER
4170 else:
4171 min_number = 0
4172 max_number = cfg.ARITHMETIC_MAX_NUMBER
4173
4174 if mode.current_operation == 'divide' and 'arithmetic' in mode.modalities[mode.mode]:
4175 if len(stats.session['position1']) >= mode.back:
4176 number_nback = stats.session['numbers'][mode.trial_number - mode.back - 1]
4177 possibilities = []
4178 for x in range(min_number, max_number + 1):
4179 if x == 0:
4180 continue
4181 if number_nback % x == 0:
4182 possibilities.append(x)
4183 continue
4184 frac = Decimal(abs(number_nback)) / Decimal(abs(x))
4185 if (frac % 1) in map(Decimal, cfg.ARITHMETIC_ACCEPTABLE_DECIMALS):
4186 possibilities.append(x)
4187 mode.current_stim['number'] = random.choice(possibilities)
4188 else:
4189 mode.current_stim['number'] = random.randint(min_number, max_number)
4190 while mode.current_stim['number'] == 0:
4191 mode.current_stim['number'] = random.randint(min_number, max_number)
4192 else:
4193 mode.current_stim['number'] = random.randint(min_number, max_number)
4194
4195 multi = mode.flags[mode.mode]['multi']
4196
4197 real_back = mode.back
4198 if mode.flags[mode.mode]['crab'] == 1:
4199 real_back = 1 + 2*((mode.trial_number-1) % mode.back)
4200 else:
4201 real_back = mode.back
4202 if cfg.VARIABLE_NBACK:
4203 real_back = mode.variable_list[mode.trial_number - real_back - 1]

Callers 1

updateFunction · 0.85

Calls 1

spawnMethod · 0.80

Tested by

no test coverage detected