<commit_before>import logging, glob
import golem, psychic
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal

def logvar_feat(x):
  return np.log(np.var(x, axis=0))

def window(x):
  return x * np.hanning(x.shape[0]).reshape(-1, 1)

# Define preprocessing pipeline
preprocessing = golem.nodes.Chain([
  # Filter to beta range (8--30 Hz)
  psychic.nodes.Filter(lambda s : signal.iirfilter(6, [8./(s/2), 30./(s/2)])),
  # Extract 2 second window centered on key-press
  psychic.nodes.Slice({1:'left', 2:'right'}, [-.7, .7]),
  ])


def acc_crit(d, n):
  '''
  Performs 5-fold cross-validation of node n on dataset d, and returns mean
  accuracy. Used for model selection.
  '''
  return golem.loss.mean_std(golem.loss.accuracy,
    golem.cv.cross_validate(golem.cv.seq_splits(d, 5), n))[0]

pipeline = golem.nodes.Chain([
  golem.nodes.FeatMap(window),
  psychic.nodes.CSP(m=6),
  psychic.nodes.Whitening(),
  golem.nodes.FeatMap(logvar_feat),
  golem.nodes.SVM(C=1e5)])

# Setup logging levels
logging.basicConfig(level=logging.WARNING)
logging.getLogger('golem.nodes.ModelSelect').setLevel(logging.INFO)

# Load dataset (see also psychic.helpers.bdf_dataset for .bdf files)
d = golem.DataSet.load('S9.dat')

# Preprocess
preprocessing.train(d) # Required to calculate sampling rate<commit_msg>Simplified example again.<commit_after>import logging, glob
import golem, psychic
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal

def logvar_feat(x):
  return np.log(np.var(x, axis=0))

def window(x):
  return x * np.hanning(x.shape[0]).reshape(-1, 1)

# Define preprocessing pipeline
preprocessing = golem.nodes.Chain([
  # Filter to beta range (8--30 Hz)
  psychic.nodes.Filter(lambda s : signal.iirfilter(6, [8./(s/2), 30./(s/2)])),
  # Extract 2 second window centered on key-press
  psychic.nodes.Slice({1:'left', 2:'right'}, [-.7, .7]),
  ])

pipeline = golem.nodes.Chain([
  golem.nodes.FeatMap(window),
  psychic.nodes.CSP(m=6),
  golem.nodes.FeatMap(logvar_feat),
  golem.nodes.SVM(C=1e5)])

# Setup logging levels
logging.basicConfig(level=logging.WARNING)
logging.getLogger('golem.nodes.ModelSelect').setLevel(logging.INFO)

# Load dataset (see also psychic.helpers.bdf_dataset for .bdf files)
d = golem.DataSet.load('S9.dat')

# Preprocess
preprocessing.train(d) # Required to calculate sampling rate
{'fraction_non_alphanumeric': 0.14836795252225518, 'fraction_numerical': 0.019923696481559984, 'mean_word_length': 4.700483091787439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2314292', 'n_tokens_mistral': 879, 'n_tokens_neox': 870, 'n_words': 195}