EEG-Powered Habit Recovery · AI Demo

Mindfully

Let's do the things we said we would. This time, let's do it mindfully.

Real-time EEG craving detection using 2 forehead electrodes. Predicts and intercepts addictive urges before they become behaviour.

256 Hz EEG1D-CNN ArchitectureSoftThresholdingJITAI InterventionEdge / .tflite
▶ Live DemoPipeline Code
Scroll

Interactive Demo

Watch the AI Predict a Craving

Press Start Demo then Simulate AI Craving Spike to trigger the full intervention sequence.

01

Receive Signal

2-channel EEG captured

02

Denoise

SoftThresholding layer

03

Classify

Dual-head CNN scores

04

Intervene

JITAI delivered

Raw EEG Signal
Awaiting signal — press Start DemoFp1 · 256 Hz
After AI Denoising
SoftThresholding (θ=0.28) — blink artifacts suppressedΘ/α/β

Hierarchical Multi-Head Output

Both heads share the same salience backbone — trained independently

0%CRAVING

SUD Head

Substance Use Disorder

Low-Theta Coherence

Chemical urge marker

0%CRAVING

Behavioral Head

Gaming / Gambling / CSBD

Late Positive Potential

Behavioral signal marker

Pipeline Output

Real Analysis Results

Output from running the BIDS pipeline on 5 synthetic subjects × 2 conditions (rest vs craving). Each recording: Fp1 + Fp2, 256 Hz, 120 s.

Subjects

5

synthetic dataset

Epoch Pass Rate

87.1%

514 / 590 epochs kept

Bad Channel Rate

4%

detected + interpolated

Fp1 Band Power (µV²)

Theta is the key craving marker — elevated 3.8× above rest

Rest
Craving
Delta (0.5–4 Hz)
18.4 µV²21.2 µV²
Theta (4–8 Hz)SUD MARKER
10.1 µV²38.7 µV²
Alpha (8–13 Hz)
22.6 µV²14.3 µV²
Beta (13–30 Hz)
5.8 µV²4.1 µV²
Gamma (30–80 Hz)
1.9 µV²2.2 µV²

Fp1–Fp2 Theta Coherence · Primary SUD Marker

Rest

0.29

Craving

0.71

+145%

elevation

Low-theta synchrony between Fp1 and Fp2 is the chemical urge marker targeted by the SUD head. Threshold for intervention: 0.60.

Coherence by Band

BandRestCraving
Delta0.310.38
Theta0.290.71
Alpha0.440.37
Beta0.220.19

Pipeline Configuration

ChannelsFp1, Fp2 (2-electrode)
Sampling rate256 Hz
Bandpass0.5 – 80 Hz (FIR, Hamming)
Notch60 Hz + harmonics
Epoch length1 s (no overlap)
PSD methodWelch (n_fft=256, 50% overlap)

Technical Architecture

Mindfully Hierarchical Net

A TensorFlow/Keras 1D-CNN designed for edge deployment. Compresses to a .tflite file via int8 post-training quantization.

Model Pipeline

EEG INPUT

(256 samples × 2 channels)

1 second · 256 Hz · Fp1 + Fp2

BLOCK 1 — Temporal Extraction

Conv1D (16 filters, kernel=32, stride=2)

BatchNormalization → ReLU

SOFT-THRESHOLDING 1

artifact_denoising_1

Adaptive blink + EMG suppression

MaxPooling1D (pool=2)

Spatial downsampling

BLOCK 2 — Salience Backbone

Conv1D (32 filters, kernel=16)

Learns dopamine anticipation signature

SOFT-THRESHOLDING 2

artifact_denoising_2

BLOCK 3 — Deep Features

Conv1D (64 filters, kernel=8)

BatchNormalization → ReLU

GLOBAL AVERAGE POOLING

shared_salience_features

64-dim vector · Dropout(0.4)

SUD HEAD

Dense(32) · Dropout(0.3)

Softmax(2) output

Low-theta coherence Substance urge marker

BEH HEAD

Dense(32) · Dropout(0.3)

Softmax(2) output

Late Positive Potential Gaming / gambling marker

SoftThresholding — The Core Innovation

With only 2 EEG channels, spatial ICA is impossible. This layer learns to suppress high-amplitude blink/EMG artifacts during backprop, preserving the low-amplitude Theta (4–8 Hz) and Gamma (30–80 Hz) waves that encode craving states.

// Forward pass:
θ = softplus(w)
mask = |x| > θ
out = sign(x) · (|x| − θ) · mask
craving_classifier.py
class SoftThresholding(layers.Layer):
  def build(self, input_shape):
    # Learnable threshold — one per feature channel
    self.threshold = self.add_weight(
      name='threshold',
      shape=(input_shape[-1],),
      initializer=Constant(0.1),
      trainable=True
    )

  def call(self, inputs):
    abs_x = tf.math.abs(inputs)
    # softplus keeps threshold strictly positive
    t = tf.math.softplus(self.threshold)
    mask = tf.cast(abs_x > t, dtype=inputs.dtype)
    # Shrink toward zero; zero if below threshold
    return tf.math.sign(inputs) * (abs_x - t) * mask

Model Specifications

Input shape(256, 2)
Total parameters~47,000
Shared backboneConv1D × 3 + SoftThreshold × 2
Outputs2 heads (SUD + Behavioral)
Target format.tflite (int8 quantized)
Edge latency< 50ms on mobile CPU
Training losssparse_categorical_crossentropy × 2
OptimizerAdam (lr=0.001)

Engineering Roadmap

Attention Mechanisms

Replace Conv1D Block 2 with CoTAttention / DAFM

Edge Quantization

PTQ float32→int8 via tf.lite.TFLiteConverter

Ablation Pipeline

OpenNeuro BIDS dataset · drop 62/64 channels

Autoregressive Forecasting

Predict craving at t + 15 min (ego-depletion)

Mindfully — Neuro-behavioral intervention platform · Confidential Demo