From dd7c57053c40be4260688ce95b9147945f9c545b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Tr=C3=B6ster?= Date: Wed, 6 Dec 2023 14:38:22 +0100 Subject: [PATCH] clean up dead code --- Schafkopf.Training/Common/Dataset.cs | 76 ---------------------------- 1 file changed, 76 deletions(-) diff --git a/Schafkopf.Training/Common/Dataset.cs b/Schafkopf.Training/Common/Dataset.cs index ab991d6..03074ee 100644 --- a/Schafkopf.Training/Common/Dataset.cs +++ b/Schafkopf.Training/Common/Dataset.cs @@ -19,79 +19,3 @@ public bool Equals(SarsExp other) public override int GetHashCode() => 0; } - -public class SupervisedSchafkopfDataset -{ - public static FlatFeatureDataset GenerateDataset( - int trainSize, int testSize) - { - (var trainX, var trainY) = generateDataset(trainSize); - (var testX, var testY) = generateDataset(testSize); - return new FlatFeatureDataset(trainX, trainY, testX, testY); - } - - private static (Matrix2D, Matrix2D) generateDataset(int size) - { - var x = Matrix2D.Zeros(size, GameState.NUM_FEATURES + 2); - var y = Matrix2D.Zeros(size, 1); - - int i = 0; int p = 0; - foreach (var exp in generateExperiences(size)) - { - Console.Write($"\rdataset {i+1} / {size} complete "); - unsafe - { - var card = exp.Action; - x.Data[p++] = GameEncoding.Encode(card.Type); - x.Data[p++] = GameEncoding.Encode(card.Color); - var stateDest = new Span(x.Data + p, GameState.NUM_FEATURES); - exp.StateBefore.ExportFeatures(stateDest); - p += stateDest.Length; - y.Data[i++] = exp.Reward; - } - } - Console.WriteLine(); - - return (x, y); - } - - private static IEnumerable generateExperiences( - int? numExamples = null) - { - var gameCaller = new HeuristicGameCaller( - new GameMode[] { GameMode.Sauspiel }); - - // TODO: supervised transfer learning requires pre-trained agent / heuristic - var agent = new RandomAgent(gameCaller); - var table = new Table( - new Player(0, agent), new Player(1, agent), - new Player(2, agent), new Player(3, agent)); - var deck = new CardsDeck(); - var session = new GameSession(table, deck); - - var serializer = new GameStateSerializer(); - var expBuffer = new SarsExp[32]; - for (int i = 0; i < 32; i++) - expBuffer[i] = new SarsExp() { - StateBefore = new GameState(), - StateAfter = new GameState() - }; - - int p = 0; - while (true) - { - var log = session.ProcessGame(); - if (log.Call.Mode == GameMode.Weiter) - continue; - - serializer.SerializeSarsExps(log, expBuffer); - - for (int i = 0; i < 32; i++) - if (numExamples == null || p++ < numExamples) - yield return expBuffer[i]; - - if (numExamples != null && p >= numExamples) - break; - } - } -}