#!/bin/bash
#SBATCH --job-name=classic_robust_explanations
#SBATCH --output=logs/classic_robust_explanations_%A_%a.out
#SBATCH --error=logs/classic_robust_explanations_%A_%a.err
#SBATCH --array=0-999  # Updated: (2 labels * 10 deltas * 5 cluster * 10 cluster size) - 1
#SBATCH --time=00:05:00
#SBATCH --cpus-per-task=1
#SBATCH --constraint="hsw"

TASK_ID=$SLURM_ARRAY_TASK_ID
DATASET="wine"

# Configuration
NUM_LABELS=2
NUM_DELTAS=10
NUM_CLUSTERS=5
CLUSTER_SIZE=10
NUM_SAMPLES=$((NUM_CLUSTERS * CLUSTER_SIZE))

# Compute indices
LABEL_INDEX=$((TASK_ID / (NUM_DELTAS * NUM_SAMPLES)))
REMAINING=$((TASK_ID % (NUM_DELTAS * NUM_SAMPLES)))
DELTA_INDEX=$((REMAINING % NUM_DELTAS))
SAMPLE_INDEX=$((REMAINING / NUM_DELTAS))

# Compute actual values
LABEL=$LABEL_INDEX
DELTA=$(printf "%.2f" "$(echo "$DELTA_INDEX * 0.01" | bc -l)")
SAMPLE=$SAMPLE_INDEX

echo "Running task $TASK_ID on dataset $DATASET with LABEL=$LABEL, DELTA=$DELTA and SAMPLE=$SAMPLE"

python -m scripts.tools.generate_explanations \
    --dataset "$DATASET" \
    --explainer cluster \
    --sample-index "$SAMPLE" \
    --label "$LABEL" \
    --delta "$DELTA" \
    --prototype "mean" \
    --num-explanations 1 \
    --num-consumers 1 \
    --output data/logs/delta_robust/classic/robust-explanations/"$DATASET"_label_"$LABEL"_delta_"$DELTA"_sample_"$SAMPLE".json
