Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7503


Ignore:
Timestamp:
02/21/12 16:28:21 (12 years ago)
Author:
sforsten
Message:

#1708:

  • residual bars center around zero at the X-Axis
  • some small changes in the appearance
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs

    r7500 r7503  
    9393      if (Content != null) {
    9494        Dictionary<string, List<double>> residuals = CalculateResiduals();
    95         double max = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max()));
    96         double intervalWidth = (max * 2.0) / bins;
    97         max = HumanRoundMax(max);
     95        double realMax = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max()));
     96        double roundedMax = HumanRoundMax(realMax);
     97        double intervalWidth = (roundedMax * 2.0) / bins;
    9898        intervalWidth = HumanRoundMax(intervalWidth);
     99        // sets roundedMax to a value, so that zero will be in the middle of the x axis
     100        double help = realMax / intervalWidth;
     101        help = help % 1 < 0.5 ? (int)help : (int)help + 1;
     102        roundedMax = help * intervalWidth;
    99103
    100104        foreach (string series in ALL_SERIES) {
    101           CalculateFrequencies(residuals[series], series, max, intervalWidth);
     105          CalculateFrequencies(residuals[series], series, roundedMax, intervalWidth);
    102106          if (!series.Equals(ALL_SAMPLES))
    103107            ShowValues(chart.Series[series], relativeFrequencies[series]);
     
    105109
    106110        ChartArea chartArea = chart.ChartAreas[0];
    107         chartArea.AxisX.Minimum = -max - intervalWidth;
    108         chartArea.AxisX.Maximum = max + intervalWidth;
    109         chartArea.AxisY.Maximum = relativeFrequencies[ALL_SAMPLES].Select(x => x.ElementAt(1)).Max() + 0.02;
    110         chartArea.AxisY.Interval = 0.1;
     111        chartArea.AxisX.Minimum = -roundedMax - intervalWidth;
     112        chartArea.AxisX.Maximum = roundedMax + intervalWidth;
     113        // get the highest frequency of a residual of any series
     114        chartArea.AxisY.Maximum = (from series in relativeFrequencies.Values
     115                                   select (from residual in series
     116                                           select residual.ElementAt(1)).Max()).Max();
     117        if (chartArea.AxisY.Maximum < 0.1) {
     118          chartArea.AxisY.Interval = 0.01;
     119          chartArea.AxisY.Maximum = Math.Ceiling(chartArea.AxisY.Maximum * 100) / 100;
     120        } else {
     121          chartArea.AxisY.Interval = 0.1;
     122          chartArea.AxisY.Maximum = Math.Ceiling(chartArea.AxisY.Maximum * 10) / 10;
     123        }
    111124        chartArea.AxisX.Interval = intervalWidth;
    112         int curBins = (int)Math.Round(max / intervalWidth);
     125        int curBins = (int)Math.Round((roundedMax * 2) / intervalWidth);
    113126        //shifts the x axis label so that zero is in the middle
    114127        if (curBins % 2 == 0)
     
    141154
    142155    private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) {
    143       //Series residualSeries = chart.Series[series];
    144156      double intervalCenter = intervalWidth / 2.0;
    145157      double sampleCount = residualValues.Count();
     
    151163        current += intervalWidth;
    152164      }
    153       //ShowValues(residualSeries, relativeFrequencies[series]);
    154165    }
    155166
Note: See TracChangeset for help on using the changeset viewer.