Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/08/12 14:04:17 (12 years ago)
Author:
mkommend
Message:

#1081: Intermediate commit of trunk updates - interpreter changes must be redone.

Location:
branches/HeuristicLab.TimeSeries
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries

    • Property svn:ignore
      •  

        old new  
        2020bin
        2121protoc.exe
         22_ReSharper.HeuristicLab.TimeSeries-3.3
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Viewsmergedeligible
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Viewsmergedeligible
      /trunk/sources/HeuristicLab.Problems.DataAnalysis.Viewsmergedeligible
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Views6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Views4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Views5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Views5815-6180
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views6284-6795
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Views5138-5162
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Views5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Views7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Views6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Views6828
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Views5370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Views6829-6865
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Views5594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Views5959-6341
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs

    r7615 r8430  
    3939    protected const string TEST_SAMPLES = "Test samples";
    4040    /// <summary>
    41     /// used to reduce code duplication
    42     /// </summary>
    43     protected static string[] ALL_SERIES = new string[] { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES };
    44     /// <summary>
    4541    /// approximate amount of bins
    4642    /// </summary>
    4743    protected const double bins = 25;
    48     /// <summary>
    49     ///  keeps for all series a list for every bin with the position of the bin, the relative frequency of the
    50     ///  residuals and the beginning and the end of the interval of the bin
    51     ///  </summary>
    52     protected Dictionary<string, List<List<double>>> relativeFrequencies;
    5344    #endregion
    5445
     
    6152      : base() {
    6253      InitializeComponent();
    63       relativeFrequencies = new Dictionary<string, List<List<double>>>();
    64       foreach (string series in ALL_SERIES) {
     54      foreach (string series in new List<String>() { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES }) {
    6555        chart.Series.Add(series);
    6656        chart.Series[series].LegendText = series;
     
    7161        chart.Series[series].BorderColor = Color.Black;
    7262        chart.Series[series].ToolTip = series + " Y = #VALY from #CUSTOMPROPERTY(from) to #CUSTOMPROPERTY(to)";
    73         relativeFrequencies[series] = new List<List<double>>();
    7463      }
    7564      //configure axis
     
    8776
    8877    private void RedrawChart() {
    89       foreach (string series in ALL_SERIES) {
    90         chart.Series[series].Points.Clear();
    91         relativeFrequencies[series].Clear();
     78      foreach (Series series in chart.Series) {
     79        series.Points.Clear();
    9280      }
    9381      if (Content != null) {
    94         Dictionary<string, List<double>> residuals = CalculateResiduals();
    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;
    98         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;
    103 
    104         foreach (string series in ALL_SERIES) {
    105           CalculateFrequencies(residuals[series], series, roundedMax, intervalWidth);
    106           if (!series.Equals(ALL_SAMPLES))
    107             ShowValues(chart.Series[series], relativeFrequencies[series]);
     82        List<double> residuals = CalculateResiduals(Content);
     83
     84        double max = 0.0;
     85        foreach (Series series in chart.Series) {
     86          CalculateFrequencies(residuals, series);
     87          double seriesMax = series.Points.Select(p => p.YValues.First()).Max();
     88          max = max < seriesMax ? seriesMax : max;
    10889        }
     90
     91        // ALL_SAMPLES has to be calculated to know its highest frequency, but it is not shown in the beginning
     92        chart.Series.First(s => s.Name.Equals(ALL_SAMPLES)).Points.Clear();
     93
     94        double roundedMax, intervalWidth;
     95        CalculateResidualParameters(residuals, out roundedMax, out intervalWidth);
    10996
    11097        ChartArea chartArea = chart.ChartAreas[0];
     
    11299        chartArea.AxisX.Maximum = roundedMax + intervalWidth;
    113100        // 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();
     101        chartArea.AxisY.Maximum = max;
    117102        if (chartArea.AxisY.Maximum < 0.1) {
    118103          chartArea.AxisY.Interval = 0.01;
     
    132117    }
    133118
    134     private Dictionary<string, List<double>> CalculateResiduals() {
    135       Dictionary<string, List<double>> residuals = new Dictionary<string, List<double>>();
    136 
    137       foreach (string series in ALL_SERIES) {
    138         residuals[series] = new List<double>();
    139       }
     119    private List<double> CalculateResiduals(IRegressionSolution solution) {
     120      List<double> residuals = new List<double>();
     121
     122      IRegressionProblemData problemdata = solution.ProblemData;
     123      List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
     124      List<double> estimatedValues = solution.EstimatedValues.ToList();
     125
     126      for (int i = 0; i < solution.ProblemData.Dataset.Rows; i++) {
     127        double residual = estimatedValues[i] - targetValues[i];
     128        residuals.Add(residual);
     129      }
     130      return residuals;
     131    }
     132
     133    private void CalculateFrequencies(List<double> residualValues, Series series) {
     134      double roundedMax, intervalWidth;
     135      CalculateResidualParameters(residualValues, out roundedMax, out intervalWidth);
     136
     137      IEnumerable<double> relevantResiduals = residualValues;
    140138      IRegressionProblemData problemdata = Content.ProblemData;
    141       List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
    142       List<double> estimatedValues = Content.EstimatedValues.ToList();
    143 
    144       for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) {
    145         double residual = estimatedValues[i] - targetValues[i];
    146         residuals[ALL_SAMPLES].Add(residual);
    147         if (i >= problemdata.TrainingPartition.Start && i < problemdata.TrainingPartition.End)
    148           residuals[TRAINING_SAMPLES].Add(residual);
    149         if (i >= problemdata.TestPartition.Start && i < problemdata.TestPartition.End)
    150           residuals[TEST_SAMPLES].Add(residual);
    151       }
    152       return residuals;
    153     }
    154 
    155     private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) {
     139      if (series.Name.Equals(TRAINING_SAMPLES)) {
     140        relevantResiduals = residualValues.Skip(problemdata.TrainingPartition.Start).Take(problemdata.TrainingPartition.Size);
     141      } else if (series.Name.Equals(TEST_SAMPLES)) {
     142        relevantResiduals = residualValues.Skip(problemdata.TestPartition.Start).Take(problemdata.TestPartition.Size);
     143      }
     144
    156145      double intervalCenter = intervalWidth / 2.0;
    157       double sampleCount = residualValues.Count();
    158       double current = -max;
     146      double sampleCount = relevantResiduals.Count();
     147      double current = -roundedMax;
     148      DataPointCollection seriesPoints = series.Points;
    159149
    160150      for (int i = 0; i <= bins; i++) {
    161         IEnumerable<double> help = residualValues.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));
    162         relativeFrequencies[series].Add(new List<double>() { current, help.Count() / sampleCount, current - intervalCenter, current + intervalCenter });
     151        IEnumerable<double> help = relevantResiduals.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));
     152        seriesPoints.AddXY(current, help.Count() / sampleCount);
     153        seriesPoints[seriesPoints.Count - 1]["from"] = (current - intervalCenter).ToString();
     154        seriesPoints[seriesPoints.Count - 1]["to"] = (current + intervalCenter).ToString();
    163155        current += intervalWidth;
    164156      }
    165157    }
    166158
    167     private double HumanRoundMax(double max) {
     159    private void ToggleSeriesData(Series series) {
     160      if (series.Points.Count > 0) {  //checks if series is shown
     161        if (chart.Series.Any(s => s != series && s.Points.Count > 0)) {
     162          series.Points.Clear();
     163        }
     164      } else if (Content != null) {
     165        List<double> residuals = CalculateResiduals(Content);
     166        CalculateFrequencies(residuals, series);
     167        chart.Legends[series.Legend].ForeColor = Color.Black;
     168        chart.Refresh();
     169      }
     170    }
     171
     172    private static void CalculateResidualParameters(List<double> residuals, out double roundedMax, out double intervalWidth) {
     173      double realMax = Math.Max(Math.Abs(residuals.Min()), Math.Abs(residuals.Max()));
     174      roundedMax = HumanRoundMax(realMax);
     175      intervalWidth = (roundedMax * 2.0) / bins;
     176      intervalWidth = HumanRoundMax(intervalWidth);
     177      // sets roundedMax to a value, so that zero will be in the middle of the x axis
     178      double help = realMax / intervalWidth;
     179      help = help % 1 < 0.5 ? (int)help : (int)help + 1;
     180      roundedMax = help * intervalWidth;
     181    }
     182
     183    private static double HumanRoundMax(double max) {
    168184      double base10;
    169185      if (max > 0) base10 = Math.Pow(10.0, Math.Floor(Math.Log10(max)));
     
    216232    }
    217233    #endregion
    218 
    219     private void ToggleSeriesData(Series series) {
    220       if (series.Points.Count > 0) {  //checks if series is shown
    221         if (chart.Series.Any(s => s != series && s.Points.Count > 0)) {
    222           series.Points.Clear();
    223         }
    224       } else if (Content != null) {
    225         ShowValues(series, relativeFrequencies[series.Name]);
    226         chart.Legends[series.Legend].ForeColor = Color.Black;
    227         chart.Refresh();
    228       }
    229     }
    230     private void ShowValues(Series series, List<List<double>> relativeSeriesFrequencies) {
    231       DataPointCollection seriesPoints = series.Points;
    232 
    233       foreach (var valueList in relativeSeriesFrequencies) {
    234         seriesPoints.AddXY(valueList[0], valueList[1]);
    235         seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString();
    236         seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString();
    237       }
    238     }
    239234  }
    240235}
Note: See TracChangeset for help on using the changeset viewer.