Changeset 7223


Ignore:
Timestamp:
12/21/11 17:01:58 (8 years ago)
Author:
bburlacu
Message:

#1661: Fixed bug in the CalculateHistogram method inside the DataTableView, adjusted the way vertical scaling is performed in the SymbolicExpressionTreeLengthAnalyzer.

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/DataTableView.cs

    r7221 r7223  
    223223      if (Content.VisualProperties.TitleFont != null) chart.Titles[0].Font = Content.VisualProperties.TitleFont;
    224224      if (!Content.VisualProperties.TitleColor.IsEmpty) chart.Titles[0].ForeColor = Content.VisualProperties.TitleColor;
    225       chart.Titles[0].Text = Content.VisualProperties.Title;
    226225
    227226      if (Content.VisualProperties.AxisTitleFont != null) area.AxisX.TitleFont = Content.VisualProperties.AxisTitleFont;
     
    578577      }
    579578
     579      double intervalCenter = intervalWidth / 2;
     580
     581      double min = 0.0;
     582      if (!Double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue) && !Content.VisualProperties.XAxisMinimumAuto)
     583        min = Content.VisualProperties.XAxisMinimumFixedValue;
     584      else min = minValue;
     585
     586      double axisInterval = intervalWidth / row.VisualProperties.ScaleFactor;
     587
    580588      var area = chart.ChartAreas[0];
    581       double current = 0.0;
    582       if (!Double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue) && !Content.VisualProperties.XAxisMinimumAuto)
    583         current = Content.VisualProperties.XAxisMinimumFixedValue;
    584       else current = minValue;
    585 
    586       area.AxisX.Interval = intervalWidth / row.VisualProperties.ScaleFactor;
    587       area.AxisX.IntervalOffset = intervalWidth / row.VisualProperties.ScaleFactor;
    588 
    589       series.SetCustomProperty("PointWidth", intervalWidth.ToString());
    590 
    591       int frequency = 0;
    592       foreach (double v in row.Values.Where(x => !IsInvalidValue(x)).OrderBy(x => x)) {
    593         while (v > current + intervalWidth) {
    594           series.Points.AddXY(current + intervalWidth, frequency);
    595           current += intervalWidth;
    596           frequency = 0;
    597         }
    598         frequency++;
    599       }
    600       series.Points.AddXY(current + intervalWidth, frequency);
     589      area.AxisX.Interval = axisInterval;
     590
     591      series.SetCustomProperty("PointWidth", "1"); // 0.8 is the default value
     592
     593      // get the range or intervals which define the grouping of the frequency values
     594      var doubleRange = DoubleRange(min, maxValue + intervalWidth, intervalWidth).Skip(1).ToList();
     595
     596      // aggregate the row values by unique key and frequency value
     597      var valueFrequencies = (from v in row.Values
     598                              where !IsInvalidValue(v)
     599                              orderby v
     600                              group v by v into g
     601                              select new Tuple<double, double>(g.First(), g.Count())).ToList();
     602
     603      // shift the chart to the left so the bars are placed on the intervals
     604      if (valueFrequencies.First().Item1 < doubleRange.First())
     605        series.Points.Add(new DataPoint(min - intervalWidth, 0));
     606
     607      // add data points
     608      int j = 0;
     609      foreach (var d in doubleRange) {
     610        double sum = 0.0;
     611        // sum the frequency values that fall within the same interval
     612        while (j < valueFrequencies.Count && valueFrequencies[j].Item1 < d) {
     613          sum += valueFrequencies[j].Item2;
     614          ++j;
     615        }
     616        series.Points.Add(new DataPoint(d - intervalCenter, sum) { ToolTip = "X: [" + (d - intervalWidth) + "-" + d + "), Y: " + sum });
     617      }
    601618    }
    602619
    603620    #region Helpers
     621    public static IEnumerable<double> DoubleRange(double min, double max, double step) {
     622      double i;
     623      for (i = min; i <= max; i += step)
     624        yield return i;
     625
     626      if (i != max + step)
     627        yield return i;
     628    }
     629
    604630    protected void RemoveCustomPropertyIfExists(Series series, string property) {
    605631      if (series.IsCustomPropertySet(property)) series.DeleteCustomProperty(property);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs

    r7172 r7223  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using System;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    201202        treeLengthsTable.VisualProperties.YAxisMaximumAuto = false;
    202203        treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    203         int maxFreq = solutions.GroupBy(s => s.Length).Max(g => g.Count());
     204        int maxFreq = (int)Math.Round(solutions.GroupBy(s => s.Length).Max(g => g.Count()) / treeLengthsTableRow.VisualProperties.ScaleFactor);
    204205        if (maxFreq % 5 != 0)
    205206          maxFreq += (5 - maxFreq % 5);
Note: See TracChangeset for help on using the changeset viewer.