/// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="copyFrom">The settings object to copy.</param>
 public NeatReproductionAsexualSettings(NeatReproductionAsexualSettings copyFrom)
 {
     this.ConnectionWeightMutationProbability = copyFrom.ConnectionWeightMutationProbability;
     this.AddNodeMutationProbability          = copyFrom.AddNodeMutationProbability;
     this.AddConnectionMutationProbability    = copyFrom.AddConnectionMutationProbability;
     this.DeleteConnectionMutationProbability = copyFrom.DeleteConnectionMutationProbability;
 }
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="metaNeatGenome">NeatGenome metadata.</param>
        /// <param name="genomeBuilder">NeatGenome builder.</param>
        /// <param name="genomeIdSeq">Genome ID sequence; for obtaining new genome IDs.</param>
        /// <param name="innovationIdSeq">Innovation ID sequence; for obtaining new innovation IDs.</param>
        /// <param name="generationSeq">Generation sequence; for obtaining the current generation number.</param>
        /// <param name="addedNodeBuffer">A history buffer of added nodes.</param>
        /// <param name="settings">Asexual reproduction settings.</param>
        /// <param name="weightMutationScheme">Connection weight mutation scheme.</param>
        public NeatReproductionAsexual(
            MetaNeatGenome <T> metaNeatGenome,
            INeatGenomeBuilder <T> genomeBuilder,
            Int32Sequence genomeIdSeq,
            Int32Sequence innovationIdSeq,
            Int32Sequence generationSeq,
            AddedNodeBuffer addedNodeBuffer,
            NeatReproductionAsexualSettings settings,
            WeightMutationScheme <T> weightMutationScheme)
        {
            _settings = settings;

            // Instantiate reproduction strategies.
            _mutateWeightsStrategy    = new MutateWeightsStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, generationSeq, weightMutationScheme);
            _deleteConnectionStrategy = new DeleteConnectionStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, generationSeq);

            // Add connection mutation; select acyclic/cyclic strategy as appropriate.
            if (metaNeatGenome.IsAcyclic)
            {
                _addConnectionStrategy = new AddAcyclicConnectionStrategy <T>(
                    metaNeatGenome, genomeBuilder,
                    genomeIdSeq, innovationIdSeq, generationSeq);
            }
            else
            {
                _addConnectionStrategy = new AddCyclicConnectionStrategy <T>(
                    metaNeatGenome, genomeBuilder,
                    genomeIdSeq, innovationIdSeq, generationSeq);
            }

            _addNodeStrategy = new AddNodeStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, innovationIdSeq, generationSeq, addedNodeBuffer);
        }
示例#3
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="jobj">The json object to read from.</param>
 public static void Read(
     NeatReproductionAsexualSettings target,
     JObject jobj)
 {
     ReadDoubleOptional(jobj, "connectionWeightMutationProbability", x => target.ConnectionWeightMutationProbability = x);
     ReadDoubleOptional(jobj, "addNodeMutationProbability", x => target.AddNodeMutationProbability                   = x);
     ReadDoubleOptional(jobj, "addConnectionMutationProbability", x => target.AddConnectionMutationProbability       = x);
     ReadDoubleOptional(jobj, "deleteConnectionMutationProbability", x => target.DeleteConnectionMutationProbability = x);
 }
 /// <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();
 }
 /// <summary>
 /// Create a new instance of <see cref="DiscreteDistribution"/> that represents a subset of the possible
 /// genome mutation types, and their relative probabilities. The subset consists of mutation types that
 /// are non-destructive (i.e. weight mutation, add node mutation, add connection mutation).
 /// </summary>
 /// <param name="settings">Asexual reproduction settings.</param>
 /// <returns>A new instance of <see cref="DiscreteDistribution"/>.</returns>
 private static DiscreteDistribution CreateMutationTypeDiscreteDistribution_NonDestructive(
     NeatReproductionAsexualSettings settings)
 {
     double[] probabilities = new double[]
     {
         settings.ConnectionWeightMutationProbability,
         settings.AddNodeMutationProbability,
         settings.AddConnectionMutationProbability
     };
     return(new DiscreteDistribution(probabilities));
 }
        /// <summary>
        /// Creates a new settings object based on the current settings object, but modified to be suitable for use when
        /// the evolution algorithm is in simplifying mode.
        /// </summary>
        /// <returns>A new instance of <see cref="NeatReproductionAsexualSettings"/>.</returns>
        public NeatReproductionAsexualSettings CreateSimplifyingSettings()
        {
            // Invoke the copy constructor with the current object.
            //
            // Note. Currently all of the settings are modified, therefore it's not necessary to use the copy constructor
            // however, if additional settings are added to the settings class then they will be handled automatically here
            // without having to update this code, so this is a slightly safer approach.
            var settings = new NeatReproductionAsexualSettings(this)
            {
                ConnectionWeightMutationProbability = 0.6,
                AddNodeMutationProbability          = 0.0,
                AddConnectionMutationProbability    = 0.0,
                DeleteConnectionMutationProbability = 0.4
            };

            return(settings);
        }
        /// <summary>
        /// Notify the strategy of a change in complexity regulation mode in the evolution algorithm.
        /// </summary>
        /// <param name="mode">The current mode.</param>
        public void NotifyComplexityRegulationMode(ComplexityRegulationMode mode)
        {
            switch (mode)
            {
            case ComplexityRegulationMode.Complexifying:
                _settingsCurrent = _settingsComplexifying;
                _mutationTypeDistributionsCurrent = _mutationTypeDistributionsComplexifying;
                break;

            case ComplexityRegulationMode.Simplifying:
                _settingsCurrent = _settingsSimplifying;
                _mutationTypeDistributionsCurrent = _mutationTypeDistributionsSimplifying;
                break;

            default:
                throw new ArgumentException("Unexpected complexity regulation mode.");
            }
        }
示例#8
0
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="metaNeatGenome">NeatGenome metadata.</param>
        /// <param name="genomeBuilder">NeatGenome builder.</param>
        /// <param name="genomeIdSeq">Genome ID sequence; for obtaining new genome IDs.</param>
        /// <param name="innovationIdSeq">Innovation ID sequence; for obtaining new innovation IDs.</param>
        /// <param name="generationSeq">Generation sequence; for obtaining the current generation number.</param>
        /// <param name="addedNodeBuffer">A history buffer of added nodes.</param>
        /// <param name="settings">Asexual reproduction settings.</param>
        /// <param name="weightMutationScheme">Connection weight mutation scheme.</param>
        public NeatReproductionAsexual(
            MetaNeatGenome <T> metaNeatGenome,
            INeatGenomeBuilder <T> genomeBuilder,
            Int32Sequence genomeIdSeq,
            Int32Sequence innovationIdSeq,
            Int32Sequence generationSeq,
            AddedNodeBuffer addedNodeBuffer,
            NeatReproductionAsexualSettings settings,
            WeightMutationScheme <T> weightMutationScheme)
        {
            var settingsComplexifying = settings;
            var settingsSimplifying   = settings.CreateSimplifyingSettings();

            _mutationTypeDistributionsComplexifying = new MutationTypeDistributions(settingsComplexifying);
            _mutationTypeDistributionsSimplifying   = new MutationTypeDistributions(settingsSimplifying);
            _mutationTypeDistributionsCurrent       = _mutationTypeDistributionsComplexifying;

            // Instantiate reproduction strategies.
            _mutateWeightsStrategy    = new MutateWeightsStrategy <T>(genomeBuilder, genomeIdSeq, generationSeq, weightMutationScheme);
            _deleteConnectionStrategy = new DeleteConnectionStrategy <T>(genomeBuilder, genomeIdSeq, generationSeq);

            // Add connection mutation; select acyclic/cyclic strategy as appropriate.
            if (metaNeatGenome.IsAcyclic)
            {
                _addConnectionStrategy = new AddAcyclicConnectionStrategy <T>(
                    metaNeatGenome, genomeBuilder,
                    genomeIdSeq, generationSeq);
            }
            else
            {
                _addConnectionStrategy = new AddCyclicConnectionStrategy <T>(
                    metaNeatGenome, genomeBuilder,
                    genomeIdSeq, generationSeq);
            }

            _addNodeStrategy = new AddNodeStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, innovationIdSeq, generationSeq, addedNodeBuffer);
        }
 /// <summary>
 /// Construct a new instance.
 /// </summary>
 /// <param name="settings">Asexual reproduction settings.</param>
 public MutationTypeDistributions(NeatReproductionAsexualSettings settings)
 {
     this.MutationTypeDistribution = CreateMutationTypeDiscreteDistribution(settings);
     this.MutationTypeDistributionNonDestructive = CreateMutationTypeDiscreteDistribution_NonDestructive(settings);
 }