Exemplo n.º 1
0
        void writeDiversityStats(bool before)
        {
            if (_generations > 0)
            {
                _learningEnabled = false;
                DiversityAnalyzer analyser    = new DiversityAnalyzer(_world);
                double[][]        readings    = analyser.getSensorReadings();
                string            diverseFile = before ? DiversityFile.Replace(".csv", "_before.csv") : DiversityFile.Replace(".csv", "_after.csv");

                using (TextWriter writer = new StreamWriter(diverseFile, true))
                {
                    List <double> orientationVariances = new List <double>();
                    List <double> velocityVariances    = new List <double>();
                    foreach (double[] reading in readings)
                    {
                        var variances = analyser.getResponseVariance(reading);
                        orientationVariances.Add(variances[0]);
                        velocityVariances.Add(variances[1]);
                    }
                    writer.WriteLine("{0},{1},{2}", _generations, orientationVariances.Average(), velocityVariances.Average());
                }
                _world.Reset();
                _learningEnabled = true;
            }
        }