Proyecto

General

Perfil

Detecting normal EKG pulses » Histórico » Versión 5

Federico Vera, 2018-07-12 06:03

1 1 Federico Vera
# Application Example
2
3 5 Federico Vera
{{>toc}}
4
5 1 Federico Vera
## Detecting normal EKG pulses.
6
7 2 Federico Vera
I will not enter into too much detail in this text in an attempt to _trick_ the reader (you) into doing some research. But the basic idea is to train an MLP and then use the results to try and deduce if a Pulse is normal or not (the same approach can be used to detect specific pathologies).
8 1 Federico Vera
9 2 Federico Vera
This is **not** the usual approach which usually includes extracting features like the a<sub>k</sub>s of the Fourier Transform, eigenvalues, and such. The approach that will be described in this example is much simpler (albeit it has a less accurate result... _or does it?_)
10 1 Federico Vera
11
## About the EKG
12 2 Federico Vera
EKGs or ECGs (whichever you like) is basically a set of five (three, five or six) different signals or _derivations_. Most of the bibliographic information and cardiological knowledge is in the time domain, and unfortunately most of the features usually extracted for NN training are frequency based, which brings us to a little problem, no cardiologist wants to apply something that he/she can't understand.
13 1 Federico Vera
14 2 Federico Vera
We can of course analyze an ECG in the time domain, and with a little tinkering the results are actually quite encouraging.
15 1 Federico Vera
16
## Preprocessing
17 2 Federico Vera
As you might know before throwing a signal at a NN and expecting great results is usually coherent to to some filtering and transforming I'll keep the filtering to a minimum, and mostly done in order to have nice function plots.
18 1 Federico Vera
19 2 Federico Vera
Let's start by getting a copy of [`mrft`] and some EKG Data (for convenience there are some samples included in `mrft`), in case you don't like them, you are free to search some, manufacture one, or even use a synthesizer like [`Java ECG Generator`](http://www.mit.edu/~gari/CODE/ECGSYN/JAVA/APPLET2/ecgsyn/ecg-java/source.html).
20 1 Federico Vera
21
## Training
22 2 Federico Vera
Open `mrft` select the menu `Examples`->`EKG (Synth)` this will populate the tables the following way: 
23 1 Federico Vera
24 3 Federico Vera
![Data](https://redmine.riddler.com.ar/attachments/download/98/data.png)
25 1 Federico Vera
26
Go ahead and press `F5` (a training session should start and with some luck converge to an _"acceptable"_ fit).
27 4 Federico Vera
28 3 Federico Vera
![FirstPlot](https://redmine.riddler.com.ar/attachments/download/99/firstplot.png)
29 1 Federico Vera
30
There's something odd with the way this MLP is trained... do you see it? No?
31
32 2 Federico Vera
(_Tip:_ in the lower plot both the training and validation errors stay very close together! they should be diverging, or at the very least separate, remember over-fitting?) This usually happens with synthetic data, since adjustment is **too perfect** the training and validation datasets are basically one in the same.
33 1 Federico Vera
34
## Adding some noise
35
Noise is a bad thing that should be removed, why do we want to add it? well the fact is that NN tend to work better with noisy data (not so noisy mind you).
36 2 Federico Vera
37
There are several ways to add noise, but for this we'll use a transformation, so go to `Dataset -> Transform... -> Custom Function (All)`, something like this should appear:
38 4 Federico Vera
39 3 Federico Vera
![](https://redmine.riddler.com.ar/attachments/download/102/custransf.png)
40 2 Federico Vera
41 1 Federico Vera
We'll leave the `x` value as it is, but in the `fx` text field write: `gaussian2(fx, 0.1)` then click on apply, your data now must look something like this:
42 4 Federico Vera
43 3 Federico Vera
![](https://redmine.riddler.com.ar/attachments/download/101/secondplot.png)
44 1 Federico Vera
45
Try pressing `F5` now so it re trains...
46
47
Yes, I lied (not entirely) gaussian noise didn't change the validation error, but I'll let you figure out why on your own (one clue: `Box–Muller`, the rest is _simple_ math). For a bit more information about this see `Adding noise` in [[Data manipulation]]
48
49 2 Federico Vera
## Selecting the right weights
50 1 Federico Vera
As the NN trains itself the synaptic weights of the training epochs are saved (not all of them), so now we must decide which of all the weights to use, click on the error table (`Error Plots` panel), and when you start selecting rows, you should see two things, one is that the red plot of the function plot changes, and the second one is that a line (or guide) appears in the error plot this indicates in the graph the moment of that particular weight.
51 4 Federico Vera
52 3 Federico Vera
![](https://redmine.riddler.com.ar/attachments/download/100/guide.png)
53 1 Federico Vera
54 2 Federico Vera
Once you are satisfied with the results (i.e. choose the "best" weights <sup id="a1">[1](#f1)</sup>)
55 1 Federico Vera
56
## Now what?
57 2 Federico Vera
I don't actually have time to finish it today, but the gist is: we will use that synaptic weight to predict values of an unknown EKG, and estimate how similar is it with the training value (mse), with that, we'll choose the one with the lowest mse (mean square error) is the one that we'll accept as correct.
58 1 Federico Vera
@TODO complete example
59
60 2 Federico Vera
<b id="f1"><sup>1</sup></b> There are several criteria for choosing the "best" as a rule of thumb pick the closest to the left with the lowest error, or the point where the validation an training errors intersect. [↩](#a1)
Volver al inicio