private void Start() { Results.Clear(); DateTime startTime = DateTime.Now; Minimum = int.MaxValue; Maximum = int.MinValue; Random random = new Random(); for (int i = 0; i < 100000; i++) { int value = random.Next(); int time = (int)(DateTime.Now.Subtract(startTime).TotalMilliseconds); ResultViewModel result = new ResultViewModel() { Value = value, Time = time }; Results.Add(result); } Minimum = Results.Min(r => r.Value); Maximum = Results.Max(r => r.Value); Average = (int)Results.Average(r => r.Value); Count = Results.Count; Time = Results.Last().Time; }
private async Task Load() { Results.Clear(); StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = (StorageFile)await folder.TryGetItemAsync("Results.bin"); if (file == null) { return; } IBuffer buffer = await FileIO.ReadBufferAsync(file); byte[] bytes = buffer.ToArray(); for (int i = 0; i < bytes.Length; i += sizeof(int) * 2) { int time = BitConverter.ToInt32(bytes, i); int value = BitConverter.ToInt32(bytes, i + sizeof(int)); ResultViewModel result = new ResultViewModel() { Time = time, Value = value }; Results.Add(result); } Minimum = Results.Min(r => r.Value); Maximum = Results.Max(r => r.Value); Average = (int)Results.Average(r => r.Value); Count = Results.Count; Time = Results.Last().Time; }
public void Calculate() { if (Results.Any()) { base.Calculate(Results); SymbolsSum = Results.Sum(x => x.Value.SymbolsCnt); AvgTime = TimeSpan.FromSeconds(Results.Average(x => x.Value.Time.TotalSeconds)); AvgRealPlace = Results.Average(x => x.Value.RealPlace); var notNullCalcPlaceResults = Results.Where(x => x.Value.CalculatedPlace.HasValue); if (notNullCalcPlaceResults.Any()) { AvgCalculatedPlace = notNullCalcPlaceResults.Average(x => x.Value.CalculatedPlace.Value); } } for (int i = 1; i <= RacesCreated; i++) { if (!base.Results.ContainsKey(i)) { continue; } if (base.Results[i].Speed == MaxSpeed) { base.Results[i].IsBestSpeed = true; } else if (base.Results[i].Speed == MinSpeed) { base.Results[i].IsWorstSpeed = true; } if (base.Results[i].ErRate == MinErRate) { base.Results[i].IsBestErRate = true; } else if (base.Results[i].ErRate == MaxErRate) { base.Results[i].IsWorstErRate = true; } if (base.Results[i].ErCnt == MinErCnt) { base.Results[i].IsBestErCnt = true; } else if (base.Results[i].ErCnt == MaxErCnt) { base.Results[i].IsWorstErCnt = true; } base.Results[i].RelativeSpeed = base.Results[i].Speed / AvgSpeed; } IsCalculated = true; }
/// <summary> /// Compute the statistics. Call this after all /// optimization runs have executed. /// </summary> public void Compute() { FitnessQuartiles = new Quartiles(); IterationsQuartiles = new Quartiles(); if (Results.Count > 0) { // Fitness quartiles. double[] fitnessArray = Results.Select(o => o.Fitness).ToArray(); FitnessQuartiles.ComputeUnsortedInplace(fitnessArray); // Iterations quartiles. double[] iterationsArray = Results.Select(o => o.Iterations).ToArray(); IterationsQuartiles.ComputeUnsortedInplace(iterationsArray); // Fitness mean and stddev. FitnessMean = Results.Average(o => o.Fitness); FitnessStdDev = Results.StdDev(o => o.Fitness); // Iterations mean and stddev. IterationsMean = Results.Average(o => o.Iterations); IterationsStdDev = Results.StdDev(o => o.Iterations); } else { // Fitness mean and stddev. FitnessMean = null; FitnessStdDev = null; // Iterations mean and stddev. IterationsMean = null; IterationsStdDev = null; } // Best results. BestResults = Results.Where(o => o.Fitness == FitnessMin); }