HTM and automatic seizure detection using EEG data

Hi, Matt taylor

First of all, I am really appreciated for your lecture (HTM School). It helped me a lot.
I want to use HTM for automatic seizure detection using EEG data.
and there are some projects dealing with EEG data.

But I want to use not a single channel. To detect seizure, I have to use
many channels and I am going to use not a raw data but features include Power spectral density.

I don’t know how to use HTM for these. Do I have to use HTM regions for each features?
Then I need hundreds of regions…
Is there any encoder to dear with these input datas?

Thank you!

1 Like

I highly suggest you chat with @marion about her work with signal analysis and sequence classification with NuPIC. Feel free to have this conversation on the #nupic forum for others to join.

Hi @marion! It is very nice to talk with you!

I have already looked your presentation wich using EEG data to control quadrotors.
And also I have looked your github.

I am using EEG data but the objective of using HTM is different.
My objective is predicting seizure in advance and finding the location of seizure which is represented as channels. To detect seizure accurately, I have to use multi-channels and the features of multi-channels make contexts about brain activity.

The features I will use is power spectral density(PSD) of each channels with window. The relative power between channels and frequency bands. Because before seizure, the energy of low frequency bands moves to high frequency bands, so these information looks important to predict seizure.

The problem is that I don’t know how to use HTM for these. Do I have to use HTM regions for each features? or aggregate these features into one encoder(maybe scalar encoder)? Is there any encoder to dear with these input data?

I am still thinking about how to detect the location of seizure… and how to make robust detector that can be used to many patient.

Thank you!!

Hi @WoongWonLee,

My recommendation would be to create an HTM model (region) per channel and then use a multi-encoder that is setup in the following manner:

  • Chunk up your FFT or PSD in a couple of of frequency buckets
  • Feed each frequency bucket value to a scalar encoder
  • Feed the output of all these scalar encoders to a MultiEncoder

Then you can feed the output of the multi-encoder to the SP + TM. Repeat the process for each channel.

The setup of the multi-encoder is similar to what is described in the project ECG+HTM project. I recommend using the multi-encoder since the vector encoder described in the project is now deprecated in NuPIC.

Once you have a model (encoders + SP + TM) setup for for the output of each channel, you can look at various outputs like the raw anomaly score, anomaly likelihood or classification of Temporal Memory cell states (the SDRClassifier does that for example).

I am not sure if this will actually work for your use case, but one idea could be to look at the anomaly likelihood of each model (one model per channel) and see which ones appear anomalous. This might help you locating the channel position of the anomaly (seizure). I am not very knowledgeable about seizure detection in EEG so I am not sure if this part will work or if it is even relevant to your use case.

More info about the project that I was talking about:

I hope this information is useful.

Marion

1 Like

Thank you @marion

I am planning to use wavelet data first. As you said, I will use scalar encoders for each frequency and aggregate the outputs with a single multi-encoder.

I know this is hard problem to solve… there is no specific pattern for seizure and I think HTM is most accurate predictor for the seizure.

I will share the results to HTM forum!

Do you guys mind if I make this private message into a public forum post? I think others will be interested.

1 Like

Oh I will be pleased if you make this public!

I have two questions

1.
I have a question about multi-encoder.
Can you show me some examples using multi-encoder?
I don’t know how to use it.
I have set my multi-encoder in modelParams.py like this way.

“encoders”: {
“EEG”: {
“fieldname”: “EEG”,
“type”: “MultiEncoder”,
“encoderDescriptions”: {
“d3”: {
“resolution”: 1,
“fieldname”: “d3”,
“name”: “d3”,
“w”: 21,
“type”: “RandomDistributedScalarEncoder”
},
“d4”: {
“resolution”: 1,
“fieldname”: “d4”,
“name”: “d4”,
“w”: 21,
“type”: “RandomDistributedScalarEncoder”
}

And I run model like this

result = model.run({“EEG” : {“d3”: d3, “d4”:d4}})

But I have an error like this…

self._classifierInputEncoder = encoderList[self._predictedFieldIdx]
TypeError: list indices must be integers, not NoneType

I don’t know how to fix this

2.
What I want to do is predicting seizure.
There is pattern right before seizure. In the picture below, the red rectangular represents the preceding pattern of seizure. It is raw EEG data. I want to detect this.

So I exported short data which include the seizure and the preceding pattern and trained the HTM model with this data. Next, I turned the training off and adjust the HTM model to original data(full length).

I expected the anomaly score is high in the normal state in the data and low in seizure state. But the result was mass… It was not working like that… Below is anomaly score of the EEG data(one channel) and red rectangular is the preceding pattern of seizure

I can achieve my goal? Training the model for the preceding pattern before seizure and recognizing the pattern in any eeg data is wrong way to do this?

Hi @WoongWonLee,

First of all here is an example of a params file with multiple inputs:
http://pastebin.com/NuAFN24c
Each of the lines starting with u’ is another field, so just add another section like that for each input field you want to include (starting with the clipInput = True down until w = 21).

Here is the run.py file I use to run it:
http://pastebin.com/GT7SpLkG

From the raw EEG data you showed that looks like a single metric. It’s always ideal to keep it to a single metric if possible, and at least worth trying to begin with. From the look of that data, if you feed that metric right into NuPIC it would find that area you boxed in red as anomalous.

If you have enough data from the subject you’re trying to detect seizures in I don’t think you’d have to turn off learning. The algorithm learns continuously, so when the EEG values are near 0 as in the beginning it’ll learn that, then when it spikes up it will adjust to that and stop finding it as anomalous, and then when it returns to calm near 0 after it will adjust and get used to that again.

I would guess that the majority of the time the data will look calm like it does in the beginning, since people aren’t having seizures most of the time. If that’s the case NuPIC will be used to calmness and surprised by the seizure spikes. I’m just saying that you may have success with a simpler approach of one metric and learning continuously (without turning off training). If you don’t have enough data of the calmer non-seizure times that’s when I’d recommend turning off training after the normal times, to ensure it’ll be surprised by the seizure spikey times.

These are just my basic intuitions and could not be correct, hope it helps.

– Sam

Also I’d recommend look at the anomaly likelihood, which normalizes the anomaly score for noisier, less predictable data sets.

Hi, I want to try the some idea, do you have any good or bad results?