Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Core/Histogram.cs @ 553

Last change on this file since 553 was 553, checked in by gkronber, 16 years ago

added a results-tab in the cedma console which contains a data chart that can be used to display histograms and scatter plots for any result value.

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Xml;
28using HeuristicLab.CEDMA.DB.Interfaces;
29using HeuristicLab.Operators;
30
31namespace HeuristicLab.CEDMA.Core {
32  public class Histogram {
33    private int buckets;
34    public int Buckets {
35      get { return buckets; }
36      set {
37        buckets = value;
38        ResetBucketBounds();
39      }
40    }
41
42    private double[] limit;
43
44    private List<double> values;
45
46    public Histogram(int buckets) {
47      this.buckets = buckets;
48      values = new List<double>();
49    }
50
51    public double LowerValue(int bucketIndex) {
52      return limit[bucketIndex];
53    }
54
55    public double UpperValue(int bucketIndex) {
56      return limit[bucketIndex+1];
57    }
58
59    public int Frequency(int bucketIndex) {
60      return values.Count(x => x >= LowerValue(bucketIndex) && x < UpperValue(bucketIndex));
61    }
62
63    public void AddValues(IEnumerable<double> xs) {
64      values.AddRange(xs.Where(x=>
65        !double.IsInfinity(x) && !double.IsNaN(x) && double.MaxValue!=x && double.MinValue !=x));
66      ResetBucketBounds();
67    }
68
69    private void ResetBucketBounds() {
70      limit = new double[buckets+1];
71      values.Sort();
72      double min = values[10];
73      double max = values[values.Count-10];
74
75      double step = (max - min) / buckets;
76      double cur = min;
77      for(int i = 0; i < buckets+1; i++) {
78        limit[i] = cur;
79        cur += step;
80      }
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.