Example #1
0
    public void CreateGenerationFromPreviousTest()
    {
        // Arrange
        int[]      hiddenLayers = new int[] { 4, 3, 6 };
        CarSpecies species      = CarSpecies.CreateInstance(typeof(CarSpecies)) as CarSpecies;

        species.GenerationSize = 100;
        species.HeterogeneousHiddenActivation  = false;
        species.HiddenLayersNeuronCount        = hiddenLayers;
        species.ActivationMutationSeverity     = 0f;
        species.ProportionUnchanged            = 0.05f;
        species.ProportionMutatantsOfUnchanged = 0.2f;
        species.OffspringMutationProbability   = 0.5f;
        species.NewDnaRate = 0.05f;

        Generation seed = Generation.CreateSeed(species, 1);

        AssertDnaHeterogeneity(seed.GenePool);

        // Act
        Generation TNG = Generation.FromPrevious(seed, 1);

        // Assert
        AssertOnDerrivedGenerationDna(species, seed.GenePool, TNG.GenePool);
    }
Example #2
0
    public void CreateSeedGenerationTest()
    {
        // Arrange
        int spawnIndex = 3;

        int[]      hiddenLayers = new int[] { 4, 3, 6 };
        CarSpecies species      = CarSpecies.CreateInstance(typeof(CarSpecies)) as CarSpecies;

        species.HiddenLayersNeuronCount = hiddenLayers;
        int[] expectedOutputsPerLayer = new int[]
        {
            species.Inputs,
            hiddenLayers[0],
            hiddenLayers[1],
            hiddenLayers[2],
            CarSpecies.Outputs,
        };

        // Act
        Generation TNG = Generation.CreateSeed(species, spawnIndex);

        // Assert
        TNG.SpawnLocationIndex.Should().Be(spawnIndex);
        TNG.GenePool.Should().HaveCount(species.GenerationSize);
        TNG.GenePool.Should().OnlyHaveUniqueItems();
        AssertDnaHeterogeneity(TNG.GenePool);
        foreach (Dna dna in TNG.GenePool)
        {
            dna.Heritage.Should().Be(DnaHeritage.New);
            dna.OutputsPerLayer.Should().Equal(expectedOutputsPerLayer);
        }
    }
Example #3
0
    public void CreateGenerationsIterativelyTest()
    {
        // Arrange
        int[]      hiddenLayers = new int[] { 4, 3, 6 };
        CarSpecies species      = CarSpecies.CreateInstance(typeof(CarSpecies)) as CarSpecies;

        species.GenerationSize = 100;
        species.HeterogeneousHiddenActivation  = false;
        species.HiddenLayersNeuronCount        = hiddenLayers;
        species.ActivationMutationSeverity     = 0f;
        species.ProportionUnchanged            = 0.05f;
        species.ProportionMutatantsOfUnchanged = 0.2f;
        species.OffspringMutationProbability   = 0.5f;
        species.NewDnaRate      = 0.05f;
        species.CrossoverPasses = 5;

        Generation seed = Generation.CreateSeed(species, 1);

        AssertDnaHeterogeneity(seed.GenePool);

        Generation previous = seed;

        for (int i = 1; i < 101; i++)
        {
            AssignFakeFitness(previous);

            // Act
            Generation TNG = Generation.FromPrevious(previous, 1);
            Debug.Log("Created gen " + i);

            // Assert
            AssertOnDerrivedGenerationDna(species, previous.GenePool, TNG.GenePool);

            previous = TNG;
        }
    }