Esempio n. 1
0
        private static void SampleXor()
        {
            SigmaEnvironment sigma = SigmaEnvironment.Create("logical");

            sigma.SetRandomSeed(0);
            sigma.Prepare();

            RawDataset dataset = new RawDataset("xor");

            dataset.AddRecords("inputs", new[] { 0, 0 }, new[] { 0, 1 }, new[] { 1, 0 }, new[] { 1, 1 });
            dataset.AddRecords("targets", new[] { 0 }, new[] { 0 }, new[] { 0 }, new[] { 1 });

            ITrainer trainer = sigma.CreateTrainer("xor-trainer");

            trainer.Network.Architecture = InputLayer.Construct(2) + FullyConnectedLayer.Construct(2) + FullyConnectedLayer.Construct(1) + OutputLayer.Construct(1) + SquaredDifferenceCostLayer.Construct();
            trainer.TrainingDataIterator = new MinibatchIterator(1, dataset);
            trainer.AddNamedDataIterator("validation", new UndividedIterator(dataset));
            trainer.Optimiser = new GradientDescentOptimiser(learningRate: 0.1);
            trainer.Operator  = new CudaSinglethreadedOperator();

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

            trainer.AddLocalHook(new StopTrainingHook(atEpoch: 10000));
            trainer.AddLocalHook(new AccumulatedValueReporter("optimiser.cost_total", TimeStep.Every(1, TimeScale.Epoch), averageValues: true));
            trainer.AddLocalHook(new AccumulatedValueReporter("optimiser.cost_total", TimeStep.Every(1, TimeScale.Stop), averageValues: true));
            trainer.AddLocalHook(new ValueReporter("network.layers.*<external_output>._outputs.default.activations", TimeStep.Every(1, TimeScale.Stop)));
            trainer.AddLocalHook(new ValueReporter("network.layers.*-fullyconnected.weights", TimeStep.Every(1, TimeScale.Stop)));
            trainer.AddLocalHook(new ValueReporter("network.layers.*-fullyconnected.biases", TimeStep.Every(1, TimeScale.Stop)));

            sigma.Run();
        }
Esempio n. 2
0
        private static void Main()
        {
            SigmaEnvironment.EnableLogging();
            SigmaEnvironment sigma = SigmaEnvironment.Create("Sigma-MNIST");

            // create a new mnist trainer
            ITrainer trainer = CreateMnistTrainer(sigma);

            // for the UI we have to activate more features
            if (UI)
            {
                // create and attach a new UI framework
                WPFMonitor gui = sigma.AddMonitor(new WPFMonitor("MNIST"));

                // create a tab
                gui.AddTabs("Overview");

                // access the window inside the ui thread
                gui.WindowDispatcher(window =>
                {
                    // enable initialisation
                    window.IsInitializing = true;

                    // add a panel that controls the learning process
                    window.TabControl["Overview"].AddCumulativePanel(new ControlPanel("Control", trainer));

                    // create an accuracy cost that updates every iteration
                    var cost = new TrainerChartPanel <CartesianChart, LineSeries, TickChartValues <double>, double>("Cost", trainer, "optimiser.cost_total", TimeStep.Every(1, TimeScale.Iteration));
                    // improve the chart performance
                    cost.Fast();

                    // add the newly created panel
                    window.TabControl["Overview"].AddCumulativePanel(cost);

                    // finish initialisation
                    window.IsInitializing = false;
                });

                // the operators should not run instantly but when the user clicks play
                sigma.StartOperatorsOnRun = false;
            }

            sigma.Prepare();

            sigma.Run();
        }