Deep Neural Network learning algorithm.
상속: ISupervisedLearning
예제 #1
0
파일: DNN.cs 프로젝트: fenge21/Csharp
        public void Train(double[][] i, double[][] o = null, int outputLength = 10, int hiddenLayer = -1)
        {
            if (n == null)
            {
                if (File.Exists(p)) n = DeepBeliefNetwork.Load(p);
                else
                {
                    outputLength = (o == null) ? outputLength : o[0].Length;
                    hiddenLayer = (hiddenLayer == -1) ? (int)Math.Log(i[0].Length, outputLength) : hiddenLayer;
                    List<int> layers = new List<int>();
                    for (int j = 0; j < hiddenLayer; j++) layers.Add(i[0].Length);
                    layers.Add(outputLength);
                    n = new DeepBeliefNetwork(new BernoulliFunction(), i[0].Length, layers.ToArray());
                    new GaussianWeights(n).Randomize();
                }
            }

            dynamic t;
            if (o == null)
            {
                t = new DeepBeliefNetworkLearning(n) { Algorithm = (h, v, j) => new ContrastiveDivergenceLearning(h, v), LayerIndex = n.Machines.Count - 1, };
                while (true) e = t.RunEpoch(t.GetLayerInput(i));
            }
            else
            {
                t = new DeepNeuralNetworkLearning(n) { Algorithm = (ann, j) => new ParallelResilientBackpropagationLearning(ann), LayerIndex = n.Machines.Count - 1, };
                while (true) e = t.RunEpoch(t.GetLayerInput(i), o);
            }
        }
예제 #2
0
 private void InitializeTeacher()
 {
     _Teacher = new DeepNeuralNetworkLearning(_Network)
     {
         Algorithm = (ann, i) => new ParallelResilientBackpropagationLearning(ann),
         LayerIndex = _Network.Machines.Count - 1,
     };
 }
예제 #3
0
        private void learnLayerSupervised()
        {
            if (!Main.CanClassify) return;
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;

            new Task(() =>
            {
                DeepNeuralNetworkLearning teacher = new DeepNeuralNetworkLearning(Main.Network)
                {
                    Algorithm = (ann, i) => new ParallelResilientBackpropagationLearning(ann),
                    LayerIndex = Main.Network.Layers.Length - 1,
                };

                double[][] inputs, outputs;
                Main.Database.Training.GetInstances(out inputs, out outputs);

                // Gather learning data for the layer
                double[][] layerData = teacher.GetLayerInput(inputs);

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

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

                Main.Network.UpdateVisibleWeights();
                IsLearning = false;

            }).Start();
        }