trictrac/bot/scripts/train.sh

42 lines
1 KiB
Bash
Raw Normal View History

2025-08-10 15:32:41 +02:00
#!/usr/bin/env sh
ROOT="$(cd "$(dirname "$0")" && pwd)/../.."
LOGS_DIR="$ROOT/bot/models/logs"
CFG_SIZE=12
2025-08-13 18:16:30 +02:00
# BINBOT=train_dqn_burn
2025-08-13 21:55:37 +02:00
BINBOT=train_dqn_burn_big
# BINBOT=train_dqn_burn_before
2025-08-10 15:32:41 +02:00
OPPONENT="random"
PLOT_EXT="png"
train() {
2025-08-13 18:16:30 +02:00
cargo build --release --bin=$BINBOT
2025-08-14 15:53:59 +02:00
NAME=$BINBOT"_$(date +%Y-%m-%d_%H:%M:%S)"
2025-08-10 15:32:41 +02:00
LOGS="$LOGS_DIR/$NAME.out"
mkdir -p "$LOGS_DIR"
2025-08-13 18:16:30 +02:00
LD_LIBRARY_PATH="$ROOT/target/release" "$ROOT/target/release/$BINBOT" | tee "$LOGS"
2025-08-10 15:32:41 +02:00
}
plot() {
2025-08-14 15:53:59 +02:00
NAME=$(ls -rt "$LOGS_DIR" | grep $BINBOT | tail -n 1)
2025-08-10 15:32:41 +02:00
LOGS="$LOGS_DIR/$NAME"
cfgs=$(head -n $CFG_SIZE "$LOGS")
for cfg in $cfgs; do
eval "$cfg"
done
# tail -n +$((CFG_SIZE + 2)) "$LOGS"
tail -n +$((CFG_SIZE + 2)) "$LOGS" |
grep -v "info:" |
awk -F '[ ,]' '{print $5}' |
feedgnuplot --lines --points --unset grid --title "adv = $OPPONENT ; density = $dense_size ; decay = $eps_decay ; max steps = $max_steps" --terminal $PLOT_EXT >"$LOGS_DIR/$OPPONENT-$dense_size-$eps_decay-$max_steps-$NAME.$PLOT_EXT"
}
if [ "$1" = "plot" ]; then
plot
else
train
fi