コード例 #1
0
 /// <summary>
 /// Read json into a target instance of <see cref="NeatReproductionAsexualSettings"/>.
 /// Settings that are present are read and set on the target settings object; all other settings
 /// remain unchanged on the target object.
 /// </summary>
 /// <param name="target">The target settings object to store the read values on.</param>
 /// <param name="jelem">The json element to read from.</param>
 public static void Read(
     NeatReproductionAsexualSettings target,
     JsonElement jelem)
 {
     ReadDoubleOptional(jelem, "connectionWeightMutationProbability", x => target.ConnectionWeightMutationProbability = x);
     ReadDoubleOptional(jelem, "addNodeMutationProbability", x => target.AddNodeMutationProbability                   = x);
     ReadDoubleOptional(jelem, "addConnectionMutationProbability", x => target.AddConnectionMutationProbability       = x);
     ReadDoubleOptional(jelem, "deleteConnectionMutationProbability", x => target.DeleteConnectionMutationProbability = x);
     target.Validate();
 }
コード例 #2
0
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="eaSettings">NEAT evolution algorithm settings.</param>
        /// <param name="evaluator">An evaluator of lists of genomes.</param>
        /// <param name="speciationStrategy">Speciation strategy.</param>
        /// <param name="population">An initial population of genomes.</param>
        /// <param name="complexityRegulationStrategy">Complexity regulation strategy.</param>
        /// <param name="reproductionAsexualSettings">Asexual reproduction settings.</param>
        /// <param name="reproductionSexualSettings">Sexual reproduction settings.</param>
        /// <param name="weightMutationScheme">Connection weight mutation scheme.</param>
        /// <param name="rng">Random source.</param>
        public NeatEvolutionAlgorithm(
            NeatEvolutionAlgorithmSettings eaSettings,
            IGenomeListEvaluator <NeatGenome <T> > evaluator,
            ISpeciationStrategy <NeatGenome <T>, T> speciationStrategy,
            NeatPopulation <T> population,
            IComplexityRegulationStrategy complexityRegulationStrategy,
            NeatReproductionAsexualSettings reproductionAsexualSettings,
            NeatReproductionSexualSettings reproductionSexualSettings,
            WeightMutationScheme <T> weightMutationScheme,
            IRandomSource rng)
        {
            // Perform some basic validation of the provided settings objects.
            eaSettings.Validate();
            reproductionAsexualSettings.Validate();
            reproductionSexualSettings.Validate();

            // Store instance fields, and null check as we go.
            _eaSettingsCurrent       = eaSettings ?? throw new ArgumentNullException(nameof(eaSettings));
            _eaSettingsComplexifying = eaSettings;
            _eaSettingsSimplifying   = eaSettings.CreateSimplifyingSettings();

            _evaluator          = evaluator ?? throw new ArgumentNullException(nameof(evaluator));
            _speciationStrategy = speciationStrategy ?? throw new ArgumentNullException(nameof(speciationStrategy));
            _pop = population ?? throw new ArgumentNullException(nameof(population));
            _complexityRegulationStrategy = complexityRegulationStrategy ?? throw new ArgumentNullException(nameof(complexityRegulationStrategy));

            if (reproductionAsexualSettings is null)
            {
                throw new ArgumentNullException(nameof(reproductionAsexualSettings));
            }
            if (reproductionSexualSettings is null)
            {
                throw new ArgumentNullException(nameof(reproductionSexualSettings));
            }

            _rng = rng;
            _genomeComparerDescending = new GenomeComparerDescending(evaluator.FitnessComparer);

            if (eaSettings.SpeciesCount > population.PopulationSize)
            {
                throw new ArgumentException("Species count is higher then the population size.");
            }

            _generationSeq = new Int32Sequence();

            _reproductionAsexual = new NeatReproductionAsexual <T>(
                _pop.MetaNeatGenome, _pop.GenomeBuilder,
                _pop.GenomeIdSeq, population.InnovationIdSeq, _generationSeq,
                _pop.AddedNodeBuffer, reproductionAsexualSettings, weightMutationScheme);

            _reproductionSexual = new NeatReproductionSexual <T>(
                _pop.MetaNeatGenome, _pop.GenomeBuilder,
                _pop.GenomeIdSeq, _generationSeq,
                reproductionSexualSettings);

            _offspringBuilder = new OffspringBuilder <T>(
                _reproductionAsexual,
                _reproductionSexual,
                eaSettings.InterspeciesMatingProportion,
                evaluator.FitnessComparer);
        }