Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj	(revision 7499)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj	(revision 7500)
@@ -141,4 +141,10 @@
       <DependentUpon>RegressionEnsembleSolutionModelView.cs</DependentUpon>
     </Compile>
+    <Compile Include="Regression\RegressionSolutionResidualHistogram.cs">
+      <SubType>UserControl</SubType>
+    </Compile>
+    <Compile Include="Regression\RegressionSolutionResidualHistogram.Designer.cs">
+      <DependentUpon>RegressionSolutionResidualHistogram.cs</DependentUpon>
+    </Compile>
     <Compile Include="Solution Views\ClassificationSolutionView.cs">
       <SubType>UserControl</SubType>
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.Designer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.Designer.cs	(revision 7500)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.Designer.cs	(revision 7500)
@@ -0,0 +1,66 @@
+﻿namespace HeuristicLab.Problems.DataAnalysis.Views {
+  partial class RegressionSolutionResidualHistogram {
+    /// <summary> 
+    /// Required designer variable.
+    /// </summary>
+    private System.ComponentModel.IContainer components = null;
+
+    /// <summary> 
+    /// Clean up any resources being used.
+    /// </summary>
+    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+    protected override void Dispose(bool disposing) {
+      if (disposing && (components != null)) {
+        components.Dispose();
+      }
+      base.Dispose(disposing);
+    }
+
+    #region Component Designer generated code
+
+    /// <summary> 
+    /// Required method for Designer support - do not modify 
+    /// the contents of this method with the code editor.
+    /// </summary>
+    private void InitializeComponent() {
+      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+      System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
+      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
+      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
+      this.SuspendLayout();
+      // 
+      // chart
+      // 
+      chartArea1.Name = "ChartArea";
+      this.chart.ChartAreas.Add(chartArea1);
+      this.chart.Dock = System.Windows.Forms.DockStyle.Fill;
+      legend1.Alignment = System.Drawing.StringAlignment.Center;
+      legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
+      legend1.Name = "Default";
+      this.chart.Legends.Add(legend1);
+      this.chart.Location = new System.Drawing.Point(0, 0);
+      this.chart.Name = "chart";
+      this.chart.Size = new System.Drawing.Size(358, 225);
+      this.chart.TabIndex = 0;
+      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
+      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
+      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
+      // 
+      // RegressionSolutionResidualHistogram
+      // 
+      this.AllowDrop = true;
+      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+      this.Controls.Add(this.chart);
+      this.Name = "RegressionSolutionResidualHistogram";
+      this.Size = new System.Drawing.Size(289, 220);
+      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
+      this.ResumeLayout(false);
+
+    }
+
+    #endregion
+
+    private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
+  }
+}
Index: /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs
===================================================================
--- /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs	(revision 7500)
+++ /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs	(revision 7500)
@@ -0,0 +1,229 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Windows.Forms;
+using System.Windows.Forms.DataVisualization.Charting;
+using HeuristicLab.MainForm;
+using HeuristicLab.MainForm.WindowsForms;
+
+namespace HeuristicLab.Problems.DataAnalysis.Views {
+  [View("Residual Histogram")]
+  [Content(typeof(IRegressionSolution))]
+  public partial class RegressionSolutionResidualHistogram : DataAnalysisSolutionEvaluationView {
+
+    #region variables
+    protected const string ALL_SAMPLES = "All samples";
+    protected const string TRAINING_SAMPLES = "Training samples";
+    protected const string TEST_SAMPLES = "Test samples";
+    /// <summary>
+    /// used to reduce code duplication
+    /// </summary>
+    protected static string[] ALL_SERIES = new string[] { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES };
+    /// <summary>
+    /// approximate amount of bins 
+    /// </summary>
+    protected const double bins = 25;
+    /// <summary>
+    ///  keeps for all series a list for every bin with the position of the bin, the relative frequency of the
+    ///  residuals and the beginning and the end of the interval of the bin
+    ///  </summary>
+    protected Dictionary<string, List<List<double>>> relativeFrequencies;
+    #endregion
+
+    public new IRegressionSolution Content {
+      get { return (IRegressionSolution)base.Content; }
+      set { base.Content = value; }
+    }
+
+    public RegressionSolutionResidualHistogram()
+      : base() {
+      InitializeComponent();
+      relativeFrequencies = new Dictionary<string, List<List<double>>>();
+      foreach (string series in ALL_SERIES) {
+        chart.Series.Add(series);
+        chart.Series[series].LegendText = series;
+        chart.Series[series].ChartType = SeriesChartType.Column;
+        chart.Series[series]["PointWidth"] = "0.9";
+        chart.Series[series].BorderWidth = 1;
+        chart.Series[series].BorderDashStyle = ChartDashStyle.Solid;
+        chart.Series[series].BorderColor = Color.Black;
+        chart.Series[series].ToolTip = series + " Y = #VALY from #CUSTOMPROPERTY(from) to #CUSTOMPROPERTY(to)";
+        relativeFrequencies[series] = new List<List<double>>();
+      }
+      //configure axis 
+      chart.CustomizeAllChartAreas();
+      chart.ChartAreas[0].AxisX.Title = "Residuals";
+      chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
+      chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
+      chart.ChartAreas[0].CursorX.Interval = 1;
+      chart.ChartAreas[0].CursorY.Interval = 1;
+      chart.ChartAreas[0].AxisY.Title = "Relative Frequency";
+      chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
+      chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
+      chart.ChartAreas[0].AxisY.IsStartedFromZero = true;
+    }
+
+    private void RedrawChart() {
+      foreach (string series in ALL_SERIES) {
+        chart.Series[series].Points.Clear();
+        relativeFrequencies[series].Clear();
+      }
+      if (Content != null) {
+        Dictionary<string, List<double>> residuals = CalculateResiduals();
+        double max = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max()));
+        double intervalWidth = (max * 2.0) / bins;
+        max = HumanRoundMax(max);
+        intervalWidth = HumanRoundMax(intervalWidth);
+
+        foreach (string series in ALL_SERIES) {
+          CalculateFrequencies(residuals[series], series, max, intervalWidth);
+          if (!series.Equals(ALL_SAMPLES))
+            ShowValues(chart.Series[series], relativeFrequencies[series]);
+        }
+
+        ChartArea chartArea = chart.ChartAreas[0];
+        chartArea.AxisX.Minimum = -max - intervalWidth;
+        chartArea.AxisX.Maximum = max + intervalWidth;
+        chartArea.AxisY.Maximum = relativeFrequencies[ALL_SAMPLES].Select(x => x.ElementAt(1)).Max() + 0.02;
+        chartArea.AxisY.Interval = 0.1;
+        chartArea.AxisX.Interval = intervalWidth;
+        int curBins = (int)Math.Round(max / intervalWidth);
+        //shifts the x axis label so that zero is in the middle
+        if (curBins % 2 == 0)
+          chartArea.AxisX.IntervalOffset = intervalWidth;
+        else
+          chartArea.AxisX.IntervalOffset = intervalWidth / 2;
+      }
+    }
+
+    private Dictionary<string, List<double>> CalculateResiduals() {
+      Dictionary<string, List<double>> residuals = new Dictionary<string, List<double>>();
+
+      foreach (string series in ALL_SERIES) {
+        residuals[series] = new List<double>();
+      }
+      IRegressionProblemData problemdata = Content.ProblemData;
+      List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
+      List<double> estimatedValues = Content.EstimatedValues.ToList();
+
+      for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) {
+        double residual = estimatedValues[i] - targetValues[i];
+        residuals[ALL_SAMPLES].Add(residual);
+        if (i >= problemdata.TrainingPartition.Start && i < problemdata.TrainingPartition.End)
+          residuals[TRAINING_SAMPLES].Add(residual);
+        if (i >= problemdata.TestPartition.Start && i < problemdata.TestPartition.End)
+          residuals[TEST_SAMPLES].Add(residual);
+      }
+      return residuals;
+    }
+
+    private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) {
+      //Series residualSeries = chart.Series[series];
+      double intervalCenter = intervalWidth / 2.0;
+      double sampleCount = residualValues.Count();
+      double current = -max;
+
+      for (int i = 0; i <= bins; i++) {
+        IEnumerable<double> help = residualValues.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));
+        relativeFrequencies[series].Add(new List<double>() { current, help.Count() / sampleCount, current - intervalCenter, current + intervalCenter });
+        current += intervalWidth;
+      }
+      //ShowValues(residualSeries, relativeFrequencies[series]);
+    }
+
+    private double HumanRoundMax(double max) {
+      double base10;
+      if (max > 0) base10 = Math.Pow(10.0, Math.Floor(Math.Log10(max)));
+      else base10 = Math.Pow(10.0, Math.Ceiling(Math.Log10(-max)));
+      double rounding = (max > 0) ? base10 : -base10;
+      while (rounding < max) rounding += base10;
+      return rounding;
+    }
+
+    #region events
+    protected override void RegisterContentEvents() {
+      base.RegisterContentEvents();
+      Content.ModelChanged += new EventHandler(Content_ModelChanged);
+      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
+    }
+    protected override void DeregisterContentEvents() {
+      base.DeregisterContentEvents();
+      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
+      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
+    }
+
+    protected override void OnContentChanged() {
+      base.OnContentChanged();
+      RedrawChart();
+    }
+    private void Content_ProblemDataChanged(object sender, EventArgs e) {
+      RedrawChart();
+    }
+    private void Content_ModelChanged(object sender, EventArgs e) {
+      RedrawChart();
+    }
+    private void chart_MouseDown(object sender, MouseEventArgs e) {
+      HitTestResult result = chart.HitTest(e.X, e.Y);
+      if (result.ChartElementType == ChartElementType.LegendItem) {
+        ToggleSeriesData(result.Series);
+      }
+    }
+    private void chart_MouseMove(object sender, MouseEventArgs e) {
+      HitTestResult result = chart.HitTest(e.X, e.Y);
+      if (result.ChartElementType == ChartElementType.LegendItem)
+        Cursor = Cursors.Hand;
+      else
+        Cursor = Cursors.Default;
+    }
+    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
+      if (chart.Series.Count != 3) return;
+      e.LegendItems[0].Cells[1].ForeColor = chart.Series[ALL_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black;
+      e.LegendItems[1].Cells[1].ForeColor = chart.Series[TRAINING_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black;
+      e.LegendItems[2].Cells[1].ForeColor = chart.Series[TEST_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black;
+    }
+    #endregion
+
+    private void ToggleSeriesData(Series series) {
+      if (series.Points.Count > 0) {  //checks if series is shown
+        if (chart.Series.Any(s => s != series && s.Points.Count > 0)) {
+          series.Points.Clear();
+        }
+      } else if (Content != null) {
+        ShowValues(series, relativeFrequencies[series.Name]);
+        chart.Legends[series.Legend].ForeColor = Color.Black;
+        chart.Refresh();
+      }
+    }
+    private void ShowValues(Series series, List<List<double>> relativeSeriesFrequencies) {
+      DataPointCollection seriesPoints = series.Points;
+
+      foreach (var valueList in relativeSeriesFrequencies) {
+        seriesPoints.AddXY(valueList[0], valueList[1]);
+        seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString();
+        seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString();
+      }
+    }
+  }
+}
