Esempio n. 1
0
    private void Awake()
    {
        SP = transform.position;
        SR = transform.eulerAngles;
        EnvironmentControler = GetComponent <NNetwork>();


        EnvironmentControler.Initialise(LAYER, NEURON);
    }
Esempio n. 2
0
 public void ResetCar()
 {
     EnvironmentControler.Initialise(LAYER, NEURON);
     transform.position    = SP;
     transform.eulerAngles = SR;
     time               = 0f;
     totalDistance      = 0f;
     avgSpeed           = 0f;
     lastPosition       = SP;
     overallPerformance = 0f;
 }
Esempio n. 3
0
    private void Crossover(NNetwork[] 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;
                    }
                }
            }

            NNetwork Child1 = new NNetwork();
            NNetwork Child2 = new NNetwork();

            Child1.Initialise(controller.LAYER, controller.NEURON);
            Child2.Initialise(controller.LAYER, controller.NEURON);

            Child1.performance = 0;
            Child2.performance = 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++;
        }
    }