private void Crossover(NNet[] newPopulation)
    {
        for (int i = 0; i < numberToCrossover; i += 2)
        {
            int AIndex = i;
            int BIndex = i + 1;

            if (genePool.Count >= 1)
            {
                for (int l = 0; l < 100; l++)
                {
                    AIndex = genePool[Random.Range(0, genePool.Count)];
                    BIndex = genePool[Random.Range(0, genePool.Count)];

                    if (AIndex != BIndex)
                    {
                        break;
                    }
                }
            }

            NNet Child1 = new NNet();
            NNet Child2 = new NNet();

            Child1.Initialise(controller.LAYERS, controller.NEURONS);
            Child2.Initialise(controller.LAYERS, controller.NEURONS);

            Child1.fitness = 0;
            Child2.fitness = 0;


            for (int w = 0; w < Child1.weights.Count; w++)
            {
                if (Random.Range(0.0f, 1.0f) < 0.5f)
                {
                    Child1.weights[w] = population[AIndex].weights[w];
                    Child2.weights[w] = population[BIndex].weights[w];
                }
                else
                {
                    Child2.weights[w] = population[AIndex].weights[w];
                    Child1.weights[w] = population[BIndex].weights[w];
                }
            }


            for (int w = 0; w < Child1.biases.Count; w++)
            {
                if (Random.Range(0.0f, 1.0f) < 0.5f)
                {
                    Child1.biases[w] = population[AIndex].biases[w];
                    Child2.biases[w] = population[BIndex].biases[w];
                }
                else
                {
                    Child2.biases[w] = population[AIndex].biases[w];
                    Child1.biases[w] = population[BIndex].biases[w];
                }
            }

            newPopulation[naturallySelected] = Child1;
            naturallySelected++;

            newPopulation[naturallySelected] = Child2;
            naturallySelected++;
        }
    }
Пример #2
0
 public Genome(int nInput, int nHiddenLayer, int nHiddenLayerNeurons, int nOutput, int genomeID)
 {
     net = new NNet();
     net.CreateNet(nInput, nHiddenLayer, nHiddenLayerNeurons, nOutput);
     this.ID = genomeID;
 }
Пример #3
0
 public Genome(Genome other, int ID)
 {
     this.fitness = other.fitness;
     this.ID      = ID;
     this.net     = other.net;
 }
Пример #4
0
 public void SetPlayer(PlayerController followingPlayer)
 {
     ResetStructure();
     nnet = followingPlayer.brain.nnet;
     CreateStructure();
 }
Пример #5
0
    private void Crossover(NNet[] newPopulation)
    {
        for (int i = 0; i < Hijos; i += 2)
        {
            int AIndex = i;
            int BIndex = i + 1;

            if (genePool.Count >= 1)
            {
                for (int j = 0; j < 100; j++)
                {
                    AIndex = genePool[Random.Range(0, genePool.Count)];
                    BIndex = genePool[Random.Range(0, genePool.Count)];

                    if (AIndex != BIndex)
                    {
                        break;
                    }
                }
            }

            NNet child1 = new NNet();
            NNet child2 = new NNet();

            child1.Initialise(controller.LAYERS, controller.NEURONS);
            child2.Initialise(controller.LAYERS, controller.NEURONS);

            child1.fitness = 0;
            child2.fitness = 0;

            for (int k = 0; k < child1.weights.Count; k++)
            {
                if (Random.Range(0.0f, 1.0f) < 0.5f)
                {
                    child1.weights[k] = population[AIndex].weights[k];
                    child2.weights[k] = population[BIndex].weights[k];
                }
                else
                {
                    child1.weights[k] = population[BIndex].weights[k];
                    child2.weights[k] = population[AIndex].weights[k];
                }
            }

            for (int k = 0; k < child1.biases.Count; k++)
            {
                if (Random.Range(0.0f, 1.0f) < 0.5f)
                {
                    child1.biases[k] = population[AIndex].biases[k];
                    child2.biases[k] = population[BIndex].biases[k];
                }
                else
                {
                    child1.biases[k] = population[BIndex].biases[k];
                    child2.biases[k] = population[AIndex].biases[k];
                }
            }

            newPopulation[naturallySelected] = child1;
            naturallySelected++;
            newPopulation[naturallySelected] = child2;
            naturallySelected++;
        }
    }
Пример #6
0
 public void ResetWithNetwork(NNet net)
 {
     network = net;
     Reset();
 }
Пример #7
0
 private void Awake()
 {
     startPosition = transform.position;
     startRotation = transform.eulerAngles;
     network       = GetComponent <NNet>();
 }
Пример #8
0
 public void setNetwork(NNet net)
 {
     brain = net;
 }