public async Task PerceptronPropagatesActivationsForwards() { var outputs = await _perceptron.FireAsync(_activations); var hiddenUnits = _network.GetHidden(); var expectedHidden1Activation = _network.ConnectionInput1Hidden1.Properties.Weight * _network.Input1Activation + _network.ConnectionInput2Hidden1.Properties.Weight * _network.Input2Activation; var expectedHidden2Activation = _network.ConnectionInput1Hidden2.Properties.Weight * _network.Input1Activation + _network.ConnectionInput2Hidden2.Properties.Weight * _network.Input2Activation; hiddenUnits.ElementAt(0).UnitActivation.Properties.ActivationValue.Should().BeApproximately(expectedHidden1Activation, 0.00000001d); hiddenUnits.ElementAt(1).UnitActivation.Properties.ActivationValue.Should().BeApproximately(expectedHidden2Activation, 0.00000001d); var expectedOutput1 = _network.ConnectionHidden1Output1.Properties.Weight * expectedHidden1Activation + _network.ConnectionHidden2Output1.Properties.Weight * expectedHidden2Activation; var expectedOutput2 = _network.ConnectionHidden1Output2.Properties.Weight * expectedHidden1Activation + _network.ConnectionHidden2Output2.Properties.Weight * expectedHidden2Activation; expectedOutput1.Should().BeGreaterThan(0d, because: "Otherwise activations or weights are not being set correctly somewhere"); expectedOutput2.Should().BeGreaterThan(0d, because: "Otherwise activations or weights are not being set correctly somewhere"); outputs.ElementAt(0).Should().BeApproximately(expectedOutput1, 0.00000001d); outputs.ElementAt(1).Should().BeApproximately(expectedOutput2, 0.00000001d); }
public void SetUp() { _network = new NetworkBuilder().Setup(); _outputErrorCalculatorMock = new Mock <IOutputUnitErrorCalculator>(); _outputErrorCalculatorMock.Setup(c => c.CalculateOutputError(IdealValue1, _network.Output1Activation, _network.Output1Derivative)).Returns(Output1ExpectedError); _outputErrorCalculatorMock.Setup(c => c.CalculateOutputError(IdealValue2, _network.Output2Activation, _network.Output2Derivative)).Returns(Output2ExpectedError); _hiddenErrorCalculatorMock = new Mock <IHiddenUnitErrorCalculator>(); _hiddenErrorCalculatorMock.Setup(c => c.CalculateHiddenError(It.IsAny <IEnumerable <double> >(), It.IsAny <IEnumerable <double> >(), _network.Hidden1Activation, _network.Hidden1Derivative)).Returns(Hidden1ExpectedError); _hiddenErrorCalculatorMock.Setup(c => c.CalculateHiddenError(It.IsAny <IEnumerable <double> >(), It.IsAny <IEnumerable <double> >(), _network.Hidden2Activation, _network.Hidden2Derivative)).Returns(Hidden2ExpectedError); _backPropagator = new ErrorValueBackPropagator(_network.GetNetwork(), _outputErrorCalculatorMock.Object, _hiddenErrorCalculatorMock.Object); _outputUnits = _network.GetOutputs(); _hiddenUnits = _network.GetHidden(); _idealValues = new List <double> { IdealValue1, IdealValue2 }; }