/// <summary>
        /// Create a weight mutation strategy that applies deltas to a random subset of weights, with deltas sampled from a uniform distribution.
        /// </summary>
        /// <param name="selectionStrategy">Weight selection strategy.</param>
        /// <param name="weightScale">The uniform distribution scale.</param>
        /// <returns>A new instance of <see cref="DeltaWeightMutationStrategy"/>.</returns>
        public static DeltaWeightMutationStrategy CreateUniformDeltaStrategy(
            ISubsetSelectionStrategy selectionStrategy,
            double weightScale)
        {
            var sampler = UniformDistributionSamplerFactory.CreateStatelessSampler <double>(weightScale, true);

            return(new DeltaWeightMutationStrategy(selectionStrategy, sampler));
        }
    /// <summary>
    /// Create a weight mutation strategy that replaces a random subset of weights, with new weights sampled
    /// from a uniform distribution.
    /// </summary>
    /// <param name="selectionStrategy">Weight selection strategy.</param>
    /// <param name="weightScale">The uniform distribution scale.</param>
    /// <returns>A new instance of <see cref="ResetWeightMutationStrategy{T}"/>.</returns>
    public static ResetWeightMutationStrategy <T> CreateUniformResetStrategy(
        ISubsetSelectionStrategy selectionStrategy,
        double weightScale)
    {
        var sampler = UniformDistributionSamplerFactory.CreateStatelessSampler <T>(weightScale, true);

        return(new ResetWeightMutationStrategy <T>(selectionStrategy, sampler));
    }
        /// <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);
        }
Esempio n. 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);
    }