#!/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-3999  # Updated: (10 deltas * 16 dims * 5 clusters * 5 seeds) - 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_DIMS=16
NUM_CLUSTERS=5
NUM_SEEDS=5
CLUSTER_SIZE=10

# Compute indices for 4D array (seeds, deltas, dims, clusters)
CLUSTER_INDEX=$((TASK_ID / (NUM_DELTAS * NUM_DIMS * NUM_SEEDS)))
REMAINING_1=$((TASK_ID % (NUM_DELTAS * NUM_DIMS * NUM_SEEDS)))
DIM_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
DIM=$((10 + DIM_INDEX))
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, 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-num-features/custom_dim_"$DIM"_delta_"$DELTA"_cluster_"$CLUSTER_INDEX"_seed_"$SEED".json
