def _train_acc(self, df): resp_win = 5 # time window when a response is counted as correct resp = df.subj_resp.copy() resp[resp.isnull()] = 0 resp = np.array(resp) resp[resp == ''] = 0 count = 0 for i in range(resp_win): roll = np.roll(resp, -i) roll[len(roll) - i:] = 0 count += roll df['count'] = count df['accuracy'] = '' for idx, row in df.iterrows(): if row['count'] >= 1: subj_resp = 1 else: subj_resp = '' if row['corr_resp'] == '' or pandas.isnull(row['corr_resp']): corr_resp = '' else: corr_resp = row['corr_resp'] acc = exp.signal_det(corr_resp, subj_resp) if acc == 'false alarm': acc = '' df.loc[idx, 'accuracy'] = acc return df
def post_trial(self): this_resp = self.all_keys.pop() self.this_trial['subj_resp'] = self.computer.valid_responses[this_resp[0]] acc = exp.signal_det(self.this_trial['corr_resp'], self.this_trial['subj_resp']) self.this_trial['accuracy'] = acc self.this_trial['rt'] = this_resp[1] if acc == 'correct': acc_int = 1 else: acc_int = 0 self.staircase.addData(acc_int) return self.this_trial