示例#1
0
        public void ConnectRandomly(RMP_NeuronGene gene, bool isInputNeuron)
        {
            int connectionCount;

            if (isInputNeuron)
            {
                connectionCount = HiddenNeuronGenes.Count;
            }
            else
            {
                connectionCount = HiddenNeuronGenes.Count + OutputNeuronGenes.Count;
            }

            gene.Connections.Clear();

            for (int i = 0; i < connectionCount; i++)
            {
                if (ConnectionChance < Pseudo.Random.NextDouble())
                {
                    continue;
                }

                gene.Connections.Add(GetRandomConnection(gene, isInputNeuron));
            }
        }
示例#2
0
        public RMP_NeuronGene GetRandomOutputNeuronGene()
        {
            var gene = new RMP_NeuronGene(GlobalOutputSigmoidFunction);

            gene.Bias.Value = Math.Pow(Pseudo.Random.NextDouble(gene.Bias.Min, gene.Bias.Max), 2);
            gene.SigmoidFunction.Randomize();

            return(gene);
        }
示例#3
0
        public void ImprintGene(RMP_NeuronGene gene)
        {
            Name   = gene.Name;
            GeneID = gene.ID;

            Bias = gene.Bias.Value;

            SigmoidFunction = (SigmoidFunction)gene.SigmoidFunction.Clone();
        }
示例#4
0
        public override Gene Clone()
        {
            var gene = new RMP_NeuronGene(GeneHeritage, (SigmoidFunction)SigmoidFunction.Clone());

            gene.IsMutable = IsMutable;
            gene.Bias      = Bias;

            foreach (var connection in Connections)
            {
                gene.Connections.Add((RMP_ConnectionGene)connection.Clone());
            }

            return(gene);
        }
示例#5
0
        public RMP_ConnectionGene GetRandomConnection(RMP_NeuronGene host, bool hostIsInputNeuron)
        {
            int connectionCount;

            if (hostIsInputNeuron)
            {
                connectionCount = HiddenNeuronGenes.Count;
            }
            else
            {
                connectionCount = HiddenNeuronGenes.Count + OutputNeuronGenes.Count;
            }

            int  targetIndex;
            bool unique;

            do
            {
                targetIndex = Pseudo.Random.Next(connectionCount);

                unique = true;
                foreach (RMP_ConnectionGene connectionGene in host.Connections)
                {
                    if (connectionGene.Target == targetIndex)
                    {
                        unique = false;
                    }
                }
            } while (!unique);

            if (targetIndex < HiddenNeuronGenes.Count)
            {
                return(GetRandomConnection(targetIndex, false));
            }
            else
            {
                return(GetRandomConnection(targetIndex - HiddenNeuronGenes.Count, true));
            }
        }