Esempio n. 1
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);
        }
Esempio n. 2
0
        public void MatrixMult()
        {
            NNMatrix M1 = NNMatrix.Random(2, 2); // 3 row * 4 Columns
            NNMatrix M2 = NNMatrix.Identity(2, 2);

            var M3 = M1 * M2;

            Assert.IsTrue(M1.Equals(M3));

            M1 = NNMatrix.Random(3, 4); // 3 row * 4 Columns
            M2 = NNMatrix.Random(4, 2);

            M3 = M1 * M2;

            Assert.AreEqual(M3.NbRows, 3);
            Assert.AreEqual(M3.NbCols, 2);
        }
Esempio n. 3
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);
        }