示例#1
0
        public Genome(Genome target, List <Gene> otherGenes = null)
        {
            SpeciesId = target.SpeciesId;
            Fitness   = target.Fitness;
            CreateNetwork(target.InputCount, target.OutputCount, otherGenes ?? target.Genes);

            Assert.AreEqual(InputNeurons.Count(), target.InputCount);
            Assert.AreEqual(OutputNeurons.Count(), target.OutputCount);
        }
示例#2
0
        public Genome(int inputCount, int outputCount, float geneWeightRandomVal = 0)
        {
            if (inputCount < 1 || outputCount < 1)
            {
                throw new System.ArgumentException("Invalid initialization", "inputCount or outputCount");
            }

            SpeciesId = null;
            Fitness   = 0;

            InitStartingNeurons(inputCount, outputCount);
            InitStartingGenes(geneWeightRandomVal);

            Assert.AreEqual(InputNeurons.Count(), inputCount);
            Assert.AreEqual(OutputNeurons.Count(), outputCount);
            Assert.AreEqual(Neurons.Count, inputCount + outputCount + 1);
            Assert.AreEqual(Genes.Count, inputCount * outputCount);
        }
示例#3
0
        /// <summary>
        /// Create a network from the given genes without any prerequesties.
        /// </summary>
        /// <param name="targetGenes"></param>
        private void CreateNetwork(int inputCount, int outputCount, IEnumerable <Gene> targetGenes)
        {
            Neurons = new List <Neuron>();
            Genes   = new List <Gene>(targetGenes.Count());

            AddStartingNeurons(inputCount, outputCount);
            foreach (var gene in targetGenes)
            {
                Genes.Add(ForceConnection(gene));
            }

            InputNeurons  = Neurons.Where(x => x.Type == ENeuronType.Input);
            OutputNeurons = Neurons.Where(x => x.Type == ENeuronType.Output);

            Debug.Assert(Genes.Count == targetGenes.Count());
            Debug.Assert(InputNeurons.Count() == inputCount);
            Debug.Assert(OutputNeurons.Count() == outputCount);
        }