#!/bin/bash
#SBATCH --job-name=custom_cluster_explanations
#SBATCH --output=logs/custom_cluster_explanations_%A_%a.out
#SBATCH --error=logs/custom_cluster_explanations_%A_%a.err
#SBATCH --array=0-4499  # Updated: (10 deltas * 5 seeds * 18 cluster sizes * 5 clusters) - 1
#SBATCH --time=05:00:00
#SBATCH --cpus-per-task=1
#SBATCH --constraint="hsw"

TASK_ID=$SLURM_ARRAY_TASK_ID

# Configuration
NUM_DELTAS=10
NUM_SEEDS=5
NUM_CLUSTERS=5
NUM_CLUSTER_SIZES=18  # 3 to 20 (inclusive)
DIM=10  # Fixed dataset: custom-10

# Compute indices for 4D array (seeds, deltas, clusters, cluster sizes)
CLUSTER_SIZE_INDEX=$((TASK_ID / (NUM_DELTAS * NUM_CLUSTERS * NUM_SEEDS)))
REMAINING_1=$((TASK_ID % (NUM_DELTAS * NUM_CLUSTERS * NUM_SEEDS)))
CLUSTER_INDEX=$((REMAINING_1 / (NUM_DELTAS * NUM_SEEDS)))
REMAINING_2=$((REMAINING_1 % (NUM_DELTAS * NUM_SEEDS)))
DELTA_INDEX=$((REMAINING_2 / NUM_SEEDS))
SEED_INDEX=$((REMAINING_2 % NUM_SEEDS))

# Compute actual values
CLUSTER_SIZE=$((3 + CLUSTER_SIZE_INDEX))  # 3 to 20
DELTA=$(printf "%.2f" "$(echo "$DELTA_INDEX * 0.02" | bc -l)")
SEED=$SEED_INDEX

echo "Running task $TASK_ID with DIM=$DIM, DELTA=$DELTA, CLUSTER_INDEX=$CLUSTER_INDEX, CLUSTER_SIZE=$CLUSTER_SIZE, and SEED=$SEED"

python -m scripts.tools.generate_explanations \
    --dataset custom \
    --custom-dim "$DIM" \
    --seed "$SEED" \
    --explainer cluster \
    --cluster-index "$CLUSTER_INDEX" \
    --cluster-size $CLUSTER_SIZE \
    --delta "$DELTA" \
    --prototype "mean" \
    --num-explanations 100000 \
    --num-consumers 1 \
    --output data/logs/cluster/scalability/cluster-explanations-by-cluster-size/custom_dim_"$DIM"_delta_"$DELTA"_cluster_"$CLUSTER_INDEX"_size_"$CLUSTER_SIZE"_seed_"$SEED".json
