social_learning.DiversityAnalyzer.getSensorReadings C# (CSharp) Method

getSensorReadings() public method

public getSensorReadings ( ) : double[][]
return double[][]
        public double[][] getSensorReadings()
        {
            IAgent a = _world.Agents.First();
            double[][] readings = new double[numlocations][];
            for (int i = 0; i < readings.Length; i++)
                readings[i] = new double[3];
            int j = 0;
            foreach (int[] location in locations)
            {
                a.X = location[0];
                a.Y = location[1];
                a.Orientation = orientations[j];
                a.Velocity = velocities[j];
                readings[j] = _world.calculateForagingAgentSensors(a);
                j++;
            }
            return readings;
        }

Usage Example

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;
            }
        }