public void SingleIterationOfLearnWithActivationFunctionReturnCorrectResult() { // Arrange var activationFunction = ActivationFunction.Sigmoid; var model = CreateFullyConnectedNeuralNetworkModel(activationFunction); var batch = CreateBatch(); var expectedResult = new FullyConnectedNeuralNetworkModel { ActivationCountsPerLayer = new[] { 4, 3 }, ActivationFunction = activationFunction, BiasLayers = new[] { new[] { -1.2943006116609224, 0.77069126468580773, 0.41209730715748505 } }, WeightLayers = new[] { new[, ] { { -0.80537379400399278, 0.41910423130779234, -0.97124654040321312 }, { 0.40789139000539582, -0.89706697984869466, 0.46692747025766013 }, { -0.7938561825726973, -0.74708704168834117, -0.0907913437911862 }, { 0.536301613044516, 0.1534224913289616, -0.76938811941200691 } } } }; mockExecuter.Setup(m => m.Execute(It.IsAny <FullyConnectedNeuralNetworkModel>(), It.Is <double[]>(it => it.Equals(batch[0].Inputs)))) .Returns <FullyConnectedNeuralNetworkModel, double[]>((arg1, arg2) => new double[][] { arg2, new[] { 0.23878872335077425, 0.41971501950211154, 0.66660062117031826 } }); mockExecuter.Setup(m => m.Execute(It.IsAny <FullyConnectedNeuralNetworkModel>(), It.Is <double[]>(it => it.Equals(batch[1].Inputs)))) .Returns <FullyConnectedNeuralNetworkModel, double[]>((arg1, arg2) => new double[][] { arg2, new[] { 0.51112549346515468, 0.53561880887592039, 0.61608786703901575 } }); mockSigmoidActivationFunction.Setup(m => m.CalculateDerivative(It.IsAny <double>())) .Returns <double>(arg1 => 0.5 * arg1); sut.Initialize(model); // Act sut.Learn(batch); // Assert mockExecuter.Verify(m => m.Execute(It.IsAny <FullyConnectedNeuralNetworkModel>(), It.Is <double[]>(it => it.Equals(batch[0].Inputs))), Times.Once); mockExecuter.Verify(m => m.Execute(It.IsAny <FullyConnectedNeuralNetworkModel>(), It.Is <double[]>(it => it.Equals(batch[1].Inputs))), Times.Once); mockSigmoidActivationFunction.Verify(m => m.CalculateDerivative(It.IsAny <double>()), Times.Exactly(model.BiasLayers.Sum(l => l.Length) * batch.Length)); sut.Model.Should().BeEquivalentTo(expectedResult); }
public void InitializeSetsTheModelCorrectly() { // Arrange var model = new FullyConnectedNeuralNetworkModel(); // Act sut.Initialize(model); // Assert sut.Model.Should().BeSameAs(model); }