Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views-3.3.csproj
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views-3.3.csproj	(revision 9329)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views-3.3.csproj	(revision 9330)
@@ -119,4 +119,10 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="SampleSizeChecker.cs">
+      <SubType>UserControl</SubType>
+    </Compile>
+    <Compile Include="SampleSizeChecker.designer.cs">
+      <DependentUpon>SampleSizeChecker.cs</DependentUpon>
+    </Compile>
     <Compile Include="SampleSizeDetermination.cs" />
     <Compile Include="StatisticalTestingView.cs">
Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/KruskalWallis.cs
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/KruskalWallis.cs	(revision 9329)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/KruskalWallis.cs	(revision 9330)
@@ -24,6 +24,9 @@
 
 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
-  // Kruskal Wallis test based on R's kruskal.test() 
   public class KruskalWallis {
+    /// <summary>
+    /// Performs the Kruskal-Wallis test and returns the p-Value. 
+    /// (source based on R's kruskal.test())
+    /// </summary>
     public static double Test(double[][] data) {
       double[] g;
@@ -78,5 +81,5 @@
     }
 
-    public static double[] FlattenArray(double[][] x, out double[] indizes) {
+    private static double[] FlattenArray(double[][] x, out double[] indizes) {
       int compLenght = 0;
       for (int i = 0; i < x.Length; i++) {
@@ -100,5 +103,5 @@
     }
 
-    public static double[][] CountDuplicates(double[] x) {
+    private static double[][] CountDuplicates(double[] x) {
       List<double> number = new List<double>();
       List<double> cnt = new List<double>();
@@ -129,5 +132,5 @@
     }
 
-    public static int[] Rank(double[] x) {
+    private static int[] Rank(double[] x) {
       double[] keys = new double[x.Length];
       int[] items = new int[x.Length];
Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeChecker.cs
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeChecker.cs	(revision 9330)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeChecker.cs	(revision 9330)
@@ -0,0 +1,178 @@
+﻿#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.Linq;
+using System.Windows.Forms;
+using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views;
+using HeuristicLab.Core.Views;
+using HeuristicLab.Data;
+using HeuristicLab.MainForm;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Analysis.AlgorithmBehavior.Views {
+  [View("Sample Size Checker View")]
+  [Content(typeof(RunCollection), false)]
+  public sealed partial class SampleSizeChecker : ItemView {
+
+    private double[] data;
+
+    public SampleSizeChecker() {
+      InitializeComponent();
+
+      double prec = 0.01;
+      double conf = 0.95;
+      precisionTextBox.Text = prec.ToString();
+      confIntervalTextBox.Text = conf.ToString();
+    }
+
+    public new RunCollection Content {
+      get { return (RunCollection)base.Content; }
+      set { base.Content = value; }
+    }
+
+    public override bool ReadOnly {
+      get { return true; }
+      set { /*not needed because results are always readonly */}
+    }
+
+    protected override void OnContentChanged() {
+      base.OnContentChanged();
+      resultComboBox.Items.Clear();
+
+      if (Content != null) {
+        UpdateResultComboBox();
+      }
+    }
+
+    #region events
+    protected override void RegisterContentEvents() {
+      base.RegisterContentEvents();
+      Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
+      Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
+      Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
+
+      RegisterRunEvents(Content);
+    }
+
+    private void RegisterRunEvents(IEnumerable<IRun> runs) {
+      foreach (IRun run in runs)
+        run.Changed += new EventHandler(run_Changed);
+    }
+
+    protected override void DeregisterContentEvents() {
+      base.DeregisterContentEvents();
+      Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
+      Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
+      Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
+
+      DeregisterRunEvents(Content);
+    }
+
+    private void DeregisterRunEvents(IEnumerable<IRun> runs) {
+      foreach (IRun run in runs)
+        run.Changed -= new EventHandler(run_Changed);
+    }
+
+    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
+      DeregisterRunEvents(e.OldItems);
+      RegisterRunEvents(e.Items);
+      //RebuildInfluenceDataTable();
+    }
+
+    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
+      DeregisterRunEvents(e.Items);
+      //RebuildInfluenceDataTable();
+    }
+
+    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
+      RegisterRunEvents(e.Items);
+      //RebuildInfluenceDataTable();
+    }
+
+    private void run_Changed(object sender, EventArgs e) {
+      if (InvokeRequired)
+        this.Invoke(new EventHandler(run_Changed), sender, e);
+      else {
+        IRun run = (IRun)sender;
+        UpdateRun(run);
+      }
+    }
+    #endregion
+
+    private void UpdateRun(IRun run) {
+      //TODO: hacky di hack... this is baaaadddd
+      RebuildDataTable();
+    }
+
+    private void UpdateResultComboBox() {
+      resultComboBox.Items.Clear();
+      var results = (from run in Content
+                     where run.Visible
+                     from result in run.Results
+                     where result.Value is IntValue || result.Value is DoubleValue
+                     select result.Key).Distinct().ToArray();
+
+      resultComboBox.Items.AddRange(results);
+      if (resultComboBox.Items.Count > 0) resultComboBox.SelectedItem = resultComboBox.Items[0];
+    }
+
+    private void RebuildDataTable() {
+      string resultName = (string)resultComboBox.SelectedItem;
+
+      var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
+      var vals = runs.Select(x => (double)((dynamic)x.Results[resultName]).Value);
+      data = vals.ToArray();
+
+      DoubleMatrix dt = new DoubleMatrix(runs.Count(), 1);
+      dt.ColumnNames = new string[] { resultName };
+
+      int i = 0;
+      foreach (double val in vals) {
+        dt[i++, 0] = val;
+      }
+
+      stringConvertibleMatrixView.Content = dt;
+    }
+
+    private void estimateSampleSizeButton_Click(object sender, EventArgs e) {
+      double precision = double.Parse(precisionTextBox.Text);
+      double confInterval = double.Parse(confIntervalTextBox.Text);
+
+      int nrSamplesReq = SampleSizeDetermination.DetermineSampleSizeByEstimatingMean(data, precision, confInterval);
+      int curNrSamples = data.Count();
+      int diff = curNrSamples - nrSamplesReq;
+
+      IntMatrix m = new IntMatrix(1, 3);
+      m[0, 0] = curNrSamples;
+      m[0, 1] = nrSamplesReq;
+      m[0, 2] = diff;
+      m.ColumnNames = new string[] { "Nr. of current samples", "Minimum nr. of required samples", "Difference" };
+
+      MainFormManager.MainForm.ShowContent(m);
+    }
+
+    private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) {
+      RebuildDataTable();
+    }
+  }
+}
Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeChecker.designer.cs
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeChecker.designer.cs	(revision 9330)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeChecker.designer.cs	(revision 9330)
@@ -0,0 +1,167 @@
+﻿#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
+
+namespace HeuristicLab.Analysis.AlgorithmBehavior.Views {
+  partial class SampleSizeChecker {
+    /// <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 Windows Form 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() {
+      this.stringConvertibleMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
+      this.label1 = new System.Windows.Forms.Label();
+      this.resultComboBox = new System.Windows.Forms.ComboBox();
+      this.estimateSampleSizeButton = new System.Windows.Forms.Button();
+      this.precisionTextBox = new System.Windows.Forms.TextBox();
+      this.confIntervalTextBox = new System.Windows.Forms.TextBox();
+      this.label2 = new System.Windows.Forms.Label();
+      this.label3 = new System.Windows.Forms.Label();
+      this.SuspendLayout();
+      // 
+      // stringConvertibleMatrixView
+      // 
+      this.stringConvertibleMatrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+      this.stringConvertibleMatrixView.Caption = "StringConvertibleMatrix View";
+      this.stringConvertibleMatrixView.Content = null;
+      this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 30);
+      this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView";
+      this.stringConvertibleMatrixView.ReadOnly = false;
+      this.stringConvertibleMatrixView.ShowRowsAndColumnsTextBox = false;
+      this.stringConvertibleMatrixView.ShowStatisticalInformation = true;
+      this.stringConvertibleMatrixView.Size = new System.Drawing.Size(746, 329);
+      this.stringConvertibleMatrixView.TabIndex = 0;
+      // 
+      // label1
+      // 
+      this.label1.AutoSize = true;
+      this.label1.Location = new System.Drawing.Point(5, 6);
+      this.label1.Name = "label1";
+      this.label1.Size = new System.Drawing.Size(40, 13);
+      this.label1.TabIndex = 6;
+      this.label1.Text = "Result:";
+      // 
+      // resultComboBox
+      // 
+      this.resultComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+      this.resultComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+      this.resultComboBox.FormattingEnabled = true;
+      this.resultComboBox.Location = new System.Drawing.Point(71, 3);
+      this.resultComboBox.Name = "resultComboBox";
+      this.resultComboBox.Size = new System.Drawing.Size(678, 21);
+      this.resultComboBox.TabIndex = 5;
+      this.resultComboBox.SelectedValueChanged += new System.EventHandler(this.resultComboBox_SelectedValueChanged);
+      // 
+      // estimateSampleSizeButton
+      // 
+      this.estimateSampleSizeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+      this.estimateSampleSizeButton.Location = new System.Drawing.Point(630, 365);
+      this.estimateSampleSizeButton.Name = "estimateSampleSizeButton";
+      this.estimateSampleSizeButton.Size = new System.Drawing.Size(119, 23);
+      this.estimateSampleSizeButton.TabIndex = 9;
+      this.estimateSampleSizeButton.Text = "Estimate sample size";
+      this.estimateSampleSizeButton.UseVisualStyleBackColor = true;
+      this.estimateSampleSizeButton.Click += new System.EventHandler(this.estimateSampleSizeButton_Click);
+      // 
+      // precisionTextBox
+      // 
+      this.precisionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+      this.precisionTextBox.Location = new System.Drawing.Point(64, 367);
+      this.precisionTextBox.Name = "precisionTextBox";
+      this.precisionTextBox.Size = new System.Drawing.Size(106, 20);
+      this.precisionTextBox.TabIndex = 10;
+      // 
+      // confIntervalTextBox
+      // 
+      this.confIntervalTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+      this.confIntervalTextBox.Location = new System.Drawing.Point(331, 368);
+      this.confIntervalTextBox.Name = "confIntervalTextBox";
+      this.confIntervalTextBox.Size = new System.Drawing.Size(100, 20);
+      this.confIntervalTextBox.TabIndex = 11;
+      // 
+      // label2
+      // 
+      this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+      this.label2.AutoSize = true;
+      this.label2.Location = new System.Drawing.Point(5, 370);
+      this.label2.Name = "label2";
+      this.label2.Size = new System.Drawing.Size(53, 13);
+      this.label2.TabIndex = 12;
+      this.label2.Text = "Precision:";
+      // 
+      // label3
+      // 
+      this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+      this.label3.AutoSize = true;
+      this.label3.Location = new System.Drawing.Point(223, 370);
+      this.label3.Name = "label3";
+      this.label3.Size = new System.Drawing.Size(102, 13);
+      this.label3.TabIndex = 13;
+      this.label3.Text = "Confidence Interval:";
+      // 
+      // SampleSizeChecker
+      // 
+      this.Controls.Add(this.label3);
+      this.Controls.Add(this.label2);
+      this.Controls.Add(this.confIntervalTextBox);
+      this.Controls.Add(this.precisionTextBox);
+      this.Controls.Add(this.estimateSampleSizeButton);
+      this.Controls.Add(this.label1);
+      this.Controls.Add(this.resultComboBox);
+      this.Controls.Add(this.stringConvertibleMatrixView);
+      this.Name = "SampleSizeChecker";
+      this.Size = new System.Drawing.Size(752, 391);
+      this.ResumeLayout(false);
+      this.PerformLayout();
+
+    }
+    #endregion
+
+    private HeuristicLab.Data.Views.StringConvertibleMatrixView stringConvertibleMatrixView;
+    private System.Windows.Forms.Label label1;
+    private System.Windows.Forms.ComboBox resultComboBox;
+    private System.Windows.Forms.Button estimateSampleSizeButton;
+    private System.Windows.Forms.TextBox precisionTextBox;
+    private System.Windows.Forms.TextBox confIntervalTextBox;
+    private System.Windows.Forms.Label label2;
+    private System.Windows.Forms.Label label3;
+  }
+}
Index: /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeDetermination.cs
===================================================================
--- /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeDetermination.cs	(revision 9329)
+++ /branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers.Views/3.3/SampleSizeDetermination.cs	(revision 9330)
@@ -38,8 +38,12 @@
       double result = 0;
 
-      double var = samples.Variance();
-      double n = alglib.normaldistribution((conf + 1) / 2);
+      double var = samples.StandardDeviation();
+      double n = alglib.invnormaldistribution((conf + 1) / 2);
       result = Math.Pow(n, 2) * Math.Pow(var, 2) / Math.Pow(e, 2);
-      return (int)Math.Ceiling(result);
+      result = Math.Ceiling(result);
+      if (result > int.MaxValue)
+        return int.MaxValue;
+      else
+        return (int)result;
     }
 
