コード例 #1
0
 public QuickBlackBox(QEAGenome genome)
 {
     this.genome        = genome;
     inputs             = new double[InputCount];
     outputs            = new double[OutputCount];
     _inputSignalArray  = new SignalArray(inputs, 0, inputs.Length);
     _outputSignalArray = new SignalArray(outputs, 0, outputs.Length);
 }
コード例 #2
0
        public QEAGenome createOffspring() // asexual reproduction
        {
            QEAGenome child = new QEAGenome(this);

            for (int i = 0; i < child.weights.Length; i++)
            {
                for (int j = 0; j < child.weights[i].Length; j++)
                {
                    for (int k = 0; k < child.weights[i][j].Length; k++)
                    {
                        if (r.NextDouble() < LEEAParams.MUTATIONRATE)
                        {
                            child.weights[i][j][k] += (float)(r.NextDouble() * QuickEvolutionAlgorithm.MUTATIONPOWER * 2 - QuickEvolutionAlgorithm.MUTATIONPOWER);
                        }
                    }
                }
            }
            return(child);
        }
コード例 #3
0
        public QEAGenome createOffspring(QEAGenome parent2) // sexual reproduction
        {
            QEAGenome child = new QEAGenome(this);

            for (int i = 0; i < weights.Length; i++)
            {
                for (int j = 0; j < weights[i].Length; j++)
                {
                    for (int k = 0; k < weights[i][j].Length; k++)
                    {
                        if (r.NextDouble() < 0.5)
                        {
                            weights[i][j][k] = parent2.weights[i][j][k];
                        }
                    }
                }
            }
            return(child);
        }
コード例 #4
0
        public BackpropAlgorithm()
        {
            LEEAParams.DOMAIN.generateSampleList();
            evaluator = LEEAParams.DOMAIN.createEvaluator();

            // initialize the network, use the QEAGenome class since it's already structured well for this task
            int layers = LEEAParams.DOMAIN.getHiddenLayers() + 1; // layers needs to be the number of layers of connections

            int[] layerNodes = new int[layers + 1];

            layerNodes[0] = LEEAParams.DOMAIN.getInputs() + 1; // +1 for the bias!
            for (int i = 0; i < layers - 1; i++)
            {
                layerNodes[i + 1] = LEEAParams.DOMAIN.getHiddenLayerNeurons(i + 1);
            }

            layerNodes[layers] = LEEAParams.DOMAIN.getOutputs();

            network = new QEAGenome(layers, layerNodes, LEEAParams.BPINITIALWEIGHTMAX);
            box     = new QuickBlackBox(network);
        }
コード例 #5
0
        private void createPopulation()
        {
            genomeList = new List <QEAGenome>();

            int layers = LEEAParams.DOMAIN.getHiddenLayers() + 1; // layers needs to be the number of layers of connections

            int[] layerNodes = new int[layers + 1];

            layerNodes[0] = LEEAParams.DOMAIN.getInputs() + 1; // +1 for the bias!
            for (int i = 0; i < layers - 1; i++)
            {
                layerNodes[i + 1] = LEEAParams.DOMAIN.getHiddenLayerNeurons(i + 1);
            }

            layerNodes[layers] = LEEAParams.DOMAIN.getOutputs();

            Parallel.For(0, LEEAParams.POPSIZE, po, i =>
            {
                QEAGenome genome = new QEAGenome(layers, layerNodes, 1);
                lock (genomeList)
                {
                    genomeList.Add(genome);
                }
            });

            // set up our worker threads
            int end;

            for (int i = 0; i < workers.Length; i++)
            {
                end        = start + genomeList.Count / LEEAParams.THREADS;
                workers[i] = new EvaluationWorker(start, end, genomeList, evaluator);
                start      = end;
            }

            // speciate the newly created folks
            speciatePopulation();
        }
コード例 #6
0
 public QEAGenome(QEAGenome copy)
 {
     r            = new FastRandom();
     this.weights = copyArray(copy.weights);
 }