/// <summary>
 /// Construct a new instance.
 /// </summary>
 /// <param name="selectionStrategy">Weight selection strategy.</param>
 /// <param name="weightDeltaSampler">Weight delta sampler.</param>
 public DeltaWeightMutationStrategy(
     ISubsetSelectionStrategy selectionStrategy,
     IStatelessSampler <double> weightDeltaSampler)
 {
     _selectionStrategy  = selectionStrategy;
     _weightDeltaSampler = weightDeltaSampler;
 }
 /// <summary>
 /// Construct with the given selection strategy and weight sampler.
 /// </summary>
 /// <param name="selectionStrategy">Weight selection strategy.</param>
 /// <param name="weightSampler">Weight sampler.</param>
 public ResetWeightMutationStrategy(
     ISubsetSelectionStrategy selectionStrategy,
     IStatelessSampler <T> weightSampler)
 {
     _selectionStrategy = selectionStrategy;
     _weightSampler     = weightSampler;
 }
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="metaNeatGenome">NEAT genome metadata.</param>
        /// <param name="genomeBuilder">NeatGenome builder.</param>
        /// <param name="genomeIdSeq">Genome ID sequence; for obtaining new genome IDs.</param>
        /// <param name="generationSeq">Generation sequence; for obtaining the current generation number.</param>
        public AddCyclicConnectionStrategy(
            MetaNeatGenome <T> metaNeatGenome,
            INeatGenomeBuilder <T> genomeBuilder,
            Int32Sequence genomeIdSeq,
            Int32Sequence generationSeq)
        {
            _metaNeatGenome = metaNeatGenome;
            _genomeBuilder  = genomeBuilder;
            _genomeIdSeq    = genomeIdSeq;
            _generationSeq  = generationSeq;

            _weightSamplerA = UniformDistributionSamplerFactory.CreateStatelessSampler <T>(metaNeatGenome.ConnectionWeightScale, true);
            _weightSamplerB = UniformDistributionSamplerFactory.CreateStatelessSampler <T>(metaNeatGenome.ConnectionWeightScale * 0.01, true);
        }
Exemple #4
0
    private NeatPopulationFactory(
        MetaNeatGenome <T> metaNeatGenome,
        double connectionsProportion,
        IRandomSource rng)
    {
        _metaNeatGenome = metaNeatGenome;
        _genomeBuilder  = NeatGenomeBuilderFactory <T> .Create(metaNeatGenome);

        _connectionsProportion = connectionsProportion;

        // Define the set of all possible connections between the input and output nodes (fully interconnected).
        int inputCount  = metaNeatGenome.InputNodeCount;
        int outputCount = metaNeatGenome.OutputNodeCount;

        _connectionDefArr = new DirectedConnection[inputCount * outputCount];

        // Notes.
        // Nodes are assigned innovation IDs. By convention the input nodes are assigned IDs first starting at zero, then the output nodes.
        // Thus, because all of the evolved networks have a fixed number of inputs and outputs, the IDs of these nodes are always fixed.
        int firstOutputNodeId = inputCount;

        for (int srcId = 0, i = 0; srcId < inputCount; srcId++)
        {
            for (int tgtIdx = 0; tgtIdx < outputCount; tgtIdx++)
            {
                _connectionDefArr[i++] = new DirectedConnection(srcId, firstOutputNodeId + tgtIdx);
            }
        }

        // Init RNG and ID sequences.
        _rng         = rng;
        _genomeIdSeq = new Int32Sequence();
        int nextInnovationId = inputCount + outputCount;

        _innovationIdSeq = new Int32Sequence(nextInnovationId);

        // Init random connection weight source.
        _connWeightDist = UniformDistributionSamplerFactory.CreateStatelessSampler <T>(_metaNeatGenome.ConnectionWeightScale, true);
    }