Ejemplo n.º 1
0
            /// <summary>
            /// Create an extracted Connect4 dataset (6 by 7 field).
            /// The dataset is shuffled and one-hot-target-preprocessed.
            /// </summary>
            /// <param name="name">The optional name.</param>
            /// <returns>The Connect4 dataset.</returns>
            public static IDataset Connect4(string name = "connect4")
            {
                CsvRecordExtractor csvExtractor = new CsvRecordReader(
                    new MultiSource(new FileSource("connect-4.data"), new UrlSource("https://raw.githubusercontent.com/moroshko/connect4/master/connect-4.data")))
                                                  .Extractor("inputs", new[] { 0, 41 }, "targets", 42)
                                                  .AddValueMapping(42, "loss", "draw", "win");

                Dictionary <object, object> mappings = new Dictionary <object, object>()
                {
                    ["x"] = 1,
                    ["b"] = 0,
                    ["o"] = -1
                };

                for (int i = 0; i < 42; i++)
                {
                    csvExtractor.AddValueMapping(i, mapping: mappings);
                }

                var extractor = csvExtractor
                                .Preprocess(new OneHotPreprocessor("targets", 0, 2))
                                .Preprocess(new ShufflePreprocessor());

                return(new ExtractedDataset(name, 67557, extractor));
            }