Exemple #1
0
        public void Perceptron_CanBackProp_Test()
        {
            int howInputs   = 60;
            int howOnHidden = 60;

            Perceptron p = new Perceptron(
                ActivationFunctionType.Sigmoid,
                new int[] { howInputs, howOnHidden, 1 },
                false,
                0.7,
                0.3);

            double[] input = Enumerable.Range(1, howInputs).Select(i => (double)i).ToArray();
            double[] ideal = new double[] { 0.6 };

            double[] first = p.GetResult(input);

            System.Console.WriteLine(p.LossFunction(ideal));

            p.BackPropagation(ideal);

            double[] second = p.GetResult(input);

            System.Console.WriteLine(p.LossFunction(ideal));

            p.BackPropagation(ideal);

            double[] third = p.GetResult(input);

            System.Console.WriteLine(p.LossFunction(ideal));
        }
Exemple #2
0
        /// <summary>
        /// Обучает нейросеть
        /// </summary>
        /// <param name="ideal">Эталонные значения</param>
        /// <returns>Ошибки на первом слое</returns>
        public double[,,] BackPropagation(double[] ideal)
        {
            var deltasOnPercInp = perceptron.BackPropagation(ideal);
            var deltaOnPl1Inp   = pl1.UpSample(
                deltasOnPercInp.ToArray3(
                    pl1.MaxPositions.GetLength(0) / pl1.HowLayers,
                    pl1.MaxPositions.GetLength(1) / poolSize,
                    pl1.MaxPositions.GetLength(2) / poolSize));
            var deltaOnCl2Inp = cl2.BackPropagation(deltaOnPl1Inp);
            var deltaOnCl1Inp = cl1.BackPropagation(deltaOnCl2Inp);

            return(deltaOnCl1Inp);
        }
        static void Train(Perceptron p, int times)
        {
            for (int i = 0; i < times; i++)
            {
                double[][] d = TrainingData();
                p.Predict(d[0]);
                p.BackPropagation(d[1], 0.45, 0.85);
                double[] res = p.Result;

                if ((double)i / times > 0.97)
                {
                    Console.WriteLine($"[{d[0][0]}, {d[0][1]}] -> {res[0].ToString("0.000")} ~ {d[1][0]}");
                }
            }
        }