Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4652 for trunk/sources


Ignore:
Timestamp:
10/28/10 17:38:37 (14 years ago)
Author:
mkommend
Message:

Added statistical information to the RunCollectionBoxPlotView and corrected minor bugs in the 'RunCollectionBubbleChartView' and the 'RunCollectionBoxPlotView' (ticket #1135).

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/EnumerableStatisticExtensions.cs

    r4477 r4652  
    8787      return ((m_n > 1) ? m_newS / (m_n - 1) : 0.0);
    8888    }
     89
     90    /// <summary>
     91    /// Calculates the pth percentile of the values.
     92    /// </summary
     93    public static double Percentile(this IEnumerable<double> values, double p) {
     94      if (values.Count() == 0) throw new InvalidOperationException("Enumeration contains no elements.");
     95      if (values.Count() == 1) return values.ElementAt(0);
     96
     97      double[] sortedValues = values.ToArray();
     98      Array.Sort(sortedValues);
     99
     100      int n = sortedValues.Length;
     101      if (p.IsAlmost(0.0)) return sortedValues[0];
     102      if (p.IsAlmost(1.0)) return sortedValues[n - 1];
     103
     104      double t = p * (n - 1);
     105      int index = (int)Math.Floor(t);
     106      double percentage = t - index;
     107      return sortedValues[index] * (1 - percentage) + sortedValues[index + 1] * percentage;
     108    }
    89109  }
    90110}
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r4600 r4652  
    2323using System.Collections.Generic;
    2424using System.ComponentModel;
     25using System.Drawing;
    2526using System.Linq;
    2627using System.Text;
     
    5152    }
    5253
     54    private bool showRowsAndColumnsTextBox;
     55    public bool ShowRowsAndColumnsTextBox {
     56      get { return showRowsAndColumnsTextBox; }
     57      set {
     58        if (value != showRowsAndColumnsTextBox) {
     59          showRowsAndColumnsTextBox = value;
     60          UpdateVisibilityOfTextBoxes();
     61        }
     62      }
     63    }
     64
    5365    public StringConvertibleMatrixView() {
    5466      InitializeComponent();
     67      showRowsAndColumnsTextBox = true;
    5568      errorProvider.SetIconAlignment(rowsTextBox, ErrorIconAlignment.MiddleLeft);
    5669      errorProvider.SetIconPadding(rowsTextBox, 2);
     
    99112
    100113    private void UpdateData() {
    101 
    102114      rowsTextBox.Text = Content.Rows.ToString();
    103115      rowsTextBox.Enabled = true;
     
    472484      new ColumnsVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>()).ShowDialog();
    473485    }
     486
     487    private void UpdateVisibilityOfTextBoxes() {
     488      rowsTextBox.Visible = columnsTextBox.Visible = showRowsAndColumnsTextBox;
     489      rowsLabel.Visible = columnsLabel.Visible = showRowsAndColumnsTextBox;
     490
     491      int headerSize = columnsTextBox.Location.Y + columnsTextBox.Size.Height +
     492        columnsTextBox.Margin.Bottom + dataGridView.Margin.Top;
     493
     494      int offset = showRowsAndColumnsTextBox ? headerSize : 0;
     495      dataGridView.Location = new Point(0, offset);
     496      dataGridView.Size = new Size(Size.Width, Size.Height - offset);
     497    }
    474498  }
    475499}
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBoxPlotView.Designer.cs

    r4094 r4652  
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      this.components = new System.ComponentModel.Container();
    4748      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    4849      System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
     
    5152      this.yAxisLabel = new System.Windows.Forms.Label();
    5253      this.yAxisComboBox = new System.Windows.Forms.ComboBox();
    53       this.chart = new System.Windows.Forms.DataVisualization.Charting.Chart();
     54      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    5455      this.noRunsLabel = new System.Windows.Forms.Label();
     56      this.splitContainer = new System.Windows.Forms.SplitContainer();
     57      this.statisticsGroupBox = new System.Windows.Forms.GroupBox();
     58      this.statisticsMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
     59      this.tooltip = new System.Windows.Forms.ToolTip(this.components);
    5560      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
     61      this.splitContainer.Panel1.SuspendLayout();
     62      this.splitContainer.Panel2.SuspendLayout();
     63      this.splitContainer.SuspendLayout();
     64      this.statisticsGroupBox.SuspendLayout();
    5665      this.SuspendLayout();
    5766      //
     
    6069      this.xAxisLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    6170      this.xAxisLabel.AutoSize = true;
    62       this.xAxisLabel.Location = new System.Drawing.Point(306, 294);
     71      this.xAxisLabel.Location = new System.Drawing.Point(298, 256);
    6372      this.xAxisLabel.Name = "xAxisLabel";
    6473      this.xAxisLabel.Size = new System.Drawing.Size(15, 13);
     
    7281      this.xAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    7382      this.xAxisComboBox.FormattingEnabled = true;
    74       this.xAxisComboBox.Location = new System.Drawing.Point(327, 290);
     83      this.xAxisComboBox.Location = new System.Drawing.Point(319, 253);
    7584      this.xAxisComboBox.Name = "xAxisComboBox";
    7685      this.xAxisComboBox.Size = new System.Drawing.Size(221, 21);
     
    8190      //
    8291      this.yAxisLabel.AutoSize = true;
    83       this.yAxisLabel.Location = new System.Drawing.Point(3, 7);
     92      this.yAxisLabel.Location = new System.Drawing.Point(3, 6);
    8493      this.yAxisLabel.Name = "yAxisLabel";
    8594      this.yAxisLabel.Size = new System.Drawing.Size(15, 13);
     
    92101      this.yAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    93102      this.yAxisComboBox.FormattingEnabled = true;
    94       this.yAxisComboBox.Location = new System.Drawing.Point(24, 4);
     103      this.yAxisComboBox.Location = new System.Drawing.Point(24, 3);
    95104      this.yAxisComboBox.Name = "yAxisComboBox";
    96105      this.yAxisComboBox.Size = new System.Drawing.Size(221, 21);
     
    105114      chartArea1.Name = "ChartArea1";
    106115      this.chart.ChartAreas.Add(chartArea1);
    107       this.chart.Location = new System.Drawing.Point(3, 28);
     116      this.chart.Location = new System.Drawing.Point(6, 30);
    108117      this.chart.Name = "chart";
    109118      series1.ChartArea = "ChartArea1";
     
    112121      series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
    113122      series1.Name = "DataSeries";
    114       series1.YValuesPerPoint = 1;
     123      series1.YValuesPerPoint = 6;
    115124      this.chart.Series.Add(series1);
    116 
    117       this.chart.Size = new System.Drawing.Size(546, 258);
     125      this.chart.Size = new System.Drawing.Size(534, 217);
    118126      this.chart.TabIndex = 17;
    119127      this.chart.Text = "chart";
    120128      this.chart.AxisViewChanged += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ViewEventArgs>(this.chart_AxisViewChanged);
     129      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    121130      //
    122131      // noRunsLabel
     
    124133      this.noRunsLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
    125134      this.noRunsLabel.AutoSize = true;
    126       this.noRunsLabel.Location = new System.Drawing.Point(200, 134);
     135      this.noRunsLabel.Location = new System.Drawing.Point(212, 122);
    127136      this.noRunsLabel.Name = "noRunsLabel";
    128137      this.noRunsLabel.Size = new System.Drawing.Size(138, 13);
     
    130139      this.noRunsLabel.Text = "No runs could be displayed.";
    131140      //
     141      // splitContainer
     142      //
     143      this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
     144      this.splitContainer.Location = new System.Drawing.Point(0, 0);
     145      this.splitContainer.Name = "splitContainer";
     146      this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
     147      //
     148      // splitContainer.Panel1
     149      //
     150      this.splitContainer.Panel1.Controls.Add(this.xAxisLabel);
     151      this.splitContainer.Panel1.Controls.Add(this.noRunsLabel);
     152      this.splitContainer.Panel1.Controls.Add(this.yAxisLabel);
     153      this.splitContainer.Panel1.Controls.Add(this.xAxisComboBox);
     154      this.splitContainer.Panel1.Controls.Add(this.yAxisComboBox);
     155      this.splitContainer.Panel1.Controls.Add(this.chart);
     156      //
     157      // splitContainer.Panel2
     158      //
     159      this.splitContainer.Panel2.Controls.Add(this.statisticsGroupBox);
     160      this.splitContainer.Size = new System.Drawing.Size(543, 416);
     161      this.splitContainer.SplitterDistance = 277;
     162      this.splitContainer.TabIndex = 23;
     163      //
     164      // statisticsGroupBox
     165      //
     166      this.statisticsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     167                  | System.Windows.Forms.AnchorStyles.Left)
     168                  | System.Windows.Forms.AnchorStyles.Right)));
     169      this.statisticsGroupBox.Controls.Add(this.statisticsMatrixView);
     170      this.statisticsGroupBox.Location = new System.Drawing.Point(3, 3);
     171      this.statisticsGroupBox.Name = "statisticsGroupBox";
     172      this.statisticsGroupBox.Size = new System.Drawing.Size(534, 129);
     173      this.statisticsGroupBox.TabIndex = 1;
     174      this.statisticsGroupBox.TabStop = false;
     175      this.statisticsGroupBox.Text = "Statistics";
     176      //
     177      // statisticsMatrixView
     178      //
     179      this.statisticsMatrixView.Caption = "StringConvertibleMatrix View";
     180      this.statisticsMatrixView.Content = null;
     181      this.statisticsMatrixView.Dock = System.Windows.Forms.DockStyle.Fill;
     182      this.statisticsMatrixView.Location = new System.Drawing.Point(3, 16);
     183      this.statisticsMatrixView.Name = "statisticsMatrixView";
     184      this.statisticsMatrixView.ReadOnly = true;
     185      this.statisticsMatrixView.ShowRowsAndColumnsTextBox = false;
     186      this.statisticsMatrixView.Size = new System.Drawing.Size(528, 110);
     187      this.statisticsMatrixView.TabIndex = 0;
     188      //
    132189      // RunCollectionBoxPlotView
    133190      //
     
    136193      this.BackColor = System.Drawing.SystemColors.Window;
    137194      this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    138       this.Controls.Add(this.noRunsLabel);
    139       this.Controls.Add(this.chart);
    140       this.Controls.Add(this.xAxisLabel);
    141       this.Controls.Add(this.xAxisComboBox);
    142       this.Controls.Add(this.yAxisLabel);
    143       this.Controls.Add(this.yAxisComboBox);
     195      this.Controls.Add(this.splitContainer);
    144196      this.Name = "RunCollectionBoxPlotView";
    145       this.Size = new System.Drawing.Size(552, 316);
     197      this.Size = new System.Drawing.Size(543, 416);
    146198      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
     199      this.splitContainer.Panel1.ResumeLayout(false);
     200      this.splitContainer.Panel1.PerformLayout();
     201      this.splitContainer.Panel2.ResumeLayout(false);
     202      this.splitContainer.ResumeLayout(false);
     203      this.statisticsGroupBox.ResumeLayout(false);
    147204      this.ResumeLayout(false);
    148       this.PerformLayout();
    149205
    150206    }
     
    156212    private System.Windows.Forms.Label yAxisLabel;
    157213    private System.Windows.Forms.ComboBox yAxisComboBox;
    158     private System.Windows.Forms.DataVisualization.Charting.Chart chart;
     214    private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
    159215    private System.Windows.Forms.Label noRunsLabel;
     216    private System.Windows.Forms.SplitContainer splitContainer;
     217    private Data.Views.StringConvertibleMatrixView statisticsMatrixView;
     218    private System.Windows.Forms.GroupBox statisticsGroupBox;
     219    private System.Windows.Forms.ToolTip tooltip;
    160220  }
    161221}
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBoxPlotView.cs

    r4211 r4652  
    2525using System.Windows.Forms;
    2626using System.Windows.Forms.DataVisualization.Charting;
     27using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Data;
     
    5051      this.chart.Series.Clear();
    5152      this.chart.ChartAreas.Add(BoxPlotChartAreaName);
     53      this.chart.CustomizeAllChartAreas();
    5254    }
    5355
     
    168170          this.chart.Series.Add(s);
    169171
     172        UpdateStatistics();
    170173        if (seriesCache.Count > 0) {
    171174          Series boxPlotSeries = CreateBoxPlotSeries();
     
    176179      }
    177180      UpdateNoRunsVisibleLabel();
     181    }
     182
     183    private void UpdateStatistics() {
     184      DoubleMatrix matrix = new DoubleMatrix(6, seriesCache.Count);
     185      matrix.SortableView = false;
     186      List<string> columnNames = new List<string>();
     187      foreach (Series series in seriesCache.Values) {
     188        DataPoint datapoint = series.Points.FirstOrDefault();
     189        if (datapoint != null) {
     190          IRun run = (IRun)datapoint.Tag;
     191          string selectedAxis = (string)xAxisComboBox.SelectedItem;
     192          IItem value = null;
     193
     194          if (Enum.IsDefined(typeof(AxisDimension), selectedAxis)) {
     195            AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), selectedAxis);
     196            switch (axisDimension) {
     197              case AxisDimension.Color: value = new StringValue(run.Color.ToString());
     198                break;
     199            }
     200          } else value = Content.GetValue(run, selectedAxis);
     201          string columnName = string.Empty;
     202          if (value is DoubleValue || value is IntValue)
     203            columnName = selectedAxis + ": ";
     204          columnName += value.ToString();
     205          columnNames.Add(columnName);
     206        }
     207      }
     208      matrix.ColumnNames = columnNames;
     209      matrix.RowNames = new string[] { "Mean", "Median", "Standard deviation", "Variance", "25th percentile", "75th percentile" };
     210
     211      for (int i = 0; i < seriesCache.Count; i++) {
     212        Series series = seriesCache.ElementAt(i).Value;
     213        double[] seriesValues = series.Points.Select(p => p.YValues[0]).OrderBy(d => d).ToArray();
     214        matrix[0, i] = seriesValues.Average();
     215        matrix[1, i] = seriesValues.Median();
     216        matrix[2, i] = seriesValues.StandardDeviation();
     217        matrix[3, i] = seriesValues.Variance();
     218        matrix[4, i] = seriesValues.Percentile(0.25);
     219        matrix[5, i] = seriesValues.Percentile(0.75);
     220      }
     221      statisticsMatrixView.Content = matrix;
    178222    }
    179223
     
    214258        Series series = seriesCache[xValue.Value];
    215259        DataPoint point = new DataPoint(xValue.Value, yValue.Value);
     260        point.Tag = run;
    216261        series.Points.Add(point);
    217262      }
     
    293338      SetCustomAxisLabels(xAxis, xAxisComboBox.SelectedIndex - axisDimensionCount);
    294339      SetCustomAxisLabels(yAxis, yAxisComboBox.SelectedIndex - axisDimensionCount);
     340      if (xAxisComboBox.SelectedItem != null)
     341        xAxis.Title = xAxisComboBox.SelectedItem.ToString();
     342      if (yAxisComboBox.SelectedItem != null)
     343        yAxis.Title = yAxisComboBox.SelectedItem.ToString();
    295344    }
    296345
     
    340389      }
    341390    }
     391
     392    private void chart_MouseMove(object sender, MouseEventArgs e) {
     393      string newTooltipText = string.Empty;
     394      string oldTooltipText;
     395      HitTestResult h = this.chart.HitTest(e.X, e.Y);
     396      if (h.ChartElementType == ChartElementType.AxisLabels) {
     397        newTooltipText = ((CustomLabel)h.Object).ToolTip;
     398      }
     399
     400      oldTooltipText = this.tooltip.GetToolTip(chart);
     401      if (newTooltipText != oldTooltipText)
     402        this.tooltip.SetToolTip(chart, newTooltipText);
     403    }
    342404    #endregion
     405
    343406  }
    344407}
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r4636 r4652  
    131131        AddDataPoint(run);
    132132      UpdateCursorInterval();
     133      chart.ChartAreas[0].RecalculateAxesScale();
    133134
    134135
Note: See TracChangeset for help on using the changeset viewer.