IntoMindLearn

Lab 4 · Middle school

Mind-Controlled Light Switch

Can you teach a computer to tell two of your own thoughts apart, well enough to switch a light?

Get ready

You need

  • An IntoMind One, charged, with its cable unplugged
  • A computer with Chrome or Edge
  • A chair for the wearer, in a quiet spot
  • A clean microfiber, soft cotton or eyeglass cloth

Roles

Wearer
Wears the IntoMind One, and rests or counts when the demo says.
Coach
Keeps the group quiet, and keeps time.
Recorder
Writes down the score, and counts the light's switches.
Skeptic
Watches the wearer, and writes down every blink, word or jaw clench, and when.

Take turns, so everyone who wants to can be the wearer. In a group of three, the coach is the skeptic too.

Rules

  • Unplug the cable before anyone puts it on.
  • Wearing it is your choice. Every role is a real one.
  • Wipe the electrodes between wearers with the soft cloth, since a rough one can scratch their gold coating.

Steps

  1. Put it on and connect

    The IntoMind One goes on the back of the head, a little above the bump where the skull meets the neck: the same place as in Alpha Flower. Alpha, which comes from the back of the brain, usually drops when you concentrate on counting, and that change is what this lab uses.

    Unplug the cable. The wearer sits down. Put it on with the strap around the head. Part the hair under each electrode so it touches skin, and press it down until it feels firm but not tight.

    Open the Mind-Controlled Light Switch demo, press Connect your IntoMind One, and choose yours from the list.

    You should seeConnected and the battery level at the top right, and the demo's line: Off is resting, On is a thought you hold.

  2. Teach it

    Press Start teaching. For about seven minutes, the demo shows Off or On.

    Off: rest with your eyes open, and let your mind wander. On: count down from 300 by sevens, in your head. Switch when the demo switches. A high beep marks On, a low beep marks Off, and the demo says each one aloud.

    You should seeEight rounds, Off and On in turn, with the readings in each round counted under the word on the screen.

  3. Read the score

    When teaching ends, the demo teaches a custom AI head: a small model of your own that tells your two states apart. Then it tests it on readings it held back.

    You should seeA line at the bottom left, like: “Tested on readings it held back: 60 of 88 right, clearly better than guessing.” If the score isn't clearly better than guessing, the line says it could be luck, and to teach it again or pick another thought for On.

  4. Run it

    PredictThe light will follow me of 10 switches.

    Press Run it on your IntoMind One. Your custom AI head now runs on the IntoMind One's own chip, and sends a score every few seconds: near 0 for Off, near 1 for On. The page compares each score with 0.5, and shows On or Off.

    The recorder calls ten switches, On, then Off, and counts how many times the light follows.

    WearerScore, of 88Clearly better than guessing?Predicted, of 10Light followed, of 10Skeptic's notes
    1
    2
    3
    4

    You should seeThe light on the board drawn in the demo turning on a few seconds after you switch to On, and off a few seconds after you rest.

  5. Save it

    Press Save, then Save the head, and rename the file with your name. It is your custom AI head, to put back on the IntoMind One in the Mind-Controlled Microcontroller.

    You should seeA file on your computer whose name starts with light-switch.

  6. Remove it, if your teacher asks

    Your custom AI head stays on your IntoMind One until it is removed or replaced. When your teacher wants the device clear, press Remove it from your IntoMind One, at the bottom right.

    You should seeRemoved. Your custom AI head stays on the page, to run or save again.

What happened

You taught a model, as in Models that learn. Every four seconds of your EEG was one example, labeled Off or On by what the demo told you to do. On the IntoMind One's chip, a model called the encoder turns each four seconds into 76 numbers, and your custom AI head learned what makes your Off numbers different from your On numbers.

The test was fair: the readings it was tested on were ones it never learned from, and its score was compared with guessing, which gets about half of 88, or 44.

The light changes a few seconds after you do, because each reading is four seconds of EEG. Your custom AI head never knows what you were thinking. It only learned what made two of your states look different.

Simulated Four seconds of EEG, the encoder on the IntoMind One's chip, the 76 numbers it makes, your custom AI head, its score, and the light, which is on while the score is above 0.5.

Talk about it

  1. What did your custom AI head learn from?

  2. Compare your score with guessing, 44 of 88. Did your custom AI head learn something real? How can you tell?

  3. The skeptic wrote down blinks and jaw clenches. Could those have fooled the custom AI head? How would you check?

Lab 4 · High school

Mind-Controlled Light Switch

Choose two mental states, and the place on the head where they should differ most. Can a model learn to tell them apart, and how will you know it isn't luck?

Background

Read it the night before.

Teaching a model your states

The demo teaches a classifier from labeled examples. Each example is four seconds of your EEG, summed up as 76 numbers by the IntoMind One's encoder, and labeled Off while you rest and On while you hold your On state. It collects them in eight rounds, Off and On in turn, eleven readings in each.

The model it fits is your custom AI head. To test it fairly, the demo teaches it eight times, each time holding back one round and testing on it, so each of the 88 readings is scored by a head that never learned from it. A whole round is held back, not single readings, because readings close together in time are alike.

Eight rounds Off and On in turn, with eleven readings kept in each. The two faint readings after every switch are left out while the brain settles. Each round in turn is held back and tested on: the outlined one is one of them.

Better than guessing?

With two states taught equally, guessing gets about half right: 44 of 88 readings. A score is evidence only when it is clearly above that, and the demo works out how far above is clear, by teaching and testing a fresh head on each of the 70 ways to relabel the rounds.

Blinks, talking and a clenched jaw make large signals that aren't from the brain. If one state has more of them, they can raise the score for the wrong reason.

Guessing How often a guesser gets each number of 88 readings right. Most often about 44, and 53 or more, in orange, about 3.5 times in 100.

Choose your states, and where they show

Each mental state changes the signal most over one part of the brain, so you choose your two states and the site together.

A fist, made or just imagined, changes the mu rhythm over the motor cortex on the opposite side of the brain from the hand. So a right fist shows at C3, on the left, about three fifths of the way from the left ear up to the top of the head.

The sites From above, with the motor cortex and the language areas shaded. The IntoMind One is drawn at C3, over the motor cortex for the right hand.
Your two statesSiteWhy there
Resting, and counting down in your headOzAlpha, from the visual areas at the back, usually drops when you concentrate.
Eyes open, and eyes closedOzAlpha rises strongly with the eyes closed, as in Alpha Flower: the surest pair.
Resting, and a right fist, made or imaginedC3The mu rhythm over the left motor cortex drops when the right hand moves, or imagines moving.
Left fist, and right fistC3, then C4Each side of the brain controls the opposite hand. Teach at C3, then test the same head at the mirror site, C4.
Resting, and saying a word in your headLeft side, just above the earMost people's language areas are on the left. Inner speech is weak in EEG, so a score near chance is a real result.
Any pairFpzNo hair, so contact is easy. But blinks are largest there, and a head can learn them instead of your states.

Get ready

You need

  • An IntoMind One, charged, with its cable unplugged
  • A computer with Chrome or Edge
  • A chair for the wearer, in a quiet spot
  • A clean microfiber, soft cotton or eyeglass cloth

Roles

Wearer
Wears the IntoMind One, and holds Off or On when the demo says.
Coach
Keeps the group quiet, and keeps time.
Recorder
Writes down the score, and counts the light's switches.
Skeptic
Watches the wearer, and writes down every blink, word or jaw clench, and the round it happened in.

Take turns, so everyone who wants to can be the wearer. In a group of three, the coach is the skeptic too.

Rules

  • Unplug the cable before anyone puts it on.
  • Wearing it is your choice. Every role is a real one.
  • Wipe the electrodes between wearers with the soft cloth, since a rough one can scratch their gold coating.

Steps

  1. Choose your states and site

    Our choiceOff: . On: . Site: , because .

    In every pair but eyes open and closed, do both states with your eyes open, in the same posture, so that the only difference is the one you chose.

  2. Put it on and connect

    A head from behind, with an orange area over Oz.A head from behind, with an orange area over Oz.Oz
    A head from its left side, with an orange area over C3, above the ear.A head from its left side, with an orange area over C3, above the ear.C3
    A head from the front, with an orange area over Fpz, on the forehead.A head from the front, with an orange area over Fpz, on the forehead.Fpz

    Put the IntoMind One at your site: on the midline just above the inion for Oz, or for C3, on the line over the top of the head from ear to ear, about three fifths of the way from the left ear up to the top. Unplug the cable first. Part the hair under each electrode, and press it down until it feels firm but not tight.

    Open the Mind-Controlled Light Switch demo, press Connect your IntoMind One, and choose yours from the list.

    You should seeConnected and the battery level at the top right, and the demo's line: Off is resting, On is a thought you hold.

  3. Teach it

    Press Start teaching. For about seven minutes the demo shows Off or On. Hold your Off state or your On state, and switch when the demo switches. A high beep marks On, a low beep marks Off, and the demo says each one aloud.

    You should seeEight rounds, Off and On in turn, with the readings in each round counted under the word on the screen.

  4. Read the score

    When teaching ends, the demo tests your custom AI head on readings it held back, a round at a time, then fits it on all 88.

    You should seeA line at the bottom left, like: “Tested on readings it held back: 60 of 88 right, clearly better than guessing.” If the score isn't clearly better, the line says it could be luck, and to teach again or choose another state for On.

  5. Run it

    PredictThe light will follow me of 10 switches.

    Press Run it on your IntoMind One. Your custom AI head now runs on the IntoMind One's own chip, and sends a score every few seconds: near 0 for Off and near 1 for On, and sometimes a little outside. The page compares each score with 0.5, and shows On or Off. The recorder calls ten switches, and counts how many times the light follows.

    You should seeThe light on the board drawn in the demo turning on a few seconds after you switch to On, and off a few seconds after you switch back.

  6. Test the mirror site

    PredictAt the mirror site, the light will follow me of 10 switches.

    For a fist pair. Keep the head running, move the IntoMind One to the mirror site, C4 for a head taught at C3, part the hair and press it down, and call ten switches again, the same way. Then put it back at the taught site.

    You should seeFor most people, the light following fewer of the ten at the mirror site.

  7. Save it

    Press Save. Save the head, to install it again later, for example in the Mind-Controlled Microcontroller, and rename its file with your name. Save the training data, to analyze it.

    You should seeTwo files on your computer: the head, and the training data. The training data comes from your EEG, so it is yours to keep or delete.

  8. Record it

    WearerStates and siteScore, of 88Clearly better than guessing?Light followed, of 10Mirror site, of 10Skeptic's notes
    1
    2
    3
    4
  9. Remove it, if your teacher asks

    Your custom AI head stays on your IntoMind One until it is removed or replaced. When your teacher wants the device clear, press Remove it from your IntoMind One, at the bottom right.

Work it out

Work it outOur best score minus 44, the guessing score: . The demo's verdict: . For a fist pair, the light followed of 10 at the taught site, and of 10 at the mirror site.

Talk about it

  1. Why does the demo alternate between Off and On over eight rounds, instead of doing all the Off first?

  2. Why would testing on the readings it trained on give a score that looks better than it is?

  3. Two wearers scored 61 and 79 out of 88. Give two reasons they might differ that aren't about their brains.

  4. Would eyes closed against eyes open separate better than resting against counting? Predict, then explain.

  5. A head taught at C3 with the right fist as On followed 8 of 10 switches there, and 5 of 10 at C4. What does that show? What would 8 of 10 at C4 have shown?

Sources

Pfurtscheller, G., and Lopes da Silva, F. H. (1999). Event-related EEG/MEG synchronization and desynchronization: basic principles. Clinical Neurophysiology.

Panachakel, J. T., and Ramakrishnan, A. G. (2021). Decoding covert speech from EEG: a comprehensive review. Frontiers in Neuroscience.

Combrisson, E., and Jerbi, K. (2015). Exceeding chance level by chance: the caveat of theoretical chance levels in brain signal classification and statistical assessment of decoding accuracy. Journal of Neuroscience Methods.

Wolpaw, J. R., and Wolpaw, E. W., editors (2012). Brain-Computer Interfaces: Principles and Practice. Oxford University Press.

Lab 5 · College

Mind-Controlled Light Switch

Choose two mental states and the site where they should differ most. Can a regularized linear model on the encoder's embeddings tell them apart on rounds it never saw, beyond what relabeling the rounds gives, and does it still work at the mirror site?

Background

Read it before the lab.

The pipeline

Every four seconds the encoder turns the EEG into 76 numbers. While you teach, the demo labels each embedding Off or On by the cue on screen, drops the two readings after every switch, which still carry the old state, and drops any reading whose four seconds had a gap. Eight rounds, Off and On in turn, keep eleven readings each: 88.

Your browser fits ridge regression from the 76 numbers to the labels, with λ from the embeddings alone, scores it by holding out each round in turn, rounds the weights to bytes, and installs the custom AI head on the IntoMind One, which sends a score every four seconds. The page, or a board, compares it with 0.5.

Simulated Four seconds of EEG, the encoder on the chip, its 76 numbers, your custom AI head, its score, and the light, on while the score is above 0.5.

States and sites

Each state changes the signal most over one part of the cortex, so you choose the pair and the site together. A fist, made or imagined, desynchronizes the mu rhythm over the motor cortex opposite the hand: C3 for the right hand. Taught at C3, a head that learned one hemisphere's change should fall toward chance at the mirror site, C4.

The sites From above, with the motor cortex and the language areas shaded. The IntoMind One is drawn at C3, over the motor cortex for the right hand.
Your two statesSiteWhy there
Resting, and counting down in your headOzOccipital alpha usually falls with concentration.
Eyes open, and eyes closedOzAlpha rises strongly with the eyes closed: the surest pair.
Resting, and a right fist, made or imaginedC3The mu rhythm over the left motor cortex falls with the right hand's movement, or its imagined movement.
Left fist, and right fistC3, then C4Each hemisphere controls the opposite hand. Teach at C3, then test the same head at the mirror site.
Resting, and a word in your headLeft side, just above the earMost people's language areas are on the left. Inner speech is weak in EEG, and decoding it sits near chance.
Any pairFpzThe easiest contact, and the largest blinks, which a head can learn in place of the states.

Against chance

Judged as 88 independent tries, a one-sided binomial test draws its 0.05 line at 53 right. But readings in a round share a state, a posture and a stretch of time, so the binomial overstates the evidence. The demo instead scores every one of the C(8, 4) = 70 ways to call four rounds On, with the same folds. Since a labeling and its mirror score alike, p can't go below 2/70, and the demo calls a score clearly better than guessing when p is below 0.05.

70 labelings Every way of calling four of the eight rounds On. Each is scored like the taught one, outlined with its mirror.

Hypothesis

Write it before the wearer sits down.

HypothesisOff: . On: . Site: , because . The head will get about of 88 right on rounds it never saw, and for a fist pair, follow of 10 switches at the mirror site.

Get ready

You need

  • An IntoMind One, charged, with its cable unplugged
  • A computer with Chrome or Edge, Python 3 with the intomind package, and the demos' source
  • A chair for the wearer, in a quiet spot, and a stopwatch
  • A clean microfiber, soft cotton or eyeglass cloth

Roles

Wearer
Wears the IntoMind One, and holds Off or On when the demo says.
Operator
Runs the demo, calls the switches and times the light.
Analyst
Notes anything that could leak into the labels: blinks, movement, talking, a missed cue, and the round it happened in.

Rotate, so everyone who wants to is the wearer once.

Rules

  • Unplug the cable before anyone puts it on.
  • Wearing it is your choice. Every role is a real one.
  • Saved training data comes from someone's EEG. Keep it only with their permission.
  • Wipe the electrodes between wearers with the soft cloth, since a rough one can scratch their gold coating.

Procedure

  1. Put it on at your site

    A head from behind, with an orange area over Oz.A head from behind, with an orange area over Oz.Oz
    A head from its left side, with an orange area over C3, above the ear.A head from its left side, with an orange area over C3, above the ear.C3
    A head from the front, with an orange area over Fpz, on the forehead.A head from the front, with an orange area over Fpz, on the forehead.Fpz

    Oz is on the midline just above the inion. C3 is on the line from ear to ear over the top of the head, three fifths of the way from the left ear up to the top. Unplug the cable, part the hair under each electrode, and press it down until it feels firm but not tight. Open the Mind-Controlled Light Switch demo and connect.

  2. Teach it

    Press Start teaching. For about seven minutes the demo shows Off or On, with a high beep for On and a low one for Off. Hold your state, and switch when the demo switches. In every pair but eyes open and closed, keep the eyes open and the posture the same in both states.

    You should seeEight rounds, Off and On in turn, with the readings in each round counted under the word on the screen.

  3. Read the score

    When teaching ends, your browser fits the head and tests it on each round held back in turn.

    You should seeA line at the bottom left: how many of the 88 readings it got right on rounds it never saw, and whether that is clearly better than guessing.

  4. Run it, and time it

    Press Run it on your IntoMind One. The operator calls ten switches at random times, and times each one from the call to the light. For a fist pair, then move the IntoMind One to the mirror site, C4 for a head taught at C3, and call ten more.

    You should seeThe light on the board drawn in the demo following a few seconds behind, and for most fist pairs, following fewer of the ten at the mirror site.

  5. Save it, and record it

    Press Save: the head, renamed with the wearer's number, and the training data, for the analysis.

    WearerStates and siteScore, of 88Demo's verdictLight followed, of 10Mirror site, of 10Analyst's notes
    1
    2
    3
  6. Remove it, if your instructor asks

    A custom AI head stays on the IntoMind One until it is removed or replaced. Press Remove it from your IntoMind One, or run python3 remove_head.py from the demos' source.

Analysis

First, reproduce one head from its training data with the demos' Python program, and check it matches the one the browser saved, byte for byte. Then, on your own training data, measure what random folds would have claimed, and run the permutation test over rounds yourself.

cd python
python3 teach_it.py --from training-data.json --out reproduced.imh
cmp reproduced.imh the-head-you-saved.imh && echo identical
import json
from itertools import combinations
import numpy as np

data = json.load(open("training-data.json"))      # the training data the demo saved
X = np.array([w["embedding"] for w in data["windows"]], float)
y = np.array([w["label"] for w in data["windows"]], float)
round_of = np.array([w["round"] for w in data["windows"]])

def fit(X, y):
    """Ridge with the trainer's λ, from the embeddings alone, and no penalty on the intercept."""
    Xc = X - X.mean(axis=0)
    ev = np.linalg.eigvalsh(Xc.T @ Xc)
    lam = np.sqrt(max(ev[0], 1) * ev[1])
    A = np.c_[X, np.ones(len(X))]
    P = lam * np.eye(A.shape[1])
    P[-1, -1] = 0
    return np.linalg.solve(A.T @ A + P, A.T @ y)

def right(X, y, folds):
    """Readings right when each fold is held out in turn."""
    n = 0
    for test in folds:
        train = np.setdiff1d(np.arange(len(y)), test)
        w = fit(X[train], y[train])
        n += np.sum((np.c_[X[test], np.ones(len(test))] @ w > 0.5) == y[test])
    return int(n)

rounds = np.unique(round_of)
by_round = [np.flatnonzero(round_of == r) for r in rounds]
shuffled = np.array_split(np.random.default_rng(0).permutation(len(y)), len(rounds))
real = right(X, y, by_round)
print("random folds:", right(X, y, shuffled), "of", len(y))
print("a round held out at a time:", real, "of", len(y))

# Every way of calling as many rounds On as were taught, scored the same way.
taught_on = [r for r in rounds if y[round_of == r][0] == 1]
null = [right(X, np.isin(round_of, on).astype(float), by_round)
        for on in combinations(rounds, len(taught_on))]
print("p over", len(null), "labelings:", round(np.mean(np.array(null) >= real), 3))
WearerRandom folds, of 88A round held out, of 88Your p, of 70 labelingsThe demo's verdict
1
2
3

Report

  1. The question, and your states, site and hypothesis as you wrote them first.
  2. Methods: the pipeline, the ridge and its λ, the folds, and the permutation test.
  3. Results: each wearer's score against chance, your p beside the demo's verdict, random folds against held-out rounds, the timed switches, and the mirror test.
  4. Interpretation: which pairs separated and why, what the mirror test says about where the head's evidence comes from, and what leaked.
  5. Limitations: one session, 88 readings for 77 parameters, the analyst's notes, and contact at each site.
  6. Your code, as an appendix.

Problems

  1. With 88 readings and a 76-dimensional embedding, what does the ridge do, and what happens without it?

  2. Why are the tests whole rounds rather than readings drawn at random?

  3. Under a binomial test against a chance of one half, how many of 88 must be right for a one-sided p below 0.05? What does it assume that this data breaks?

  4. The head is rounded to signed bytes before it runs on the device. How would you measure what that changes?

  5. Make the mirror test fair. What must be the same at both sites, and what confounds it?

Sources

Pfurtscheller, G., and Lopes da Silva, F. H. (1999). Event-related EEG/MEG synchronization and desynchronization: basic principles. Clinical Neurophysiology.

McFarland, D. J., Miner, L. A., Vaughan, T. M., and Wolpaw, J. R. (2000). Mu and beta rhythm topographies during motor imagery and actual movements. Brain Topography.

Panachakel, J. T., and Ramakrishnan, A. G. (2021). Decoding covert speech from EEG: a comprehensive review. Frontiers in Neuroscience.

Combrisson, E., and Jerbi, K. (2015). Exceeding chance level by chance: the caveat of theoretical chance levels in brain signal classification and statistical assessment of decoding accuracy. Journal of Neuroscience Methods.

Varoquaux, G., and others (2017). Assessing and tuning brain decoders: cross-validation, caveats, and guidelines. NeuroImage.

Wolpaw, J. R., and Wolpaw, E. W., editors (2012). Brain-Computer Interfaces: Principles and Practice. Oxford University Press.

Lab 5 · Graduate

Mind-Controlled Light Switch

Can a linear head on the encoder's embeddings tell two of your states apart on rounds it never saw, does the demo's test of that hold up, and does the head still work on another day?

The demo, exactly

PartWhat it doesSource
TeachingEight rounds, Off and On in turn, starting with Off, cued by a word and a beep, high for On. Each keeps 11 embeddings, one every four seconds, after dropping the 2 after each switch and any with a gap in the signal: 88 in about seven minutes.light-switch/main.js
The fitRidge regression of the labels, 0 and 1, on the embeddings as integers, the intercept unpenalized, its penalty the geometric mean of the two smallest eigenvalues of the centered Gram matrix. Refused unless there are more embeddings than 76.lib/train.js
The headWeights rounded to signed bytes against the largest, the bias in the same units: 156 bytes, installed in slot 2.lib/train.js
The scoreEight folds of one round each. Every labeling of four rounds On, 70 in all, scored with the same folds by heads rounded as the device runs them. Clearly better than guessing when the share scoring at least as well is under 0.05, which can't fall below 2/70.lib/train.js
RunningThe device scores every window, and the light follows each score above or below 0.5. A window with a gap leaves it as it was.light-switch/main.js
SavingThe head, and the training data: every kept embedding with its round and label, the states and the encoder's identity, as JSON. The Python program teach_it.py rebuilds the same head from it, byte for byte.lib/train.js, python/teach_it.py

What it leaves out: any second day, since a head is taught and tested within one session. A penalty chosen for prediction rather than for stability, with 77 windows to fit 76 weights in every fold. And any check on what the head learned: blinks, muscle and posture that change with the state are as learnable as the state.

States and sites

Each state changes the signal most over one part of the cortex, so the pair and the site are chosen together. A fist, made or imagined, desynchronizes the mu and beta rhythms over the motor cortex opposite the hand (Pfurtscheller and Lopes da Silva, 1999): C3 for the right hand. Taught at C3, a head that learned one hemisphere's change should fall toward chance at the mirror site, C4. Inner speech is weak in EEG, and decoding it sits near chance (Panachakel and Ramakrishnan, 2021).

Between days the embeddings move: contact, posture, alertness and the electrodes' exact place all change, and a head fitted on one session meets a shifted distribution on the next (Shenoy and others, 2006). Removing each session's mean before fitting and applying is the simplest correction, a Euclidean cousin of re-centering covariance matrices (Zanini and others, 2018).

The sites From above, with the motor cortex and the language areas shaded. The IntoMind One is drawn at C3, over the motor cortex for the right hand.
Your two statesSiteWhy there
Resting, and counting down in your headOzOccipital alpha usually falls with concentration.
Eyes open, and eyes closedOzAlpha rises strongly with the eyes closed: the surest pair.
Resting, and a right fist, made or imaginedC3The mu rhythm over the left motor cortex falls with the right hand's movement, or its imagined movement.
Left fist, and right fistC3, then C4Each hemisphere controls the opposite hand. Teach at C3, then test the same head at the mirror site.
Resting, and a word in your headLeft side, just above the earMost people's language areas are on the left. Inner speech is weak in EEG, and decoding it sits near chance.
Any pairFpzThe easiest contact, and the largest blinks, which a head can learn in place of the states.

Preregister

Fill it in before the first session, and change nothing after. The report names every deviation.

ItemYour plan, before any data
States and site, and why
Hypotheses: each session's score, the transfer to the second day, and the mirror site for a fist pair
Penalties and tests, and what would count against each hypothesis
Exclusions: missed cues, blinks or movement noted, contact
Controls: how you will tell the state from what comes with it

Get ready

You need

  • An IntoMind One, charged, with its cable unplugged
  • A computer with Chrome or Edge, Python 3 with the intomind package, and the demos' source
  • A chair for the wearer, in a quiet spot, and a stopwatch
  • A clean microfiber, soft cotton or eyeglass cloth

Roles

Wearer
Wears the IntoMind One, and holds Off or On when the demo says.
Operator
Runs the demo, calls the switches and times the light.
Analyst
Notes anything that could leak into the labels: blinks, movement, talking, a missed cue, and the round it happened in.

Rotate, so everyone who wants to is the wearer once.

Rules

  • Unplug the cable before anyone puts it on.
  • Wearing it is your choice. Every role is a real one.
  • Saved training data comes from someone's EEG. Keep it only with their permission.
  • Wipe the electrodes between wearers with the soft cloth, since a rough one can scratch their gold coating.

Procedure

  1. Session 1: put it on at your site

    A head from behind, with an orange area over Oz.A head from behind, with an orange area over Oz.Oz
    A head from its left side, with an orange area over C3, above the ear.A head from its left side, with an orange area over C3, above the ear.C3
    A head from the front, with an orange area over Fpz, on the forehead.A head from the front, with an orange area over Fpz, on the forehead.Fpz

    Oz is on the midline just above the inion. C3 is on the line from ear to ear over the top of the head, three fifths of the way from the left ear up to the top. Unplug the cable, part the hair under each electrode, and press it down until it feels firm but not tight. Open the Mind-Controlled Light Switch demo and connect.

  2. Teach it

    Press Start teaching. For about seven minutes the demo shows Off or On. Hold your state, and switch when the demo switches. In every pair but eyes open and closed, keep the eyes open and the posture the same in both states.

    You should seeEight rounds, Off and On in turn, then a line at the bottom left: how many of the 88 readings the head got right on rounds it never saw, and whether that is clearly better than guessing.

  3. Run it, and time it

    Press Run it on your IntoMind One. The operator calls ten switches at random times and times each from the call to the light. For a fist pair, move the IntoMind One to the mirror site and call ten more.

    You should seeThe light following a few seconds behind, if the head works, and for most fist pairs following fewer at the mirror site.

  4. Probe it

    Still running, with the wearer holding Off, the operator asks for three bursts of blinking, a jaw clench, and a slow look left and right, ten seconds apart. The analyst counts how often the light turns on.

  5. Save it

    Press Save: the head and the training data. Rename both with the wearer's number and the session, as w1-session1.

  6. Session 2: the same site, another day

    At least a day later, put the IntoMind One on at the same site, connect, and press Install a saved head to put session 1's head back on. Run it, and call ten switches as before.

    You should seeHow well yesterday's head follows today's states.

  7. Teach it again

    Press Teach again for a second session's 88 readings, and save the training data and the head as w1-session2. The new head replaces the old one on the IntoMind One.

  8. Record it

    Each wearer's results, from the demo and the stopwatch, and then remove the heads if your instructor asks: Remove it from your IntoMind One, or python3 remove_head.py.

    WearerStates and siteSession 1, of 88Light followed, of 10Probes that switched itYesterday's head today, of 10Session 2, of 88
    1
    2
    3

Analyses

First, reproduce a head from its training data with the demos' Python program, and check it matches the one saved, byte for byte. Then, for each wearer: each session's held-out score against its 70 relabelings with the demo's penalty and with a heavier one that also uses no labels, session 1's head on session 2 with and without each session's mean removed, and how far the sessions moved compared with the states.

cd python
python3 teach_it.py --from w1-session1.json --out reproduced.imh
cmp reproduced.imh w1-session1.imh && echo identical
import json
from itertools import combinations
import numpy as np

def load(path):
    """A training file the demo saved: embeddings as integers, labels, and rounds."""
    w = json.load(open(path))["windows"]
    X = np.array([v["embedding"] for v in w], float)
    return X, np.array([v["label"] for v in w], float), np.array([v["round"] for v in w])

def penalty(X, rule):
    """Both use no labels: "gap" is the demo's, "mean" the Gram matrix's mean eigenvalue."""
    ev = np.linalg.eigvalsh((X - X.mean(0)).T @ (X - X.mean(0)))
    return np.sqrt(max(ev[0], 1) * ev[1]) if rule == "gap" else ev.mean()

def fit(X, y, rule):
    """Ridge with the intercept unpenalized: the weights and the intercept."""
    m = X.mean(0)
    xc = X - m
    lam = penalty(X, rule)
    w = np.linalg.solve(xc.T @ xc + lam * np.eye(X.shape[1]), xc.T @ (y - y.mean()))
    return w, y.mean() - m @ w

def held_out(X, y, r, rule):
    """Readings right with each round held out in turn."""
    right = 0
    for k in np.unique(r):
        w, b = fit(X[r != k], y[r != k], rule)
        right += np.sum((X[r == k] @ w + b > 0.5) == (y[r == k] == 1))
    return right

def relabelings(y, r):
    """Every labeling of the rounds with as many On as were taught: 70 for 4 of 8."""
    rounds = np.unique(r)
    on = sum(y[r == k][0] for k in rounds)
    return [np.isin(r, c).astype(float) for c in combinations(rounds, int(on))]

s1, s2 = load("w1-session1.json"), load("w1-session2.json")     # the files you saved
for rule in ("gap", "mean"):
    for name, (X, y, r) in (("session 1", s1), ("session 2", s2)):
        real = held_out(X, y, r, rule)
        p = np.mean([held_out(X, z, r, rule) >= real for z in relabelings(y, r)])
        print(f"{rule:4s} {name}: {real} of {len(y)} on held-out rounds, p {p:.3f}")
    # Transfer: the head from all of session 1, on all of session 2, against its relabelings.
    for recenter in (False, True):
        (X1, y1, _), (X2, y2, r2) = s1, s2
        if recenter:                        # each session's own mean, which uses no labels
            X1, X2 = X1 - X1.mean(0), X2 - X2.mean(0)
        w, b = fit(X1, y1, rule)
        hit = lambda z: np.sum((X2 @ w + b > 0.5) == (z == 1))
        p = np.mean([hit(z) >= hit(y2) for z in relabelings(y2, r2)])
        print(f"{rule:4s} session 1's head on session 2{', recentered' if recenter else ''}: "
              f"{hit(y2)} of {len(y2)}, p {p:.3f}")

(X1, y1, _), (X2, y2, _) = s1, s2
shift = np.linalg.norm(X2.mean(0) - X1.mean(0))
states = np.linalg.norm(X1[y1 == 1].mean(0) - X1[y1 == 0].mean(0))
print(f"the sessions' means are {shift:.0f} apart, "
      f"the two states' means within session 1 {states:.0f}")

Then report:

  1. Each session's score and p with both penalties, and why a score below 44 of 88 can still have a small p.
  2. The transfer, raw and recentered, against each session's own held-out score.
  3. The probes and the mirror site: what the head responds to besides the state.
  4. For the class: which pairs and sites held up on a second day.

Open problems

  1. Another day. Nonstationarity between sessions is among the main obstacles to everyday use of noninvasive interfaces (Shenoy and others, 2006). How to keep a head working without teaching it again is open.
  2. Who can't. For some people a decoder never separates the states, which has been called BCI illiteracy (Vidaurre and Blankertz, 2010). Thompson (2019) argues the term puts on the person a failure of the method, and how to design for everyone is open.
  3. The body in the signal. Telling a state from the blinks, muscle and posture that come with it, without many channels or other sensors, is unsolved, and a high score doesn't settle it.

Report

  1. The preregistration as written, and every deviation from it, each with its reason.
  2. Methods: the states, the site, both sessions, the penalties and the tests.
  3. Results for each wearer: both sessions' scores and p values, the transfer raw and recentered, the timed switches, the probes, and the mirror site where used.
  4. What the head learned, as far as the controls can say.
  5. The code, with the reproduced head's check.

Sources

Pfurtscheller, G., and Lopes da Silva, F. H. (1999). Event-related EEG/MEG synchronization and desynchronization: basic principles. Clinical Neurophysiology.

Shenoy, P., Krauledat, M., Blankertz, B., Rao, R. P. N., and Müller, K.-R. (2006). Towards adaptive classification for BCI. Journal of Neural Engineering.

Vidaurre, C., and Blankertz, B. (2010). Towards a cure for BCI illiteracy. Brain Topography.

Zanini, P., Congedo, M., Jutten, C., Said, S., and Berthoumieu, Y. (2018). Transfer learning: a Riemannian geometry framework with applications to brain-computer interfaces. IEEE Transactions on Biomedical Engineering.

Thompson, M. C. (2019). Critiquing the concept of BCI illiteracy. Science and Engineering Ethics.

Panachakel, J. T., and Ramakrishnan, A. G. (2021). Decoding covert speech from EEG: a comprehensive review. Frontiers in Neuroscience.