Exemplo n.º 1
0
    public void AverageTrialScoresPerGen(int curGeneration)
    {
        // Average Values over the entire Generation
        Debug.Log ("AverageTrialScoresPerGen(); avgRawScore: " + generationDataList[curGeneration].avgAgentScoreRaw.ToString());
        generationDataList[curGeneration].avgAgentScoreRaw = generationDataList[curGeneration].totalAgentScoresRaw / (float)generationDataList[curGeneration].agentDataArray.Length;
        generationDataList[curGeneration].avgAgentScoreWeighted = generationDataList[curGeneration].totalAgentScoresWeighted / (float)generationDataList[curGeneration].agentDataArray.Length;

        // Calculate Generation average genome:
        int numAgents = generationDataList[curGeneration].agentDataArray.Length;
        Genome avgGenome = new Genome();
        avgGenome.genomeBiases = new float[playerRef.masterPopulation.masterAgentArray[0].genome.genomeBiases.Length];
        avgGenome.genomeWeights = new float[playerRef.masterPopulation.masterAgentArray[0].genome.genomeWeights.Length];
        avgGenome.ZeroGenome(); // set all values to 0f;
        for(int i = 0; i < numAgents; i++) {
            // iterate through Bias Arrays and add each agent's bias value to the avg
            for(int b = 0; b < avgGenome.genomeBiases.Length; b++) {
                avgGenome.genomeBiases[b] += playerRef.masterPopulation.masterAgentArray[i].genome.genomeBiases[b] / (float)numAgents;
            }
            // iterate through Weight Arrays and add each agent's weight value to the avg
            for(int w = 0; w < avgGenome.genomeWeights.Length; w++) {
                avgGenome.genomeWeights[w] += playerRef.masterPopulation.masterAgentArray[i].genome.genomeWeights[w] / (float)numAgents;
            }
        }
        // Save the genome values to this generation Data:
        generationDataList[curGeneration].genAvgGenome.genomeBiases = avgGenome.genomeBiases;
        generationDataList[curGeneration].genAvgGenome.genomeWeights = avgGenome.genomeWeights;
    }