Exemplo n.º 1
0
        public async Task PerceptronClampsInputs()
        {
            await _perceptron.FireAsync(_activations);

            var inputs = _network.GetInputs();

            inputs.ElementAt(0).ActivationValue.Should().Be(_activations[0], because: "Input unit value is fed forward without modification.");
            inputs.ElementAt(1).ActivationValue.Should().Be(_activations[1], because: "Input unit value is fed forward without modification.");
        }
Exemplo n.º 2
0
 public void SetUp()
 {
     _network     = new NetworkBuilder().Setup();
     _perceptron  = new Perceptron(_network.GetInputs());
     _activations = new List <double> {
         1d, 2d
     };
 }
Exemplo n.º 3
0
        public void ErrorBackPropagationStepsThrowsExceptionIfLearningRateIsZero()
        {
            var inputs           = _network.GetInputs();
            var weightSetterMock = new Mock <IWeightSetter>();
            var perceptronMock   = new Mock <IPerceptronUnderTraining>();
            var exception        = Assert.Throws <ArgumentException>(() => new ErrorBackPropagationStepsOnline(weightSetterMock.Object, perceptronMock.Object, 0d, 1d));

            exception.Message.Should().Be(ErrorBackPropagationStepsBase.LearningRateShouldNotBeZero);
        }
Exemplo n.º 4
0
        public void LayeredUnitsSeparatesUnitsIntoLayersCorrectly()
        {
            var inputs = _network.GetInputs();
            var layeredUnitCollection = new LayeredUnitCollection <IUnit, IConnection, IUnitActivation <IUnit> >(inputs).GetLayeredUnits();

            layeredUnitCollection.ElementAt(0).Should().ContainInOrder(new List <object>
            {
                _network.Input1,
                _network.Input2,
                _network.InputUnorthodox,
            });
            layeredUnitCollection.ElementAt(1).Should().ContainInOrder(new List <object>
            {
                _network.Hidden1,
                _network.Hidden2,
            });
            layeredUnitCollection.ElementAt(2).Should().ContainInOrder(new List <object>
            {
                _network.Output1,
                _network.Output2,
            });
        }
        public void LayeredConnectionsSeparatesUnitsIntoLayersCorrectly()
        {
            var inputs = _network.GetInputs();

            _network.AddBias();

            var layeredUnitCollection = new LayeredConnectionCollection <IUnit, IConnection, IUnitActivation <IUnit> >(inputs);
            var layeredConnections    = layeredUnitCollection.GetLayeredConnection().ToList();

            layeredConnections.Should().HaveCount(2);

            var inputToHiddenConnections  = layeredConnections.ElementAt(0);
            var hiddenToOutputConnections = layeredConnections.ElementAt(1);

            inputToHiddenConnections.Should().Contain(new List <object>
            {
                _network.ConnectionInput1Hidden1,
                _network.ConnectionInput1Hidden2,
                _network.ConnectionInput2Hidden1,
                _network.ConnectionInput2Hidden2,
                _network.InputUnorthodoxToHidden1,
                _network.HiddenBiasToHidden1,
                _network.HiddenBiasToHidden2,
            }).And.HaveCount(7);

            hiddenToOutputConnections.Should().Contain(new List <object>
            {
                _network.ConnectionHidden1Output1,
                _network.ConnectionHidden1Output2,
                _network.ConnectionHidden2Output1,
                _network.ConnectionHidden2Output2,
                _network.InputUnorthodoxToOutput1,
                _network.OutputBiasToOutput1,
                _network.OutputBiasToOutput2,
            }).And.HaveCount(7);
        }