#!/usr/bin/env bash
# Signal amplification tests on the best config (vlaai_ws + aug + electrode-cluster dropout), 2 training seeds each:
#   1) onset targets: the DNN reconstructs envelope AND onset envelope, evidence = mean correlation over both (mat prep)
#   2) wider band: FFT band-pass 1-15 Hz (fft15) vs 1-9 Hz (fft), same pipeline; plus WF on fft15 as linear reference
cd "$(dirname "$0")/.."
PY=../../.venv/bin/python
QLOG=logs/queue_signal.log
echo "$(date '+%F %T') queue signal started; build cache/fft15" | tee -a "$QLOG"
$PY prepare_data.py fft15 >> logs/prepare_fft15.stdout 2>&1 || echo "$(date '+%F %T') fft15 cache build FAILED" | tee -a "$QLOG"
run() {  # exp decoder prep args...
  local exp=$1 dec=$2 prep=$3; shift 3
  [[ -f results/$exp.json ]] && return
  echo "$(date '+%F %T') START $exp" | tee -a "$QLOG"
  if $PY run_experiment.py --decoder $dec --prep $prep "$@" < /dev/null >> logs/$exp.stdout 2>&1; then
    rm -f results/$exp.FAILED
    echo "$(date '+%F %T') DONE  $exp: $(grep 'MEAN over' logs/$exp.log | tail -1 | cut -d' ' -f3-)" | tee -a "$QLOG"
  else
    touch results/$exp.FAILED; echo "$(date '+%F %T') FAILED $exp" | tee -a "$QLOG"
  fi
  $PY summarize.py > /dev/null 2>&1 || true
}
run vlaai_ws__mat_aug_cluster_onset    vlaai_ws mat   --tag _aug_cluster_onset    --aug-variant cluster --targets env,onset
run vlaai_ws__mat_aug_cluster_onset_s1 vlaai_ws mat   --tag _aug_cluster_onset_s1 --aug-variant cluster --targets env,onset --train-seed 1
run vlaai_ws__fft15_aug_cluster        vlaai_ws fft15 --tag _aug_cluster          --aug-variant cluster
run vlaai_ws__fft15_aug_cluster_s1     vlaai_ws fft15 --tag _aug_cluster_s1       --aug-variant cluster --train-seed 1
run vlaai_ws__fft_aug_cluster_s1       vlaai_ws fft   --tag _aug_cluster_s1       --aug-variant cluster --train-seed 1
run wf__fft15                          wf       fft15
echo "$(date '+%F %T') queue signal finished" | tee -a "$QLOG"
