Photo by israel palacio on Unsplash

Update: Read about part 2 of this project where I build a machine learning model to automatically detect ERP’s.

What if the computer could read your mind and knew exactly what you liked even better than you do? What if it could use this insight to compose original music that’s specifically tailored to your taste and what you want to hear in this moment? What if you could take a quick 10 minute test to screen for all sorts of psychiatric disorders in your own home to help your doctor diagnose you? These are the sorts of possibilities that make me excited about the combination of affordable EEG devices and machine learning/AI.

Photo by Robert Lukeman on Unsplash

It all started when I saw an advertisement for Muse, the “brain sensing headband.” It’s essentially a consumer grade EEG device that is intended for neurofeedback during meditation. The idea is, you wear it while meditating, it detects your brainwaves, and it transforms the signal into sounds that give you realtime feedback about how you’re doing. If your mind is very distracted you’ll hear thunder. If you manage to calm the mind more, you will hear gentle rain, then it will go quiet, and eventually you will hear birds singing, which is a sign you’re doing really well. As a Vipassana meditator, I approve, but as a machine learning engineer I am even more excited to get my hands on the raw EEG data to see what kind of insights can be extracted.

Photo by Robert Lukeman on Unsplash

The first thing I had to find out is, does this thing actually work? Is it really sensing the brain or is it some kind of elaborate placebo? I did my research, and the short answer is, yes it detects the brain with surprising accuracy. I found an excellent research paper from the Centre for Biomedical Research in University of Victoria which compared Muse against a research grade EEG system, which costs $75,000.

The results presented here clearly demonstrate that the MUSE EEG system can be used to conduct event-related brain potential (ERP) research from a single computer without the use of event-markers. […] Further, we note there that the time to complete both experimental tasks — including EEG setup — was done, on average, in less than 10 min. For comparison purposes, one must consider the task completion time with our large array ActiChamp system. […] the setup time and testing time with the MUSE was approximately one sixth of the setup and testing time with our large array system. Other points to consider here are the fact that large array systems typically require two (or more) research assistants vs. one with our MUSE setup and cost considerably more approximately $75,000 vs. $250 for the MUSE system Source: Choosing MUSE: Validation of a Low-Cost, Portable EEG System for ERP Research

Wow! This is a game changer. Often times, the most exciting technological progress comes when the price of existing technologies drops to be affordable to the masses. Think about personal computers and smart phones. It wasn’t until they became cheap, that they really changed the way we live. Of course, the expensive setup is more still accurate and has more electrodes, but if you give me something that’s 95% as good, easier to use, and literally 300 times cheaper, I’ll take that one, thank you very much.

So, as a first step I set out to try to replicate the above paper with my own brain scans, and I was surprised how easy it was. To understand this, you need to know what an Event Related Potential (ERP) is. An ERP is simply a specific pattern of voltages (hence potential) that can be measured in the brain immediately following some event. For example, reward positivity (RewP) is an ERP that happens when you get feedback on an action that is positive (e.g. you won a game). Feedback negativity is another ERP, when you get negative feedback on an action. Many other ERP’s have been studied that could potentially be useful. Since this paper uses RewP, I decided to try to detect it myself.

I needed to design and experiment to perform on myself to trigger RewP. Previous studies have used monetary reward to coax this out of subjects, but thankfully I found a study, which showed that RewP is present even without a monetary reward, if the subjects emotionally cares about the outcome. So, I decided I would record my brain while solving chess puzzles (I’m mildly-obsessed with chess, so I will care if I get it right), and I wrote quick Python script to record my mouse clicks with timestamps, so I can sync up the timing of the EEG data. I also recorded my screen, so I can label the mouse release timestamps with the outcome (whether I got it right or not). Here’s what RewP is supposed to look like (from the University of Victoria paper). Look at the darker line.

Average brain activations following feedback (positive or negative) recorded with Muse. Source: https://www.frontiersin.org/articles/10.3389/fnins.2017.00109/full#F6

And here are some of my EEG recordings immediately after I got a chess puzzle right.