Esempio n. 1
0
        public void ForwardBackwardTest()
        {
            var fl      = new FullLayer(3);
            var weights = TensorOld.Ones(4, 3);
            var bias    = TensorOld.Values(0.5, 1, 3);
            var input   = new TensorOld(new double[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 2, 4);
            var error   = new TensorOld(new double[] { -1, 0.8, 1.5, 1, -1, 1 }, 2, 3);

            var forward         = new TensorOld(new double[] { 10.5, 10.5, 10.5, 26.5, 26.5, 26.5 }, 2, 3);
            var backward        = new TensorOld(new double[] { 1.3, 1.3, 1.3, 1.3, 1, 1, 1, 1 }, 2, 4);
            var biasGradient    = new TensorOld(new double[] { 0, -0.2, 2.5 }, 1, 3);
            var weightsGradient = new TensorOld(new double[, ]
            {
                { 4, -4.2, 6.5 },
                { 4, -4.4, 9 },
                { 4, -4.6, 11.5 },
                { 4, -4.8, 14 },
            });

            fl.PrepareTrain(input);
            fl.SetWeights(weights);
            fl.SetBias(bias);
            fl.Forward(input);
            fl.Backward(error);

            Assert.Equal(forward, fl.ForwardOutput);
            Assert.Equal(backward, fl.BackwardOutput);
            MyAssert.ApproximatelyEqual(biasGradient, fl.BiasGradient);
            Assert.Equal(weightsGradient, fl.WeightsGradient);
        }
Esempio n. 2
0
        public void Play()
        {
            var data   = DataEmulator.Instance.RandomArray(100000);
            var tensor = new TensorOld(data, 500, 200);
            var full   = new FullLayer(100);

            full.PrepareTrain(tensor);
            var start1 = DateTime.Now;
            var output = full.Forward(tensor);
            var ts1    = DateTime.Now - start1;

            Console.WriteLine($"Forward Time:{ts1.TotalMilliseconds}");
        }
Esempio n. 3
0
        public void FullLayerStorageTest()
        {
            var weights = new TensorOld(new double[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 4, 2);
            var bias    = new TensorOld(new double[] { 3, 4 }, 1, 2);
            var xml     = new XmlDocument();

            var layer = new FullLayer(2);

            layer.SetWeights(weights);
            layer.SetBias(bias);

            var el   = XmlStorage.SaveToEl(xml, layer);
            var test = XmlStorage.LoadFromNode <ILayer>(el);

            Assert.True(test is FullLayer);

            var full = test as FullLayer;

            Assert.Equal(2, full.UnitCount);
            Assert.Equal(weights, full.Weights);
            Assert.Equal(bias, full.Bias);
        }