示例#1
0
 public void setOutputLayer(NeuronLayer outputLayer)
 {
     System.Random random = GlobalRandom.getInstance().getRandom();
     foreach (AbstractNeuron neuron in neuronList)
     {
         foreach (AbstractNeuron output in outputLayer.neuronList)
         {
             output.addInput(neuron, random.NextDouble() - random.NextDouble());
         }
     }
 }
示例#2
0
 public void setOutputLayer(NeuronLayer layer)
 {
     System.Random random = GlobalRandom.getInstance().getRandom();
     foreach (IOutputValue input in inputs)
     {
         foreach (AbstractNeuron neuron in layer.getNeuronList())
         {
             neuron.addInput(input, random.NextDouble() - random.NextDouble());
         }
     }
 }
示例#3
0
 public override void generateWaypoints()
 {
     flightPath.Clear();
     for (int i = 0; i < pathSize; i++)
     {
         System.Random  random   = GlobalRandom.getInstance().getRandom();
         float          x        = (float)random.NextDouble() * fieldSize.x - (float)random.NextDouble() * fieldSize.x;
         float          y        = (float)random.NextDouble() * fieldSize.y - (float)random.NextDouble() * fieldSize.y;
         float          z        = (float)random.NextDouble() * fieldSize.z - (float)random.NextDouble() * fieldSize.z;
         FlightWaypoint waypoint = Instantiate(wayPointPrefab, new Vector3(x, y, z), Quaternion.identity);
         flightPath.Add(waypoint);
     }
 }
示例#4
0
    public void mutateViolently(double mutationRate)
    {
        List <double> newWeights = new List <double>();

        System.Random random = GlobalRandom.getInstance().getRandom();
        foreach (double weight in weights)
        {
            if (random.NextDouble() < mutationRate)
            {
                newWeights.Add(generateRandomGene());
            }
            else
            {
                newWeights.Add(weight);
            }
        }
        weights = newWeights;
    }
示例#5
0
    private Chromosome selectRandomChromosome()
    {
        System.Random random = GlobalRandom.getInstance().getRandom();
        double        slice  = totalFitness * random.NextDouble();

        double accumulatedFitness = 0;

        foreach (Chromosome chromosome in chromosomes)
        {
            accumulatedFitness += chromosome.getFitness();

            if (accumulatedFitness >= slice)
            {
                return(chromosome);
            }
        }

        return(chromosomes[chromosomes.Count - 1]);
    }
示例#6
0
    private void crossover(Chromosome a, Chromosome b, List <Chromosome> population)
    {
        System.Random random = GlobalRandom.getInstance().getRandom();
        if (random.NextDouble() > crossoverRate)
        {
            a.mutate(mutationRate, mutationPower);
            b.mutate(mutationRate, mutationPower);
            population.Add(a);
            population.Add(b);
        }
        else
        {
            int crossoverIndex = random.Next(chromosomeLength - 1);

            Chromosome child1 = a.crossover(b, crossoverIndex);
            Chromosome child2 = b.crossover(a, crossoverIndex);

            child1.mutate(mutationRate, mutationPower);
            child2.mutate(mutationRate, mutationPower);
            population.Add(child1);
            population.Add(child2);
        }
    }
示例#7
0
 public static double generateRandomGene()
 {
     System.Random random = GlobalRandom.getInstance().getRandom();
     return(random.NextDouble() - random.NextDouble());
 }