Exemple #1
0
        public void EvaluateTest()
        {
            var layer = new DenseLayer(6, 3, new IdentityActivation(), new Distance());

            layer.Initialize();

            var input = NNArray.Random(6);

            layer.Evaluate(input);
        }
Exemple #2
0
        public void MatrixCalc()
        {
            //  W*I+B  test calculattin Input*Weights + Biases
            int nbInput = 6;
            int nbOutput = 3;
            NNArray I = NNArray.Random(nbInput);
            NNMatrix W = NNMatrix.Random(nbInput, nbOutput);
            NNArray B = NNArray.Random(nbOutput);

            var tmp = W * I;
            var O = tmp + B;

            Assert.AreEqual(O.Length, nbOutput);
        }
Exemple #3
0
        public void BackPropagateTest()
        {
            int nbInput = 6;
            var input   = NNArray.Random(nbInput);
            var output  = new double[] { 0, 1 };

            IActivation activation;

            activation = new IdentityActivation();
            TrainNetwork(activation, input, output);
            activation = new Sigmoid();
            TrainNetwork(activation, input, output);
            activation = new Tanh();
            TrainNetwork(activation, input, output);
            activation = new Relu();
            TrainNetwork(activation, input, output);
        }
Exemple #4
0
        public void MatrixPerformance()
        {
            //  W*I+B  test calculattin Input*Weights + Biases
            int nbInput = 300;
            int nbOutput = 200;

            NNArray I = NNArray.Random(nbInput);
            NNMatrix W = NNMatrix.Random(nbInput, nbOutput);
            NNArray B = NNArray.Random(nbOutput);

            int count = 200;
            DateTime start;
            DateTime end;
            double duration;

            // Not optimized
            start = DateTime.Now;
            for (int i = 0; i < count; i++)
            {
                NNArray res = W * I + B;
            }
            end = DateTime.Now;
            duration = (end - start).TotalMilliseconds / 1000;
            Console.WriteLine("Duration Non Optimized: "+duration);

            // Optimized
            NNArray O = NNArray.Random(nbOutput);
            start = DateTime.Now;
            for (int i = 0; i < count; i++)
            {
                W.Multiply(I,O);
                O.Add(B,O);
            }
            end = DateTime.Now;
            duration = (end - start).TotalMilliseconds / 1000;
            Console.WriteLine("Duration Optimized: " + duration);
        }