GetLayerAlgorithm() public method

Gets the unsupervised learning algorithm allocated for the given layer.
public GetLayerAlgorithm ( int layerIndex ) : IUnsupervisedLearning
layerIndex int The index of the layer to get the algorithm for.
return IUnsupervisedLearning
Example #1
0
        private void learnLayerUnsupervised()
        {
            if (!Main.CanGenerate) return;
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;

            new Task(() =>
            {
                DeepBeliefNetworkLearning teacher = new DeepBeliefNetworkLearning(Main.Network)
                {
                    Algorithm = (h, v, i) => new ContrastiveDivergenceLearning(h, v)
                    {
                        LearningRate = LearningRate,
                        Momentum = 0.5,
                        Decay = WeightDecay,
                    },

                    LayerIndex = SelectedLayerIndex - 1,
                };

                double[][] inputs;
                Main.Database.Training.GetInstances(out inputs);
                int batchCount = Math.Max(1, inputs.Length / BatchSize);

                // Create mini-batches to speed learning
                int[] groups = Accord.Statistics.Tools
                    .RandomGroups(inputs.Length, batchCount);
                double[][][] batches = inputs.Subgroups(groups);

                // Gather learning data for the layer
                double[][][] layerData = teacher.GetLayerInput(batches);
                var cd = teacher.GetLayerAlgorithm(teacher.LayerIndex) as ContrastiveDivergenceLearning;

                // Start running the learning procedure
                for (int i = 0; i < Epochs && !shouldStop; i++)
                {
                    double error = teacher.RunEpoch(layerData) / inputs.Length;

                    dispatcher.BeginInvoke((Action<int, double>)updateError,
                        DispatcherPriority.ContextIdle, i + 1, error);

                    if (i == 10)
                        cd.Momentum = Momentum;
                }

                IsLearning = false;

            }).Start();
        }