Exemplo n.º 1
0
        public void ExecuteTest()
        {
            Random random = new Random(1234);

            const int batches = 1000, tests = 8;

            foreach (int num in new int[] { 32, 64, 128, 256 })
            {
                List <float> variance_list = new List <float>();

                for (int i = 0; i < tests; i++)
                {
                    Tensor x = Tensor.NormalRandom(Shape.Map0D(num, batches), random);
                    Tensor w = new Tensor(Shape.Kernel0D(num, 1));

                    var initializer = new LeCunNormal(w, random);
                    initializer.Execute();

                    Tensor y = Tensor.Dense(x, w);

                    float variance = Tensor.Average(y * y).State[0];

                    variance_list.Add(variance);
                }

                float mean_variance = variance_list.Average();

                Assert.AreEqual(1, mean_variance, 0.1f, $"{num}:{mean_variance}");

                Console.WriteLine($"{num}:{mean_variance}");
            }
        }
Exemplo n.º 2
0
        public void LeCunNormalTest()
        {
            var init = new LeCunNormal();
            var m    = init.Initialize(new Matrix(2, 2));

            Assert.IsTrue(Math.Abs(m.FrobeniusNorm()) > 0.01, init.Type().ToString() + " Initializer.");
        }