Esempio n. 1
0
        public override void Init(Genome parent, double mutationRate)
        {
            var nnParent = (NeuronNet)parent;
            var nnSettings = (NeuronNetSettings)mSettings;
            int numLayers = nnParent.mLayers.Count + LayerMutation();
            numLayers = Util.Clamp(numLayers, nnSettings.mNumLayersMin, nnSettings.mNumLayersMax);
            int numNeurons = 0;
            int iLayer = 0;

            if (numLayers > 0)
            {
                numNeurons = AddLayer().Init(nnSettings.mNumInputs, nnParent.GetLayer(iLayer), mutationRate);
                iLayer++;

                for (int iHiddenLayer = 0; iHiddenLayer < numLayers - 1; iHiddenLayer++)
                {
                    numNeurons = AddLayer().Init(numNeurons, nnParent.GetLayer(iLayer), mutationRate);
                    iLayer++;
                }

                mOutputLayer.Init(numNeurons, nnSettings.mNumOutputs, nnParent.mOutputLayer, mutationRate);
            }
            else
            {
                mOutputLayer.Init(nnSettings.mNumInputs, nnSettings.mNumOutputs, nnParent.mOutputLayer, mutationRate);
            }
        }
Esempio n. 2
0
        private Genome SelectMate(Genome mateA)
        {
            if (mPopulation.Count <= 1)
                return null;

            if (mateA == null)
                throw new Exception();

            int orderMin = Math.Max(0, mateA.mOrder - mSettings.mMateThreshold);
            int orderMax = Math.Min(mateA.mOrder + mSettings.mMateThreshold, mPopulation.Count);
            int iMateB = Util.RandomRangeExcept(orderMin, orderMax, mateA.mOrder);
            var mateB = mPopulation[iMateB];
            mateB.mOrder = iMateB;
            return mateB;
        }
Esempio n. 3
0
 private Genome Cross(Genome parent)
 {
     var baby = (Genome)GetInstance();
     Debug.Assert(baby != null);
     baby.Init(parent, mSettings.mMutationRate);
     return baby;
 }
Esempio n. 4
0
 private Genome Cross(Genome mum, Genome dad)
 {
     var baby = (Genome)GetInstance();
     Debug.Assert(baby != null);
     baby.Init(mum, dad, mSettings.mMutationRate);
     return baby;
 }
Esempio n. 5
0
        public override void Init(Genome mum, Genome dad, double mutationRate)
        {
            var nnMum = (NeuronNet)mum;
            var nnDad = (NeuronNet)dad;
            var nnSettings = (NeuronNetSettings)mSettings;

            int numLayers = Util.RandomRange(nnMum.mLayers.Count, nnDad.mLayers.Count) + LayerMutation();
            numLayers = Util.Clamp(numLayers, nnSettings.mNumLayersMin, nnSettings.mNumLayersMax);

            int numNeurons = 0;
            int iLayer = 0;

            if (numLayers > 0)
            {
                numNeurons = AddLayer().Init(nnSettings.mNumInputs, nnMum.GetLayer(iLayer), nnDad.GetLayer(iLayer), mutationRate);
                iLayer++;

                for (int iHiddenLayer = 0; iHiddenLayer < numLayers - 1; iHiddenLayer++)
                {
                    numNeurons = AddLayer().Init(numNeurons, nnMum.GetLayer(iLayer), nnDad.GetLayer(iLayer), mutationRate);
                    iLayer++;
                }

                mOutputLayer.Init(numNeurons, nnSettings.mNumOutputs, nnMum.mOutputLayer, nnDad.mOutputLayer, mutationRate);
            }
            else
            {
                mOutputLayer.Init(nnSettings.mNumInputs, nnSettings.mNumOutputs, nnMum.mOutputLayer, nnDad.mOutputLayer, mutationRate);
            }
        }
Esempio n. 6
0
 public abstract void Init(Genome mum, Genome dad, double mutationRate);
Esempio n. 7
0
 public abstract void Init(Genome parent, double mutationRate);
Esempio n. 8
0
 public abstract void Init(Genome mum, Genome dad, double mutationRate);
Esempio n. 9
0
 public abstract void Init(Genome parent, double mutationRate);