Exemple #1
0
        private static void SampleHutter()
        {
            const long timeWindowSize = 10L;

            SigmaEnvironment sigma = SigmaEnvironment.Create("recurrent");

            IDataSource      source    = new MultiSource(new FileSource("enwik8"), new CompressedSource(new MultiSource(new FileSource("enwik8.zip"), new UrlSource("http://mattmahoney.net/dc/enwik8.zip"))));
            IRecordExtractor extractor = new CharacterRecordReader(source, (int)(timeWindowSize + 1), Encoding.ASCII)
                                         .Extractor(new ArrayRecordExtractor <short>(ArrayRecordExtractor <short>
                                                                                     .ParseExtractorParameters("inputs", new[] { 0L }, new[] { timeWindowSize }, "targets", new[] { 0L }, new[] { timeWindowSize }))
                                                    .Offset("targets", 1L))
                                         .Preprocess(new PermutePreprocessor(0, 2, 1))
                                         .Preprocess(new OneHotPreprocessor(0, 255));
            IDataset dataset = new ExtractedDataset("hutter", ExtractedDataset.BlockSizeAuto, false, extractor);

            ITrainer trainer = sigma.CreateTrainer("hutter");

            trainer.Network.Architecture = InputLayer.Construct(256) + RecurrentLayer.Construct(256) + OutputLayer.Construct(256) + SoftMaxCrossEntropyCostLayer.Construct();
            trainer.TrainingDataIterator = new MinibatchIterator(32, dataset);
            trainer.AddNamedDataIterator("validation", new MinibatchIterator(100, dataset));
            trainer.Optimiser = new AdagradOptimiser(baseLearningRate: 0.07);
            trainer.Operator  = new CudaSinglethreadedOperator();

            trainer.AddInitialiser("*.*", new GaussianInitialiser(standardDeviation: 0.05));

            trainer.AddLocalHook(new AccumulatedValueReporter("optimiser.cost_total", TimeStep.Every(1, TimeScale.Iteration), averageValues: true));
            trainer.AddLocalHook(new RunningTimeReporter(TimeStep.Every(10, TimeScale.Iteration)));

            sigma.PrepareAndRun();
        }
        public void TestByteRecordExtractorExtract()
        {
            ArrayRecordExtractor <byte> extractor = new ArrayRecordExtractor <byte>(ArrayRecordExtractor <byte> .ParseExtractorParameters("inputs", new[] { 0L }, new[] { 1L }));
            IComputationHandler         handler   = new CpuFloat32Handler();

            Assert.Throws <InvalidOperationException>(() => extractor.ExtractDirect(10, handler));

            byte[][] rawData = new[] { new byte[] { 0 }, new byte[] { 1 } };

            Assert.AreEqual(new float[] { 0, 1 }, extractor.ExtractDirectFrom(rawData, 2, handler)["inputs"].GetDataAs <float>().GetValuesArrayAs <float>(0L, 2L));
        }
        public void TestByteRecordExtractorCreate()
        {
            string filename = ".unittestfile" + nameof(TestByteRecordExtractorCreate);

            CreateCsvTempFile(filename);

            FileSource source = new FileSource(filename, Path.GetTempPath());

            Assert.Throws <ArgumentNullException>(() => new ArrayRecordExtractor <byte>(null));
            Assert.Throws <ArgumentException>(() => new ArrayRecordExtractor <byte>(new Dictionary <string, long[][]>()
            {
                ["test"] = new long[1][] { new long[] { 1, 2, 3 } }
            }));

            ArrayRecordExtractor <byte> extractor = new ArrayRecordExtractor <byte>(ArrayRecordExtractor <byte> .ParseExtractorParameters("inputs", new[] { 0L }, new[] { 1L }));

            Assert.AreEqual(new[] { "inputs" }, extractor.SectionNames);

            source.Dispose();

            DeleteTempFile(filename);
        }
Exemple #4
0
 public ArrayRecordExtractor <byte> Extractor(params object[] parameters)
 {
     return((ArrayRecordExtractor <byte>)Extractor(ArrayRecordExtractor <byte> .ParseExtractorParameters(parameters)));
 }