Initialize NeuroAnalyzer
using NeuroAnalyzer
using Plots
eeg = load("files/eeg.hdf")
e10 = epoch(eeg, ep_len = 10)using NeuroAnalyzer
using Plots
eeg = load("files/eeg.hdf")
e10 = epoch(eeg, ep_len = 10)Synchronization Likelihood (SL) Measures statistical dependencies between two signals by comparing their state-space trajectories.
Formula:
\[ \text{SL} = \frac{1}{N} \sum_{k=1}^N \Theta(\epsilon - \vert x_1(k) - x_2(k) \vert ) \]
where:
Interpretation:
Advantages:
Cosine Similarity is a measure of similarity between two non-zero vectors defined in an inner product space.
The cosine similarity always belongs to the interval \([-1, +1]\).
Two proportional vectors have a cosine similarity of \(+1\), two orthogonal vectors have a similarity of \(0\), and two opposite vectors have a similarity of \(−1\).
cs = cosim(e10, e10; ch1 = "F3", ch2 = "F4", ep1 = 1, ep2 = 1);
println("CS: $(cs[1])")CS: -0.16021870641882938
Phase Synchronization Analysis (PSA) is a normalized phase synchronization between two signals.
PSA uses the Hilbert transform to calculate instantaneous phases, hence the signal should be narrowband.
\[ PS = \frac{\sum{\cos(\vartheta_x - \vartheta_y)}}{n} \] \(\vartheta\): instantaneous phases
\(n\): number of samples
ps = psa(e10, e10; ch1 = "F3", ch2 = "F4", ep1 = 1, ep2 = 1);
println("PS: $(ps[1])")PS: -0.13306412443233112
Correlation shows how two signals are related to each other.
\[ r_{x,y} = \frac{x^T \times y}{\|x\| \times \|y\|} \]
Pearson correlation coefficient is the cosine of the angle between two vectors - when those vectors are mean-centered.
cr = corr(e10, e10; ch1 = "F3", ch2 = "F4", ep1 = 1, ep2 = 1);
println("CR: $(cr[1])")CR: -0.18477387837802986
Phase Slope Index (PSI) estimates the direction of information flux in multivariate time series.
PSI is insensitive to mixtures of independent sources and gives meaningful results even if the phase spectrum is not linear. Moreover, PSI properly weights contributions from different frequencies.
PSI values are reported in pairs (source-destination).
pv = psi(e10, e10; ch1 = "F3", ch2 = "F4", ep1 = 1, ep2 = 1);
println("PSI F3->F4: $(pv[1][1])")
println("PSI F4->F3: $(pv[1][2])")PSI F3->F4: -0.015433719065658758
PSI F4->F3: 0.015433719065658758
PSI can be also calculated for a specific frequency range:
pv = psi(e10, e10; ch1 = "F3", ch2 = "F4", ep1 = 1, ep2 = 1, flim = (8, 12));
println("PSI F3->F4: $(pv[1][1])")
println("PSI F4->F3: $(pv[1][2])")PSI F3->F4: 0.038495602914841255
PSI F4->F3: -0.038495602914841255
Normalized PSI is PSI divided by its standard deviation.
Mutual information (MI): is a measure of the mutual dependence between the two variables. MI quantifies the “amount of information” obtained about one random variable by observing the other random variable.
m = mutual_information(eeg; ch = "eeg")
plot_matrix(m[:, :, 1]; xlabels = labels(eeg)[1:19], ylabels = labels(eeg)[1:19])┌ Warning: Found `resolution` in the theme when creating a `Scene`. The `resolution` keyword for `Scene`s and `Figure`s has been deprecated. Use `Figure(; size = ...` or `Scene(; size = ...)` instead, which better reflects that this is a unitless size and not a pixel resolution. The key could also come from `set_theme!` calls or related theming functions. └ @ Makie ~/.julia/packages/Makie/kJl0u/src/scenes.jl:264
(!) Currently only one estimator (maximum likelihood) is available. Internally it uses InformationMeasures.get_mutual_information(), source: InformationMeasures.jl.