コード例 #1
0
        public void LearnPerformsTheCorrectCalls()
        {
            // Arrange
            var model = CreateFullyConnectedNeuralNetworkModel();
            var batch = CreateBatch();

            mockModelExecuter.Setup(m => m.Execute(It.IsAny <FullyConnectedNeuralNetworkModel>(), It.IsAny <double[]>()))
            .Returns(activationCountsPerLayer.Select(l => CreateAndInitializeDoubleArray(l, () => 0.5)).ToArray());
            // Setup 1 member of the population to return the desired output for the batches
            mockModelExecuter.Setup(m => m.Execute(It.Is <FullyConnectedNeuralNetworkModel>(it => it.Equals(population[1])), batch[0].Inputs))
            .Returns(new[] { batch[0].Outputs });
            mockModelExecuter.Setup(m => m.Execute(It.Is <FullyConnectedNeuralNetworkModel>(it => it.Equals(population[1])), batch[1].Inputs))
            .Returns(new[] { batch[1].Outputs });

            mockPopulationBreeder.Setup(m => m.CreateNextGeneration(It.Is <FullyConnectedNeuralNetworkModel[]>(it => it.Length == 2), populationSize))
            .Returns(() => CreateManyFullyConnectedNeuralNetworkModel(populationSize - selectionSize));

            sut.Initialize(model);
            population.Add(model);

            // Act
            sut.Learn(batch);

            // Assert
            mockModelExecuter.Verify(m => m.Execute(It.IsAny <FullyConnectedNeuralNetworkModel>(), It.IsAny <double[]>()), Times.Exactly(6));
            mockModelExecuter.Verify(m => m.Execute(It.Is <FullyConnectedNeuralNetworkModel>(it => it.Equals(population[1])), batch[0].Inputs), Times.Once);
            mockModelExecuter.Verify(m => m.Execute(It.Is <FullyConnectedNeuralNetworkModel>(it => it.Equals(population[1])), batch[1].Inputs), Times.Once);
            mockPopulationBreeder.Verify(m => m.CreateNextGeneration(It.Is <FullyConnectedNeuralNetworkModel[]>(it => it.Length == 2), populationSize), Times.Once);
            sut.Model.Should().BeSameAs(population[1]);
        }
コード例 #2
0
        public void CallCreateNextGeneration()
        {
            // Arrange
            var model = modelInitializer.CreateModel(activationCountsPerLayer, activationFunction);

            sut.Initialize(model);

            // Act
            // sut.CreateNextGeneration();

            // Assert
        }
コード例 #3
0
        public void InitializeCorrectlySetsTheModel()
        {
            // Arrange
            var model = CreateFullyConnectedNeuralNetworkModel();
            var activationCountsPerLayer = new[] { 4, 3 };
            Expression <Func <IModelInitializer, FullyConnectedNeuralNetworkModel> > createModelFunction = m => m.CreateModel(activationCountsPerLayer, model.ActivationFunction);

            mockModelInitializer.Setup(createModelFunction)
            .Returns(CreateFullyConnectedNeuralNetworkModel);

            // Act
            sut.Initialize(model);

            // Assert
            mockModelInitializer.Verify(createModelFunction, Times.Exactly(populationSize - 1));
            sut.Model.Should().BeSameAs(model);
        }