Exemple #1
0
 /// <summary>
 /// Construct with the default distribution parameters, and a new random source.
 /// </summary>
 public BoxMullerGaussianSampler()
     : this(0.0, 1.0, RandomDefaults.CreateRandomSource())
 {
 }
Exemple #2
0
 /// <summary>
 /// Construct with the given distribution parameters, and a new random source.
 /// </summary>
 /// <param name="mean">Distribution mean.</param>
 /// <param name="stdDev">Distribution standard deviation.</param>
 /// <param name="seed">Random source seed.</param>
 public BoxMullerGaussianSampler(double mean, double stdDev, ulong seed)
     : this(mean, stdDev, RandomDefaults.CreateRandomSource(seed))
 {
 }
Exemple #3
0
 /// <summary>
 /// Construct with the default distribution parameters, and a new random source.
 /// </summary>
 public ZigguratGaussianSampler()
     : this(0.0, 1.0, RandomDefaults.CreateRandomSource())
 {
 }
Exemple #4
0
 /// <summary>
 /// Construct with the given distribution parameters, and a new random source.
 /// </summary>
 /// <param name="mean">Distribution mean.</param>
 /// <param name="stdDev">Distribution standard deviation.</param>
 public ZigguratGaussianSampler(double mean, double stdDev)
     : this(mean, stdDev, RandomDefaults.CreateRandomSource())
 {
 }
 /// <summary>
 /// Construct a uniform distribution generator with the provided random seed.
 /// If {signed} is false the distribution interval is [0, scale), otherwise it is (-scale, +scale).
 /// </summary>
 public UniformDistribution(float scale, bool signed, ulong seed)
     : this(scale, signed, RandomDefaults.CreateRandomSource(seed))
 {
 }
        public void TestCreateGenome()
        {
            var metaNeatGenome = new MetaNeatGenome <double>(
                inputNodeCount: 10,
                outputNodeCount: 20,
                isAcyclic: true,
                activationFn: new SharpNeat.NeuralNet.Double.ActivationFunctions.ReLU());

            var genomeBuilder = NeatGenomeBuilderFactory <double> .Create(metaNeatGenome);

            int count = 100;
            NeatPopulation <double> pop = NeatPopulationFactory <double> .CreatePopulation(metaNeatGenome, 0.1, count, RandomDefaults.CreateRandomSource());

            var strategy = new UniformCrossoverReproductionStrategy <double>(
                pop.MetaNeatGenome, genomeBuilder,
                pop.GenomeIdSeq, pop.GenerationSeq,
                RandomDefaults.CreateRandomSource());

            IRandomSource rng = RandomDefaults.CreateRandomSource(0);

            var cyclicGraphAnalysis = new CyclicGraphAnalysis();

            for (int i = 0; i < 1000; i++)
            {
                // Randomly select two parents from the population.
                var genome1 = pop.GenomeList[rng.Next(count)];
                var genome2 = pop.GenomeList[rng.Next(count)];

                var childGenome = strategy.CreateGenome(genome1, genome2);

                // The connection genes should be sorted.
                Assert.IsTrue(SortUtils.IsSortedAscending(childGenome.ConnectionGenes._connArr));

                // The child genome should describe an acyclic graph, i.e. the new connection should not have
                // formed a cycle in the graph.
                var digraph = childGenome.DirectedGraph;
                Assert.IsFalse(cyclicGraphAnalysis.IsCyclic(digraph));

                // The child genome node IDs should be a superset of those from parent1 + parent2.
                var childNodeIdSet = GetNodeIdSet(childGenome);
                var parentIdSet    = GetNodeIdSet(genome1);
                parentIdSet.IntersectWith(GetNodeIdSet(genome2));

                Assert.IsTrue(childNodeIdSet.IsSupersetOf(parentIdSet));
            }
        }
 /// <summary>
 /// Construct a uniform distribution generator over the interval [0,1).
 /// </summary>
 public UniformDistribution()
     : this(1f, false, RandomDefaults.CreateRandomSource())
 {
 }
 /// <summary>
 /// Construct a uniform distribution generator over the interval [0,1) with the provided random seed.
 /// </summary>
 public UniformDistribution(ulong seed)
     : this(1f, false, RandomDefaults.CreateRandomSource(seed))
 {
 }
Exemple #9
0
        public void TestInitialConnections()
        {
            MetaNeatGenome <double> metaNeatGenome = new MetaNeatGenome <double>(
                inputNodeCount: 100,
                outputNodeCount: 200,
                isAcyclic: true,
                activationFn: new NeuralNet.Double.ActivationFunctions.ReLU());

            NeatPopulation <double> neatPop = NeatPopulationFactory <double> .CreatePopulation(metaNeatGenome, 0.5, 1, RandomDefaults.CreateRandomSource());

            NeatGenome <double> genome = neatPop.GenomeList[0];

            Assert.AreEqual(10000, genome.ConnectionGenes.Length);
            Assert.IsTrue(SortUtils.IsSortedAscending(genome.ConnectionGenes._connArr));

            CalcWeightMinMaxMean(genome.ConnectionGenes._weightArr, out double min, out double max, out double mean);

            Assert.IsTrue(min < -genome.MetaNeatGenome.ConnectionWeightScale * 0.98);
            Assert.IsTrue(max > genome.MetaNeatGenome.ConnectionWeightScale * 0.98);
            Assert.IsTrue(Math.Abs(mean) < 0.1);
        }
Exemple #10
0
 /// <summary>
 /// Construct with the given distribution and a new random source.
 /// </summary>
 /// <param name="max">Maximum absolute value.</param>
 /// <param name="signed">Indicates if the distribution interval includes negative values.</param>
 /// <param name="seed">Random source seed.</param>
 public UniformDistributionSampler(float max, bool signed, ulong seed)
     : this(max, signed, RandomDefaults.CreateRandomSource(seed))
 {
 }
Exemple #11
0
        public void TestCreatePopulation()
        {
            MetaNeatGenome <double> metaNeatGenome = new MetaNeatGenome <double>(
                inputNodeCount: 3,
                outputNodeCount: 2,
                isAcyclic: true,
                activationFn: new NeuralNet.Double.ActivationFunctions.ReLU());

            int count = 10;
            NeatPopulation <double> neatPop = NeatPopulationFactory <double> .CreatePopulation(metaNeatGenome, 1.0, count, RandomDefaults.CreateRandomSource());

            Assert.AreEqual(count, neatPop.GenomeList.Count);
            Assert.AreEqual(count, neatPop.GenomeIdSeq.Peek);

            // The population factory assigns the same innovation IDs to matching structures in the genomes it creates.
            // In this test there are 5 nodes and 6 connections in each genome, and they are each identifiably
            // the same structure in each of the genomes (e.g. input 0 or whatever) and so have the same innovation ID
            // across all of the genomes.
            // Thus in total although we created N genomes there are only 5 innovation IDs allocated (5 nodes).
            Assert.AreEqual(5, neatPop.InnovationIdSeq.Peek);

            // Loop the created genomes.
            for (int i = 0; i < count; i++)
            {
                var genome = neatPop.GenomeList[i];
                Assert.AreEqual(i, genome.Id);
                Assert.AreEqual(0, genome.BirthGeneration);

                TestGenome(genome);
            }
        }
 /// <summary>
 /// Construct with the given distribution and a new random source.
 /// </summary>
 /// <param name="dist">Discrete distribution.</param>
 /// <param name="seed">Random source seed.</param>
 public DiscreteDistributionSampler(DiscreteDistribution dist, ulong seed)
 {
     _dist = dist;
     _rng  = RandomDefaults.CreateRandomSource(seed);
 }
Exemple #13
0
        private static Species <double> CreateTestSpecies(int genomeCount)
        {
            // Create the species genomes; we use NeatPopulationFactory for this.
            MetaNeatGenome <double> metaNeatGenome = new(
                inputNodeCount : 1,
                outputNodeCount : 1,
                isAcyclic : true,
                activationFn : new SharpNeat.NeuralNets.Double.ActivationFunctions.ReLU());

            NeatPopulation <double> neatPop = NeatPopulationFactory <double> .CreatePopulation(metaNeatGenome, 1.0, genomeCount, RandomDefaults.CreateRandomSource());

            // Create the species object, and assign all of the created genomes to it.
            var species = new Species <double>(0, new ConnectionGenes <double>(0));

            species.GenomeList.AddRange(neatPop.GenomeList);

            // Return the species.
            return(species);
        }
Exemple #14
0
 /// <summary>
 /// Construct with the given distribution parameters, and a new random source.
 /// </summary>
 /// <param name="mean">Distribution mean.</param>
 /// <param name="stdDev">Distribution standard deviation.</param>
 public BoxMullerGaussianSampler(float mean, float stdDev)
     : this(mean, stdDev, RandomDefaults.CreateRandomSource())
 {
 }
Exemple #15
0
        private static NeatPopulation <double> CreateNeatPopulation(
            int count,
            int inputNodeCount,
            int outputNodeCount,
            double connectionsProportion)
        {
            MetaNeatGenome <double> metaNeatGenome = new MetaNeatGenome <double>(
                inputNodeCount: inputNodeCount,
                outputNodeCount: outputNodeCount,
                isAcyclic: true,
                activationFn: new SharpNeat.NeuralNets.Double.ActivationFunctions.ReLU());

            NeatPopulation <double> neatPop = NeatPopulationFactory <double> .CreatePopulation(metaNeatGenome, connectionsProportion, count, RandomDefaults.CreateRandomSource());

            return(neatPop);
        }