Skip to content

Commit

Permalink
beautify log prints
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonifatius94 committed Dec 5, 2023
1 parent 8b3446b commit a1314c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Schafkopf.Training/Algos/MDP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ public void Collect(PPORolloutBuffer buffer)

for (int gameId = 0; gameId < numGames + 1; gameId++)
{
Console.Write($"\rcollecting ppo training data { gameId+1 } / { numGames+1 } ... ");
Console.Write($"\rcollecting data { gameId+1 } / { numGames+1 } ");
playGame(envs, states, batchesOfTurns);
prepareRewards(states, rewards);
fillBuffer(gameId, buffer, states, batchesOfTurns, rewards);
for (int i = 0; i < states.Length; i++)
states[i] = envs[i].Reset();
}

Console.WriteLine();
}

Expand Down
16 changes: 8 additions & 8 deletions Schafkopf.Training/Algos/PPOAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ public PPOModel Train(PPOTrainingSettings config)

for (int ep = 0; ep < config.NumTrainings; ep++)
{
Console.WriteLine($"epoch {ep+1}");
exps.Collect(rollout);
model.Train(rollout);

if ((ep + 1) % 10 == 0)
{
model.RecompileCache(batchSize: 1);
double winRate = benchmark.Benchmark(agent);
model.RecompileCache(batchSize: config.BatchSize);
Console.WriteLine($"epoch {ep}: win rate vs. random agents is {winRate}");
}
model.RecompileCache(batchSize: 1);
double winRate = benchmark.Benchmark(agent);
model.RecompileCache(batchSize: config.BatchSize);

Console.WriteLine($"win rate vs. random agents: {winRate}");
Console.WriteLine("--------------------------------------");
}

return model;
Expand Down Expand Up @@ -150,7 +150,7 @@ public void Train(PPORolloutBuffer memory)
int i = 1;
foreach (var batch in batches)
{
Console.Write($"\rtraining {i++} / {numBatches}");
Console.Write($"\rtraining {i++} / {numBatches} ");
updateModels(batch);
}
Console.WriteLine();
Expand Down
2 changes: 2 additions & 0 deletions Schafkopf.Training/Benchmark/RandomPlayBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public double Benchmark(ISchafkopfAIAgent agentToEval, int epochs = 10_000)
int wins = 0;
for (int i = 0; i < epochs; i++)
{
Console.Write($"\rbenchmarking {i+1} / {epochs} ");
var log = session.ProcessGame();

// info: only evaluate games where cards were played
Expand All @@ -31,6 +32,7 @@ public double Benchmark(ISchafkopfAIAgent agentToEval, int epochs = 10_000)
bool isWin = !eval.DidCallerWin ^ isCaller;
wins += isWin ? 1 : 0;
}
Console.WriteLine();

return (double)wins / epochs; // win rate
}
Expand Down

0 comments on commit a1314c5

Please sign in to comment.