Newer
Older
notebooks / icom / nback_structure_extractor.py
# Note: install pyreadr package to read RData file
import pyreadr
import pandas as pd

dataset_file = '../data/CL2015.RData'


def count_targets(stimulus_types):
    print(stimulus_types)
    return 12  #stimulus_types[stimulus_types == 'target']


# read n-back dataset
datasets = pyreadr.read_r(dataset_file, use_objects="NB")
dataset = datasets["NB"]

# number of trials to look back for local regularities
window_size = 8

ps = dataset.group_by('participant')

ds = dataset[dataset.participant == 'P1']

x_tl = ds.stimulus_type.astype('category') \
    .rolling(window_size).apply(lambda x: x, raw=True)

print(x_tl.head())


#dataset \
#  .groupby(['participant','condition']) \

#group by participant and condition
#mark lures
# targets in the block (X_t column)
# lures in the block (X_l column)
# X_v
# recent targets (X_tl)
# recetnt