Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/12/08 11:24:03 (16 years ago)
Author:
gkronber
Message:

added 'jitter' sliders to add random noise to data points (useful in scatter plots with integer values). #200 (Simple indexer for results and matching search-frontend for solution-quality)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/ResultListView.cs

    r553 r554  
    1414    private ResultList results;
    1515    private const string FREQUENCY = "<Frequency>";
     16    private double xJitterFactor = 0.0;
     17    private double yJitterFactor = 0.0;
     18    private double maxXJitterPercent = .1;
     19    private double maxYJitterPercent = .1;
    1620
    1721    public ResultListView(ResultList results) {
     
    2529
    2630    private void yAxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     31      yJitterFactor = 0.0;
     32      yTrackBar.Value = 0;
    2733      UpdateChart();
    2834    }
    2935
    3036    private void xAxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     37      xJitterFactor = 0.0;
     38      xTrackBar.Value = 0;
    3139      UpdateChart();
    3240    }
    3341
    3442    private void UpdateChart() {
     43      if(xAxisComboBox.SelectedItem == null || yAxisComboBox.SelectedItem == null) return;
     44      if(yAxisComboBox.SelectedItem.Equals(FREQUENCY)) {
     45        CreateHistogramChart();
     46      } else {
     47        CreateScatterplot();
     48      }
     49    }
     50
     51    private void CreateScatterplot() {
    3552      double minX = double.PositiveInfinity;
    3653      double minY = double.PositiveInfinity;
    3754      double maxX = double.NegativeInfinity;
    3855      double maxY = double.NegativeInfinity;
    39       if(xAxisComboBox.SelectedItem == null || yAxisComboBox.SelectedItem == null) return;
    40       if(yAxisComboBox.SelectedItem.Equals(FREQUENCY)) {
    41         Color curCol = Color.Blue;
    42         Pen p = new Pen(curCol);
    43         SolidBrush b = new SolidBrush(curCol);
    44         // frequency
    45         dataChart.Chart = new HeuristicLab.Charting.Data.Datachart(0, 0, 100, 100);
    46         dataChart.Chart.UpdateEnabled = false;
    47         dataChart.Chart.Group.Add(new Axis(dataChart.Chart, 0, 0, AxisType.Both));
    48         Histogram h = results.GetHistogram((string)xAxisComboBox.SelectedItem);
    49         for(int i = 0; i < h.Buckets; i++) {
    50           double lower = h.LowerValue(i);
    51           double upper = h.UpperValue(i);
    52           int freq = h.Frequency(i);
    53           if(lower < minX) minX = lower;
    54           if(upper > maxX) maxX = upper;
    55           if(freq > maxY) maxY = freq;
    56           dataChart.Chart.AddDataRow(HeuristicLab.Charting.Data.DataRowType.Bars, p, b);
    57           dataChart.Chart.AddDataPoint(0, lower, 0);
    58           dataChart.Chart.AddDataPoint(0, upper, freq);
     56
     57      xTrackBar.Enabled = true;
     58      yTrackBar.Enabled = true;
     59      Random random = new Random();
     60      Color curCol = Color.FromArgb(30, Color.Blue);
     61      Pen p = new Pen(curCol);
     62      SolidBrush b = new SolidBrush(curCol);
     63      IList<double> xs = results.GetValues((string)xAxisComboBox.SelectedItem);
     64      IList<double> ys = results.GetValues((string)yAxisComboBox.SelectedItem);
     65      dataChart.Chart = new HeuristicLab.Charting.Data.Datachart(0, 0, 100, 100);
     66      dataChart.Chart.UpdateEnabled = false;
     67      dataChart.Chart.Group.Add(new Axis(dataChart.Chart, 0, 0, AxisType.Both));
     68      dataChart.Chart.AddDataRow(HeuristicLab.Charting.Data.DataRowType.Points, p, b);
     69      for(int i = 0; i < xs.Count; i++) {
     70        double x = xs[i] + (random.NextDouble() * 2.0 - 1.0) * xJitterFactor;
     71        double y = ys[i] + (random.NextDouble() * 2.0 - 1.0) * yJitterFactor;
     72        if(double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN;
     73        if(double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN;
     74        if(!double.IsNaN(x) && !double.IsNaN(y)) {
     75          dataChart.Chart.AddDataPoint(0, x, y);
     76          if(x > maxX) maxX = x;
     77          if(y > maxY) maxY = y;
     78          if(x < minX) minX = x;
     79          if(y < minY) minY = y;
    5980        }
    60         minY = 0;
     81      }
     82      dataChart.Chart.UpdateEnabled = true;
     83      if(minX<maxX && minY<maxY) dataChart.Chart.ZoomIn(minX, minY, maxX, maxY);
     84    }
    6185
    62         dataChart.Chart.UpdateEnabled = true;
    63       } else {
    64         Color curCol = Color.FromArgb(30, Color.Blue);
    65         Pen p = new Pen(curCol);
    66         SolidBrush b = new SolidBrush(curCol);
    67         IList<double> xs = results.GetValues((string)xAxisComboBox.SelectedItem);
    68         IList<double> ys = results.GetValues((string)yAxisComboBox.SelectedItem);
    69         dataChart.Chart = new HeuristicLab.Charting.Data.Datachart(0, 0, 100, 100);
    70         dataChart.Chart.UpdateEnabled = false;
    71         dataChart.Chart.Group.Add(new Axis(dataChart.Chart, 0, 0, AxisType.Both));
    72         dataChart.Chart.AddDataRow(HeuristicLab.Charting.Data.DataRowType.Points, p, b);
    73         for(int i = 0; i < xs.Count; i++) {
    74           double x = xs[i];
    75           double y = ys[i];
    76           if(double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN;
    77           if(double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN;
    78           if(!double.IsNaN(x) && !double.IsNaN(y)) {
    79             dataChart.Chart.AddDataPoint(0, x, y);
    80             if(x > maxX) maxX = x;
    81             if(y > maxY) maxY = y;
    82             if(x < minX) minX = x;
    83             if(y < minY) minY = y;
    84           }
    85         }
    86         dataChart.Chart.UpdateEnabled = true;
     86    private void CreateHistogramChart() {
     87      double minX = double.PositiveInfinity;
     88      double minY = double.PositiveInfinity;
     89      double maxX = double.NegativeInfinity;
     90      double maxY = double.NegativeInfinity;
     91
     92      xTrackBar.Enabled = false;
     93      yTrackBar.Enabled = false;
     94      Color curCol = Color.Blue;
     95      Pen p = new Pen(curCol);
     96      SolidBrush b = new SolidBrush(curCol);
     97      // frequency
     98      dataChart.Chart = new HeuristicLab.Charting.Data.Datachart(0, 0, 100, 100);
     99      dataChart.Chart.UpdateEnabled = false;
     100      dataChart.Chart.Group.Add(new Axis(dataChart.Chart, 0, 0, AxisType.Both));
     101      Histogram h = results.GetHistogram((string)xAxisComboBox.SelectedItem);
     102      for(int i = 0; i < h.Buckets; i++) {
     103        double lower = h.LowerValue(i);
     104        double upper = h.UpperValue(i);
     105        int freq = h.Frequency(i);
     106        if(lower < minX) minX = lower;
     107        if(upper > maxX) maxX = upper;
     108        if(freq > maxY) maxY = freq;
     109        dataChart.Chart.AddDataRow(HeuristicLab.Charting.Data.DataRowType.Bars, p, b);
     110        dataChart.Chart.AddDataPoint(0, lower, 0);
     111        dataChart.Chart.AddDataPoint(0, upper, freq);
    87112      }
     113      minY = 0;
     114      dataChart.Chart.UpdateEnabled = true;
     115      if(minX < maxX && minY < maxY) dataChart.Chart.ZoomIn(minX, minY, maxX, maxY);
     116    }
    88117
    89       dataChart.Chart.ZoomIn(minX, minY, maxX, maxY);
     118    private void yTrackBar_ValueChanged(object sender, EventArgs e) {
     119      if(dataChart.Chart != null) {
     120        yJitterFactor = yTrackBar.Value / 100.0 * maxYJitterPercent * dataChart.Chart.Size.Height;
     121      }
     122      UpdateChart();
     123    }
     124
     125    private void xTrackBar_ValueChanged(object sender, EventArgs e) {
     126      if(dataChart.Chart != null) {
     127        xJitterFactor = xTrackBar.Value / 100.0 * maxXJitterPercent * dataChart.Chart.Size.Width;
     128      }
     129      UpdateChart();
    90130    }
    91131  }
Note: See TracChangeset for help on using the changeset viewer.