Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8863


Ignore:
Timestamp:
10/30/12 16:22:04 (12 years ago)
Author:
sforsten
Message:

#1776:

  • merged r8810:8862 from trunk into branch
  • fixed exception in ClassificationEnsembleSolutionAccuracyToCoveredSamples, if no estimated values are in a partition, so nothing can be shown
Location:
branches/ClassificationEnsembleVoting
Files:
4 deleted
24 edited
5 copied

Legend:

Unmodified
Added
Removed
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis

  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views

  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionAccuracyToCoveredSamples.cs

    r8862 r8863  
    118118        }
    119119
    120         int row;
    121         for (int i = 0; i < maxPoints; i++) {
    122           double confidenceValue = (1.0 / (maxPoints - 1)) * i;
    123           int notCovered = 0;
    124 
    125           for (int j = 0; j < indizes.Length; j++) {
    126             row = indizes[j];
    127             if (confidences[j] >= confidenceValue) {
    128               accuracyCalc.Add(target[row], estimatedClassValues[j]);
    129             } else {
    130               notCovered++;
     120        if (!estimatedClassValues.All(x => Double.IsNaN(x))) {
     121          int row;
     122          for (int i = 0; i < maxPoints; i++) {
     123            double confidenceValue = (1.0 / (maxPoints - 1)) * i;
     124            int notCovered = 0;
     125
     126            for (int j = 0; j < indizes.Length; j++) {
     127              row = indizes[j];
     128              if (confidences[j] >= confidenceValue) {
     129                accuracyCalc.Add(target[row], estimatedClassValues[j]);
     130              } else {
     131                notCovered++;
     132              }
    131133            }
     134
     135            accuracy[i + 1] = accuracyCalc.Accuracy;
     136            if (indizes.Length > 0) {
     137              covered[i] = 1.0 - (double)notCovered / (double)indizes.Length;
     138            }
     139            accuracyCalc.Reset();
    132140          }
    133141
    134           accuracy[i + 1] = accuracyCalc.Accuracy;
    135           if (indizes.Length > 0) {
    136             covered[i] = 1.0 - (double)notCovered / (double)indizes.Length;
    137           }
    138           accuracyCalc.Reset();
     142          accuracy[0] = accuracy[1];
     143          covered[maxPoints] = 0.0;
     144
     145          accuracy = accuracy.Reverse().ToArray();
     146          covered = covered.Reverse().ToArray();
     147
     148          Series area = this.chart.Series.Add(AREA);
     149          area.ChartType = SeriesChartType.Area;
     150          area.Color = Color.LightBlue;
     151          IEnumerable<IEnumerable<double>> areaPoints = CalculateAreaPoints(covered, accuracy);
     152          area.Points.DataBindXY(areaPoints.ElementAt(0), areaPoints.ElementAt(1));
     153
     154          Series series = this.chart.Series.Add(ACCURACYCOVERED);
     155          series.Color = Color.Red;
     156          series.ChartType = SeriesChartType.FastPoint;
     157          series.MarkerStyle = MarkerStyle.Diamond;
     158          series.MarkerSize = 5;
     159          series.Points.DataBindXY(covered, accuracy);
     160
     161          double auc = CalculateAreaUnderCurve(series);
     162          area.LegendToolTip = "AUC: " + auc;
     163
     164          AUCLabel.Text = "AUC: " + auc;
     165        } else {
     166          AUCLabel.Text = "No values in this partition!";
    139167        }
    140 
    141         accuracy[0] = accuracy[1];
    142         covered[maxPoints] = 0.0;
    143 
    144         accuracy = accuracy.Reverse().ToArray();
    145         covered = covered.Reverse().ToArray();
    146 
    147         Series area = this.chart.Series.Add(AREA);
    148         area.ChartType = SeriesChartType.Area;
    149         area.Color = Color.LightBlue;
    150         IEnumerable<IEnumerable<double>> areaPoints = CalculateAreaPoints(covered, accuracy);
    151         area.Points.DataBindXY(areaPoints.ElementAt(0), areaPoints.ElementAt(1));
    152 
    153         Series series = this.chart.Series.Add(ACCURACYCOVERED);
    154         series.Color = Color.Red;
    155         series.ChartType = SeriesChartType.FastPoint;
    156         series.MarkerStyle = MarkerStyle.Diamond;
    157         series.MarkerSize = 5;
    158         series.Points.DataBindXY(covered, accuracy);
    159 
    160         double auc = CalculateAreaUnderCurve(series);
    161         area.LegendToolTip = "AUC: " + auc;
    162 
    163         AUCLabel.Text = "AUC: " + auc;
    164168      }
    165169    }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs

    r8814 r8863  
    133133        int row = indizes[i];
    134134        values[i, 0] = row.ToString();
    135         values[i, 1] = target[i].ToString();
     135        values[i, 1] = target[row].ToString();
    136136        //display only indices and target values if no models are present
    137137        if (solutionsCount > 0) {
    138138          values[i, 2] = estimatedClassValues[i].ToString();
    139           correctClassified = target[i].IsAlmost(estimatedClassValues[i]);
     139          correctClassified = target[row].IsAlmost(estimatedClassValues[i]);
    140140          values[i, 3] = correctClassified.ToString();
    141141          curConfidence = confidences[i];
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationFeatureCorrelationView.cs

    r8811 r8863  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationTimeframeFeatureCorrelationView.cs

    r8811 r8863  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationRocCurvesView.cs

    r8811 r8863  
    114114        maxThreshold += thresholdIncrement;
    115115
    116         List<double> classValues = Content.Model.ClassValues.ToList();
     116        List<double> classValues = Content.ProblemData.ClassValues.ToList();
    117117
    118118        foreach (double classValue in classValues) {
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.Designer.cs

    r8508 r8863  
    1 namespace HeuristicLab.Problems.DataAnalysis.Views {
     1using System.Windows.Forms.DataVisualization.Charting;
     2namespace HeuristicLab.Problems.DataAnalysis.Views {
    23  partial class DiscriminantFunctionClassificationSolutionThresholdView {
    34    /// <summary>
     
    5354      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    5455      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
     56      this.chart.PostPaint += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs>(chart_PostPaint);
    5557      //
    5658      // JitterTrackBar
     
    9294
    9395    }
    94 
    9596    #endregion
    9697
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r8811 r8863  
    4040    private const string TestLabelText = "Test Samples";
    4141
     42    private const double ClassNameLeftOffset = 10.0;
     43    private const double ClassNameBottomOffset = 5.0;
     44
    4245    public new IDiscriminantFunctionClassificationSolution Content {
    4346      get { return (IDiscriminantFunctionClassificationSolution)base.Content; }
     
    4750    private Dictionary<double, Series> classValueSeriesMapping;
    4851    private Random random;
    49     private bool updateInProgress;
     52    private bool updateInProgress, updateThresholds;
    5053
    5154    public DiscriminantFunctionClassificationSolutionThresholdView()
     
    126129            FillSeriesWithDataPoints(series);
    127130          }
    128           AddThresholds();
     131          updateThresholds = true;
    129132        }
    130133        chart.ChartAreas[0].RecalculateAxesScale();
     
    166169    }
    167170
     171    private void chart_PostPaint(object sender, ChartPaintEventArgs e) {
     172      if (updateThresholds) {
     173        AddThresholds();
     174        updateThresholds = false;
     175      }
     176    }
     177
    168178    private void AddThresholds() {
    169179      chart.Annotations.Clear();
    170180      int classIndex = 1;
     181      SizeF textSizeInPixel;
     182      IClassificationProblemData problemData = Content.ProblemData;
     183      var classValues = Content.Model.ClassValues.ToArray();
     184      Graphics g = chart.CreateGraphics();
     185      Axis y = chart.ChartAreas[0].AxisY;
     186      Axis x = chart.ChartAreas[0].AxisX;
     187      string name;
    171188      foreach (double threshold in Content.Model.Thresholds) {
    172189        if (!double.IsInfinity(threshold)) {
     
    176193          annotation.LineWidth = 2;
    177194          annotation.LineColor = Color.Red;
    178 
    179195          annotation.IsInfinitive = true;
    180196          annotation.ClipToChartArea = chart.ChartAreas[0].Name;
    181197          annotation.Tag = classIndex;  //save classIndex as Tag to avoid moving the threshold accross class bounderies
    182 
    183198          annotation.AxisX = chart.ChartAreas[0].AxisX;
    184           annotation.AxisY = chart.ChartAreas[0].AxisY;
     199          annotation.AxisY = y;
    185200          annotation.Y = threshold;
    186201
     202          name = problemData.GetClassName(classValues[classIndex - 1]);
     203          TextAnnotation beneathLeft = CreateTextAnnotation(name, classIndex, x, y);
     204          beneathLeft.Y = threshold;
     205          beneathLeft.X = x.Minimum;
     206          TextAnnotation beneathRigth = CreateTextAnnotation(name, classIndex, x, y);
     207          beneathRigth.Y = threshold;
     208          textSizeInPixel = g.MeasureString(beneathRigth.Text, beneathRigth.Font);
     209          double textWidthPixelPos = x.ValueToPixelPosition(x.Maximum) - textSizeInPixel.Width - ClassNameLeftOffset;
     210          //check if position is within the position boundary
     211          beneathRigth.X = textWidthPixelPos < 0 || textWidthPixelPos > chart.Width ? double.NaN : x.PixelPositionToValue(textWidthPixelPos);
     212
     213          name = problemData.GetClassName(classValues[classIndex]);
     214          TextAnnotation aboveLeft = CreateTextAnnotation(name, classIndex, x, y);
     215          textSizeInPixel = g.MeasureString(aboveLeft.Text, aboveLeft.Font);
     216          double textHeightPixelPos = y.ValueToPixelPosition(threshold) - textSizeInPixel.Height - ClassNameBottomOffset;
     217          //check if position is within the position boundary
     218          aboveLeft.Y = textHeightPixelPos < 0 || textHeightPixelPos > chart.Height ? double.NaN : y.PixelPositionToValue(textHeightPixelPos);
     219          aboveLeft.X = x.Minimum;
     220          TextAnnotation aboveRight = CreateTextAnnotation(name, classIndex, x, y);
     221          aboveRight.Y = aboveLeft.Y;
     222          textWidthPixelPos = x.ValueToPixelPosition(x.Maximum) - textSizeInPixel.Width - ClassNameLeftOffset;
     223          //check if position is within the position boundary
     224          aboveRight.X = textWidthPixelPos < 0 || textWidthPixelPos > chart.Width ? double.NaN : x.PixelPositionToValue(textWidthPixelPos);
     225
    187226          chart.Annotations.Add(annotation);
     227          chart.Annotations.Add(beneathLeft);
     228          chart.Annotations.Add(aboveLeft);
     229          chart.Annotations.Add(beneathRigth);
     230          chart.Annotations.Add(aboveRight);
    188231          classIndex++;
    189232        }
    190233      }
     234    }
     235
     236    private TextAnnotation CreateTextAnnotation(string name, int classIndex, Axis x, Axis y) {
     237      TextAnnotation annotation = new TextAnnotation();
     238      annotation.Text = name;
     239      annotation.AllowMoving = true;
     240      annotation.AllowResizing = false;
     241      annotation.AllowSelecting = false;
     242      annotation.ClipToChartArea = chart.ChartAreas[0].Name;
     243      annotation.Tag = classIndex;
     244      annotation.AxisX = chart.ChartAreas[0].AxisX;
     245      annotation.AxisY = y;
     246      return annotation;
    191247    }
    192248
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.Designer.cs

    r8689 r8863  
    2121
    2222#endregion
     23
    2324namespace HeuristicLab.Problems.DataAnalysis.Views {
    2425  partial class AbstractFeatureCorrelationView {
     
    4849      this.components = new System.ComponentModel.Container();
    4950      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AbstractFeatureCorrelationView));
    50       this.DataGridView = new System.Windows.Forms.DataGridView();
    5151      this.HeatMapProgressBar = new System.Windows.Forms.ProgressBar();
    5252      this.PartitionComboBox = new System.Windows.Forms.ComboBox();
     
    6060      this.CalculatingPanel = new System.Windows.Forms.Panel();
    6161      this.CalculatingLabel = new System.Windows.Forms.Label();
    62       this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
    63       this.ShowHideColumns = new System.Windows.Forms.ToolStripMenuItem();
    64       ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
     62      this.dataView = new HeuristicLab.Problems.DataAnalysis.Views.EnhancedStringConvertibleMatrixView();
    6563      ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).BeginInit();
    6664      ((System.ComponentModel.ISupportInitialize)(this.SplitContainer)).BeginInit();
     
    6967      this.SplitContainer.SuspendLayout();
    7068      this.CalculatingPanel.SuspendLayout();
    71       this.contextMenu.SuspendLayout();
    7269      this.SuspendLayout();
    73       //
    74       // DataGridView
    75       //
    76       this.DataGridView.AllowUserToAddRows = false;
    77       this.DataGridView.AllowUserToDeleteRows = false;
    78       this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    79       this.DataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
    80       this.DataGridView.Location = new System.Drawing.Point(0, 0);
    81       this.DataGridView.Name = "DataGridView";
    82       this.DataGridView.ReadOnly = true;
    83       this.DataGridView.Size = new System.Drawing.Size(475, 301);
    84       this.DataGridView.TabIndex = 0;
    85       this.DataGridView.VirtualMode = true;
    86       this.DataGridView.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.DataGridView_CellPainting);
    87       this.DataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.DataGridView_CellValueNeeded);
    88       this.DataGridView.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_ColumnHeaderMouseClick);
    89       this.DataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DataGridView_KeyDown);
    90       this.DataGridView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.DataGridView_MouseClick);
    9170      //
    9271      // HeatMapProgressBar
     
    162141      //
    163142      this.PictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    164                   | System.Windows.Forms.AnchorStyles.Right)));
     143            | System.Windows.Forms.AnchorStyles.Right)));
    165144      this.PictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    166145      this.PictureBox.Image = ((System.Drawing.Image)(resources.GetObject("PictureBox.Image")));
     
    175154      //
    176155      this.SplitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    177                   | System.Windows.Forms.AnchorStyles.Left)
    178                   | System.Windows.Forms.AnchorStyles.Right)));
     156            | System.Windows.Forms.AnchorStyles.Left)
     157            | System.Windows.Forms.AnchorStyles.Right)));
    179158      this.SplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
    180159      this.SplitContainer.IsSplitterFixed = true;
     
    193172      //
    194173      this.SplitContainer.Panel2.Controls.Add(this.CalculatingPanel);
    195       this.SplitContainer.Panel2.Controls.Add(this.DataGridView);
     174      this.SplitContainer.Panel2.Controls.Add(this.dataView);
    196175      this.SplitContainer.Size = new System.Drawing.Size(475, 330);
    197176      this.SplitContainer.SplitterDistance = 25;
     
    217196      this.CalculatingLabel.Text = "Calculating correlation...";
    218197      //
    219       // contextMenu
    220       //
    221       this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    222             this.ShowHideColumns});
    223       this.contextMenu.Name = "contextMenu";
    224       this.contextMenu.Size = new System.Drawing.Size(191, 26);
    225       //
    226       // ShowHideColumns
    227       //
    228       this.ShowHideColumns.Name = "ShowHideColumns";
    229       this.ShowHideColumns.Size = new System.Drawing.Size(190, 22);
    230       this.ShowHideColumns.Text = "Show / Hide Columns";
    231       this.ShowHideColumns.Click += new System.EventHandler(this.ShowHideColumns_Click);
     198      // DataGridView
     199      //
     200      this.dataView.Dock = System.Windows.Forms.DockStyle.Fill;
     201      this.dataView.Location = new System.Drawing.Point(0, 0);
     202      this.dataView.Name = "DataView";
     203      this.dataView.ReadOnly = true;
     204      this.dataView.Size = new System.Drawing.Size(475, 301);
     205      this.dataView.TabIndex = 0;
    232206      //
    233207      // AbstractFeatureCorrelationView
     
    241215      this.Name = "AbstractFeatureCorrelationView";
    242216      this.Size = new System.Drawing.Size(569, 336);
    243       ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
    244217      ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).EndInit();
    245218      this.SplitContainer.Panel1.ResumeLayout(false);
     
    250223      this.CalculatingPanel.ResumeLayout(false);
    251224      this.CalculatingPanel.PerformLayout();
    252       this.contextMenu.ResumeLayout(false);
    253225      this.ResumeLayout(false);
    254226
     
    257229    #endregion
    258230
    259     protected System.Windows.Forms.DataGridView DataGridView;
    260231    protected System.Windows.Forms.ProgressBar HeatMapProgressBar;
    261232    protected System.Windows.Forms.ComboBox PartitionComboBox;
     
    269240    protected System.Windows.Forms.Panel CalculatingPanel;
    270241    protected System.Windows.Forms.Label CalculatingLabel;
    271     protected System.Windows.Forms.ContextMenuStrip contextMenu;
    272     protected System.Windows.Forms.ToolStripMenuItem ShowHideColumns;
     242    protected HeuristicLab.Problems.DataAnalysis.Views.EnhancedStringConvertibleMatrixView dataView;
    273243
    274244  }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs

    r8729 r8863  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using System.ComponentModel;
    25 using System.Drawing;
    2623using System.Linq;
    27 using System.Text;
    2824using System.Windows.Forms;
    29 using HeuristicLab.Analysis;
    30 using HeuristicLab.Common;
    31 using HeuristicLab.Data.Views;
    32 using HeuristicLab.DataAnalysis.Views;
     25using HeuristicLab.Data;
    3326using HeuristicLab.MainForm;
    3427using HeuristicLab.MainForm.WindowsForms;
     28using HeuristicLab.PluginInfrastructure;
    3529
    3630namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3832  [Content(typeof(DataAnalysisProblemData), false)]
    3933  public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView {
    40 
    41     private int[] virtualRowIndices;
    42     private VariableVisibilityDialog variableVisibility;
    43     private List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
    44     private StringConvertibleMatrixView.RowComparer rowComparer;
    45 
    4634    protected FeatureCorrelationCalculator fcc;
    47     protected HeatMap currentCorrelation;
     35    protected DoubleMatrix currentCorrelation;
    4836
    4937    public new DataAnalysisProblemData Content {
     
    5442    protected AbstractFeatureCorrelationView() {
    5543      InitializeComponent();
    56       sortedColumnIndices = new List<KeyValuePair<int, SortOrder>>();
    57       rowComparer = new StringConvertibleMatrixView.RowComparer();
    5844      fcc = new FeatureCorrelationCalculator();
    59       var calculatorList = FeatureCorrelationEnums.EnumToList<FeatureCorrelationEnums.CorrelationCalculators>().Select(x => new KeyValuePair<FeatureCorrelationEnums.CorrelationCalculators, string>(x, FeatureCorrelationEnums.GetEnumDescription(x))).ToList();
    60       CorrelationCalcComboBox.ValueMember = "Key";
    61       CorrelationCalcComboBox.DisplayMember = "Value";
    62       CorrelationCalcComboBox.DataSource = new BindingList<KeyValuePair<FeatureCorrelationEnums.CorrelationCalculators, string>>(calculatorList);
    63       var partitionList = FeatureCorrelationEnums.EnumToList<FeatureCorrelationEnums.Partitions>().Select(x => new KeyValuePair<FeatureCorrelationEnums.Partitions, string>(x, FeatureCorrelationEnums.GetEnumDescription(x))).ToList();
    64       PartitionComboBox.ValueMember = "Key";
    65       PartitionComboBox.DisplayMember = "Value";
    66       PartitionComboBox.DataSource = new BindingList<KeyValuePair<FeatureCorrelationEnums.Partitions, string>>(partitionList);
     45      var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
     46      var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
     47      CorrelationCalcComboBox.ValueMember = "Calculator";
     48      CorrelationCalcComboBox.DisplayMember = "Name";
     49      CorrelationCalcComboBox.DataSource = calcList;
     50      CorrelationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator)));
     51      PartitionComboBox.DataSource = FeatureCorrelationPartitions.Partitions;
     52      PartitionComboBox.SelectedItem = FeatureCorrelationPartitions.TRAININGSAMPLES;
    6753    }
    6854
     
    8167    protected override void OnContentChanged() {
    8268      base.OnContentChanged();
     69      fcc.TryCancelCalculation();
    8370      if (Content != null) {
    8471        fcc.ProblemData = Content;
    85         bool[] initialVisibility = SetInitialVisibilityOfColumns();
    86 
    87         variableVisibility = new VariableVisibilityDialog(Content.Dataset.DoubleVariables, initialVisibility);
    88         variableVisibility.VariableVisibilityChanged += new ItemCheckEventHandler(variableVisibility_VariableVisibilityChanged);
    8972        CalculateCorrelation();
    9073      } else {
    91         DataGridView.Columns.Clear();
    92         DataGridView.Rows.Clear();
     74        dataView.Maximum = 0;
     75        dataView.Minimum = 0;
     76        dataView.Content = null;
     77        dataView.ResetVisibility();
    9378      }
    9479    }
    9580
    96     protected virtual bool[] SetInitialVisibilityOfColumns() {
     81    protected virtual bool[] SetInitialVariableVisibility() {
    9782      bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
    9883      int i = 0;
     
    10388      return initialVisibility;
    10489    }
    105 
    106     protected abstract void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e);
    10790
    10891    protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
     
    11699    protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
    117100
    118     protected void UpdateDataGrid() {
    119       virtualRowIndices = Enumerable.Range(0, currentCorrelation.Rows).ToArray();
    120       DataGridViewColumn[] columns = new DataGridViewColumn[currentCorrelation.Columns];
    121       for (int i = 0; i < columns.Length; ++i) {
    122         var column = new DataGridViewTextBoxColumn();
    123         column.FillWeight = 1;
    124         columns[i] = column;
    125       }
     101    protected void UpdateDataView() {
     102      IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
     103      maximumLabel.Text = calc.Maximum.ToString();
     104      minimumLabel.Text = calc.Minimum.ToString();
    126105
    127       DataGridView.Columns.Clear();
    128       DataGridView.Columns.AddRange(columns);
    129 
    130       DataGridView.RowCount = currentCorrelation.Rows;
    131 
    132       ClearSorting();
    133       UpdateColumnHeaders();
    134       UpdateRowHeaders();
    135 
    136       maximumLabel.Text = currentCorrelation.Maximum.ToString();
    137       minimumLabel.Text = currentCorrelation.Minimum.ToString();
    138 
    139       DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);
    140       DataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
    141       DataGridView.Enabled = true;
    142     }
    143 
    144     protected virtual void UpdateColumnHeaders() {
    145       for (int i = 0; i < DataGridView.ColumnCount; i++) {
    146         DataGridView.Columns[i].HeaderText = currentCorrelation.ColumnNames.ElementAt(i);
    147         DataGridView.Columns[i].Visible = variableVisibility.Visibility[i];
    148       }
    149     }
    150     protected virtual void UpdateRowHeaders() {
    151       for (int i = 0; i < DataGridView.RowCount; i++) {
    152         DataGridView.Rows[i].HeaderCell.Value = currentCorrelation.RowNames.ElementAt(virtualRowIndices[i]);
    153         DataGridView.Rows[i].Visible = variableVisibility.Visibility[virtualRowIndices[i]];
    154       }
     106      currentCorrelation.SortableView = true;
     107      dataView.Maximum = calc.Maximum;
     108      dataView.Minimum = calc.Minimum;
     109      dataView.Content = currentCorrelation;
     110      dataView.Enabled = true;
    155111    }
    156112
     
    163119      HeatMapProgressBar.Value = e.ProgressPercentage;
    164120    }
    165 
    166     protected void DataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) {
    167       if (Content == null) return;
    168       int rowIndex = virtualRowIndices[e.RowIndex];
    169       e.Value = currentCorrelation[rowIndex, e.ColumnIndex];
    170     }
    171 
    172     protected void DataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
    173       if (Content == null) return;
    174       if (e.RowIndex < 0) return;
    175       if (e.ColumnIndex < 0) return;
    176       if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
    177       if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
    178 
    179       int rowIndex = virtualRowIndices[e.RowIndex];
    180       Color backColor = GetDataPointColor(currentCorrelation[rowIndex, e.ColumnIndex], currentCorrelation.Minimum, currentCorrelation.Maximum);
    181       using (Brush backColorBrush = new SolidBrush(backColor)) {
    182         e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
    183       }
    184       e.PaintContent(e.CellBounds);
    185       e.Handled = true;
    186     }
    187 
    188     protected virtual Color GetDataPointColor(double value, double min, double max) {
    189       if (double.IsNaN(value)) {
    190         return Color.DarkGray;
    191       }
    192       IList<Color> colors = ColorGradient.Colors;
    193       int index = (int)((colors.Count - 1) * (value - min) / (max - min));
    194       if (index >= colors.Count) index = colors.Count - 1;
    195       if (index < 0) index = 0;
    196       return colors[index];
    197     }
    198 
    199     #region sort
    200     protected void DataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
    201       if (Content != null) {
    202         if (e.Button == MouseButtons.Left) {
    203           bool addToSortedIndices = (Control.ModifierKeys & Keys.Control) == Keys.Control;
    204           SortOrder newSortOrder = SortOrder.Ascending;
    205           if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) {
    206             SortOrder oldSortOrder = sortedColumnIndices.Where(x => x.Key == e.ColumnIndex).First().Value;
    207             int enumLength = Enum.GetValues(typeof(SortOrder)).Length;
    208             newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString());
    209           }
    210 
    211           if (!addToSortedIndices)
    212             sortedColumnIndices.Clear();
    213 
    214           if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) {
    215             int sortedIndex = sortedColumnIndices.FindIndex(x => x.Key == e.ColumnIndex);
    216             if (newSortOrder != SortOrder.None)
    217               sortedColumnIndices[sortedIndex] = new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder);
    218             else
    219               sortedColumnIndices.RemoveAt(sortedIndex);
    220           } else
    221             if (newSortOrder != SortOrder.None)
    222               sortedColumnIndices.Add(new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder));
    223           Sort();
    224         }
    225       }
    226     }
    227 
    228     protected virtual void ClearSorting() {
    229       virtualRowIndices = Enumerable.Range(0, currentCorrelation.Rows).ToArray();
    230       sortedColumnIndices.Clear();
    231       UpdateSortGlyph();
    232     }
    233 
    234     private void Sort() {
    235       virtualRowIndices = Sort(sortedColumnIndices);
    236       UpdateSortGlyph();
    237       UpdateRowHeaders();
    238       DataGridView.Invalidate();
    239     }
    240 
    241     protected virtual int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
    242       int[] newSortedIndex = Enumerable.Range(0, currentCorrelation.Rows).ToArray();
    243       if (sortedColumns.Count() != 0) {
    244         rowComparer.SortedIndices = sortedColumns;
    245         rowComparer.Matrix = currentCorrelation;
    246         Array.Sort(newSortedIndex, rowComparer);
    247       }
    248       return newSortedIndex;
    249     }
    250     private void UpdateSortGlyph() {
    251       foreach (DataGridViewColumn col in this.DataGridView.Columns)
    252         col.HeaderCell.SortGlyphDirection = SortOrder.None;
    253       foreach (KeyValuePair<int, SortOrder> p in sortedColumnIndices)
    254         this.DataGridView.Columns[p.Key].HeaderCell.SortGlyphDirection = p.Value;
    255     }
    256     #endregion
    257 
    258     #region copy
    259     protected void DataGridView_KeyDown(object sender, KeyEventArgs e) {
    260       if (e.Control && e.KeyCode == Keys.C)
    261         CopyValuesFromDataGridView();
    262     }
    263 
    264     private void CopyValuesFromDataGridView() {
    265       if (DataGridView.SelectedCells.Count == 0) return;
    266       StringBuilder s = new StringBuilder();
    267       int minRowIndex = DataGridView.SelectedCells[0].RowIndex;
    268       int maxRowIndex = DataGridView.SelectedCells[DataGridView.SelectedCells.Count - 1].RowIndex;
    269       int minColIndex = DataGridView.SelectedCells[0].ColumnIndex;
    270       int maxColIndex = DataGridView.SelectedCells[DataGridView.SelectedCells.Count - 1].ColumnIndex;
    271 
    272       if (minRowIndex > maxRowIndex) {
    273         int temp = minRowIndex;
    274         minRowIndex = maxRowIndex;
    275         maxRowIndex = temp;
    276       }
    277       if (minColIndex > maxColIndex) {
    278         int temp = minColIndex;
    279         minColIndex = maxColIndex;
    280         maxColIndex = temp;
    281       }
    282 
    283       bool addRowNames = DataGridView.AreAllCellsSelected(false) && currentCorrelation.RowNames.Count() > 0;
    284       bool addColumnNames = DataGridView.AreAllCellsSelected(false) && currentCorrelation.ColumnNames.Count() > 0;
    285 
    286       //add colum names
    287       if (addColumnNames) {
    288         if (addRowNames)
    289           s.Append('\t');
    290 
    291         DataGridViewColumn column = DataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    292         while (column != null) {
    293           s.Append(column.HeaderText);
    294           s.Append('\t');
    295           column = DataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
    296         }
    297         s.Remove(s.Length - 1, 1); //remove last tab
    298         s.Append(Environment.NewLine);
    299       }
    300 
    301       for (int i = minRowIndex; i <= maxRowIndex; i++) {
    302         int rowIndex = this.virtualRowIndices[i];
    303         if (addRowNames) {
    304           s.Append(currentCorrelation.RowNames.ElementAt(rowIndex));
    305           s.Append('\t');
    306         }
    307 
    308         DataGridViewColumn column = DataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    309         while (column != null) {
    310           DataGridViewCell cell = DataGridView[column.Index, i];
    311           if (cell.Selected) {
    312             s.Append(currentCorrelation[rowIndex, column.Index]);
    313             s.Append('\t');
    314           }
    315 
    316           column = DataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
    317         }
    318         s.Remove(s.Length - 1, 1); //remove last tab
    319         s.Append(Environment.NewLine);
    320       }
    321       Clipboard.SetText(s.ToString());
    322     }
    323     #endregion
    324 
    325     protected void ShowHideColumns_Click(object sender, EventArgs e) {
    326       variableVisibility.ShowDialog();
    327     }
    328 
    329     protected void DataGridView_MouseClick(object sender, MouseEventArgs e) {
    330       if (Content == null) return;
    331       if (e.Button == MouseButtons.Right && DataGridView.Columns.Count != 0)
    332         contextMenu.Show(MousePosition);
    333     }
    334 
    335     protected int GetRowIndexOfVirtualindex(int virtualIndex) {
    336       if (virtualIndex < 0 || virtualIndex >= virtualRowIndices.Length) {
    337         throw new ArgumentException("Virtual index is out of bounds");
    338       }
    339 
    340       for (int i = 0; i < virtualRowIndices.Length; i++) {
    341         if (virtualRowIndices[i] == virtualIndex) {
    342           return i;
    343         }
    344       }
    345       throw new ArgumentException("Virtual index was not found!");
    346     }
    347121  }
    348122}
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs

    r8729 r8863  
    5151    }
    5252
    53     public void CalculateElements(FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitions partition) {
     53    public void CalculateElements(IDependencyCalculator calc, string partition) {
    5454      CalculateElements(problemData.Dataset, calc, partition);
    5555    }
    5656
    57     // returns if any calculation takes place
    58     public bool CalculateTimeframeElements(FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitions partition, string variable, int frames, double[,] correlation = null) {
     57    // returns true if any calculation takes place
     58    public bool CalculateTimeframeElements(IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null) {
    5959      if (correlation == null || correlation.GetLength(1) <= frames) {
    6060        CalculateElements(problemData.Dataset, calc, partition, variable, frames, correlation);
     
    6565    }
    6666
     67    public void TryCancelCalculation() {
     68      if (bw != null && bw.IsBusy) {
     69        bwInfo = null;
     70        bw.CancelAsync();
     71      }
     72    }
     73
    6774    private double[,] GetElementsOfCorrelation(double[,] corr, int frames) {
    6875      double[,] elements = new double[corr.GetLength(0), frames + 1];
     
    7582    }
    7683
    77     private void CalculateElements(Dataset dataset, FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitions partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null) {
     84    private void CalculateElements(Dataset dataset, IDependencyCalculator calc, string partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null) {
    7885      bwInfo = new BackgroundWorkerInfo { Dataset = dataset, Calculator = calc, Partition = partition, Variable = variable, Frames = frames, AlreadyCalculated = alreadyCalculated };
    7986      if (bw == null) {
     
    107114      BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;
    108115      Dataset dataset = bwInfo.Dataset;
    109       FeatureCorrelationEnums.Partitions partition = bwInfo.Partition;
    110       FeatureCorrelationEnums.CorrelationCalculators calc = bwInfo.Calculator;
     116      string partition = bwInfo.Partition;
     117      IDependencyCalculator calc = bwInfo.Calculator;
    111118
    112119      IList<string> doubleVariableNames = dataset.DoubleVariables.ToList();
     
    121128        for (int j = 0; j < i + 1; j++) {
    122129          if (worker.CancellationPending) {
     130            worker.ReportProgress(100);
    123131            e.Cancel = true;
    124132            return;
     
    127135          IEnumerable<double> var2 = GetRelevantValues(problemData, partition, doubleVariableNames[j]);
    128136
    129           elements[i, j] = CalculateElementWithCalculator(calc, var1, var2, out error);
     137          elements[i, j] = calc.Calculate(var1, var2, out error);
    130138
    131139          if (!error.Equals(OnlineCalculatorError.None)) {
     
    137145      }
    138146      e.Result = elements;
     147      worker.ReportProgress(100);
    139148    }
    140149
     
    144153      BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;
    145154      Dataset dataset = bwInfo.Dataset;
    146       FeatureCorrelationEnums.Partitions partition = bwInfo.Partition;
    147       FeatureCorrelationEnums.CorrelationCalculators calc = bwInfo.Calculator;
     155      string partition = bwInfo.Partition;
     156      IDependencyCalculator calc = bwInfo.Calculator;
    148157      string variable = bwInfo.Variable;
    149158      int frames = bwInfo.Frames;
     
    169178        for (int j = start; j <= frames; j++) {
    170179          if (worker.CancellationPending) {
     180            worker.ReportProgress(100);
    171181            e.Cancel = true;
    172182            return;
     
    181191          var1 = help;
    182192
    183           elements[i, j] = CalculateElementWithCalculator(calc, var1, var2, out error);
     193          elements[i, j] = calc.Calculate(var1, var2, out error);
    184194
    185195          if (!error.Equals(OnlineCalculatorError.None)) {
     
    190200      }
    191201      e.Result = elements;
    192     }
    193 
    194     private IEnumerable<double> GetRelevantValues(IDataAnalysisProblemData problemData, FeatureCorrelationEnums.Partitions partition, string variable) {
     202      worker.ReportProgress(100);
     203    }
     204
     205    private IEnumerable<double> GetRelevantValues(IDataAnalysisProblemData problemData, string partition, string variable) {
    195206      IEnumerable<double> var = problemData.Dataset.GetDoubleValues(variable);
    196       if (partition.Equals(FeatureCorrelationEnums.Partitions.TrainingSamples)) {
     207      if (partition.Equals(FeatureCorrelationPartitions.TRAININGSAMPLES)) {
    197208        var = var.Skip(problemData.TrainingPartition.Start).Take(problemData.TrainingPartition.End - problemData.TrainingPartition.Start);
    198       } else if (partition.Equals(FeatureCorrelationEnums.Partitions.TestSamples)) {
     209      } else if (partition.Equals(FeatureCorrelationPartitions.TESTSAMPLES)) {
    199210        var = var.Skip(problemData.TestPartition.Start).Take(problemData.TestPartition.End - problemData.TestPartition.Start);
    200211      }
    201212      return var;
    202     }
    203 
    204     private double CalculateElementWithCalculator(FeatureCorrelationEnums.CorrelationCalculators calc, IEnumerable<double> var1, IEnumerable<double> var2, out OnlineCalculatorError error) {
    205       if (calc.Equals(FeatureCorrelationEnums.CorrelationCalculators.HoeffdingsDependence)) {
    206         return HoeffdingsDependenceCalculator.Calculate(var1, var2, out error);
    207       } else if (calc.Equals(FeatureCorrelationEnums.CorrelationCalculators.SpearmansRank)) {
    208         return SpearmansRankCorrelationCoefficientCalculator.Calculate(var1, var2, out error);
    209       } else if (calc.Equals(FeatureCorrelationEnums.CorrelationCalculators.PearsonsRSquared)) {
    210         return OnlinePearsonsRSquaredCalculator.Calculate(var1, var2, out error);
    211       } else {
    212         return Math.Sqrt(OnlinePearsonsRSquaredCalculator.Calculate(var1, var2, out error));
    213       }
    214213    }
    215214
     
    222221          OnCorrelationCalculationFinished((double[,])e.Result, bwInfo.Calculator, bwInfo.Partition, bwInfo.Variable);
    223222        }
    224       } else {
     223      } else if (bwInfo != null) {
    225224        bw.RunWorkerAsync(bwInfo);
    226225      }
     
    231230    public class CorrelationCalculationFinishedArgs : EventArgs {
    232231      public double[,] Correlation { get; private set; }
    233       public FeatureCorrelationEnums.CorrelationCalculators Calculcator { get; private set; }
    234       public FeatureCorrelationEnums.Partitions Partition { get; private set; }
     232      public IDependencyCalculator Calculcator { get; private set; }
     233      public string Partition { get; private set; }
    235234      public string Variable { get; private set; }
    236235
    237       public CorrelationCalculationFinishedArgs(double[,] correlation, FeatureCorrelationEnums.CorrelationCalculators calculator, FeatureCorrelationEnums.Partitions partition, string variable = null) {
     236      public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {
    238237        this.Correlation = correlation;
    239238        this.Calculcator = calculator;
     
    245244    public delegate void CorrelationCalculationFinishedHandler(object sender, CorrelationCalculationFinishedArgs e);
    246245    public event CorrelationCalculationFinishedHandler CorrelationCalculationFinished;
    247     protected virtual void OnCorrelationCalculationFinished(double[,] correlation, FeatureCorrelationEnums.CorrelationCalculators calculator, FeatureCorrelationEnums.Partitions partition, string variable = null) {
     246    protected virtual void OnCorrelationCalculationFinished(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {
    248247      var handler = CorrelationCalculationFinished;
    249248      if (handler != null)
     
    255254    protected void BwProgressChanged(object sender, ProgressChangedEventArgs e) {
    256255      BackgroundWorker worker = sender as BackgroundWorker;
    257       if (!worker.CancellationPending && ProgressCalculation != null) {
     256      if (ProgressCalculation != null) {
    258257        ProgressCalculation(sender, e);
    259258      }
     
    263262    private class BackgroundWorkerInfo {
    264263      public Dataset Dataset { get; set; }
    265       public FeatureCorrelationEnums.CorrelationCalculators Calculator { get; set; }
    266       public FeatureCorrelationEnums.Partitions Partition { get; set; }
     264      public IDependencyCalculator Calculator { get; set; }
     265      public string Partition { get; set; }
    267266      public string Variable { get; set; }
    268267      public int Frames { get; set; }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs

    r8729 r8863  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Windows.Forms;
    23 using HeuristicLab.Analysis;
    2425using HeuristicLab.Data;
    2526using HeuristicLab.MainForm;
    2627using HeuristicLab.MainForm.WindowsForms;
     28using HeuristicLab.PluginInfrastructure;
    2729
    2830namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    4042
    4143    protected override void OnContentChanged() {
     44      if (Content != null) {
     45        dataView.RowVisibility = SetInitialVariableVisibility();
     46        dataView.ColumnVisibility = SetInitialVariableVisibility();
     47      }
    4248      correlationCache.Reset();
    4349      base.OnContentChanged();
     
    4652    protected override void CalculateCorrelation() {
    4753      if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null) {
    48         FeatureCorrelationEnums.CorrelationCalculators calc = (FeatureCorrelationEnums.CorrelationCalculators)CorrelationCalcComboBox.SelectedValue;
    49         FeatureCorrelationEnums.Partitions partition = (FeatureCorrelationEnums.Partitions)PartitionComboBox.SelectedValue;
    50         DataGridView.Columns.Clear();
    51         DataGridView.Enabled = false;
     54        IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
     55        string partition = (string)PartitionComboBox.SelectedValue;
     56        dataView.Enabled = false;
    5257        double[,] corr = correlationCache.GetCorrelation(calc, partition);
    5358        if (corr == null) {
    5459          fcc.CalculateElements(calc, partition);
    5560        } else {
    56           SetNewCorrelation(corr, calc);
    57           UpdateDataGrid();
     61          fcc.TryCancelCalculation();
     62          SetNewCorrelation(corr);
     63          UpdateDataView();
    5864        }
    5965      }
    6066    }
    6167
    62     private void SetNewCorrelation(double[,] elements, FeatureCorrelationEnums.CorrelationCalculators calc) {
    63       DoubleRange range = FeatureCorrelationEnums.calculatorInterval[calc];
    64       HeatMap hm = new HeatMap(elements, "", range.End, range.Start);
    65       hm.RowNames = Content.Dataset.DoubleVariables;
    66       hm.ColumnNames = Content.Dataset.DoubleVariables;
    67       currentCorrelation = hm;
     68    private void SetNewCorrelation(double[,] elements) {
     69      currentCorrelation = new DoubleMatrix(elements,
     70                                            Content.Dataset.DoubleVariables,
     71                                            Content.Dataset.DoubleVariables);
    6872    }
    6973
     
    7377      } else {
    7478        correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation);
    75         SetNewCorrelation(e.Correlation, e.Calculcator);
    76         UpdateDataGrid();
     79        SetNewCorrelation(e.Correlation);
     80        UpdateDataView();
    7781      }
    7882    }
    7983
    80     protected override void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e) {
    81       DataGridView.Columns[e.Index].Visible = e.NewValue == CheckState.Checked;
    82       DataGridView.Rows[GetRowIndexOfVirtualindex(e.Index)].Visible = e.NewValue == CheckState.Checked;
     84    [NonDiscoverableType]
     85    private class FeatureCorrelationCache : Object {
     86      private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache;
     87
     88      public FeatureCorrelationCache()
     89        : base() {
     90        InitializeCaches();
     91      }
     92
     93      private void InitializeCaches() {
     94        correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>();
     95      }
     96
     97      public void Reset() {
     98        InitializeCaches();
     99      }
     100
     101      public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {
     102        double[,] corr;
     103        var key = new Tuple<IDependencyCalculator, string>(calc, partition);
     104        correlationsCache.TryGetValue(key, out corr);
     105        return corr;
     106      }
     107
     108      public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {
     109        var key = new Tuple<IDependencyCalculator, string>(calc, partition);
     110        correlationsCache[key] = correlation;
     111      }
    83112    }
    84113  }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.Designer.cs

    r8578 r8863  
    4949      this.VariableSelectionComboBox = new System.Windows.Forms.ComboBox();
    5050      this.TimeFrameLabel = new System.Windows.Forms.Label();
    51       this.TimeframeComboBox = new System.Windows.Forms.ComboBox();
     51      this.TimeframeTextbox = new System.Windows.Forms.TextBox();
    5252      ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).BeginInit();
    5353      ((System.ComponentModel.ISupportInitialize)(this.SplitContainer)).BeginInit();
     
    7878      //
    7979      this.SplitContainer.Panel1.Controls.Add(this.VariableSelectionComboBox);
    80       this.SplitContainer.Panel1.Controls.Add(this.TimeframeComboBox);
     80      this.SplitContainer.Panel1.Controls.Add(this.TimeframeTextbox);
    8181      this.SplitContainer.Panel1.Controls.Add(this.TimeFrameLabel);
    8282      this.SplitContainer.Panel1.Controls.Add(this.VariableSelectionLabel);
     
    117117      // TimeframeComboBox
    118118      //
    119       this.TimeframeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    120       this.TimeframeComboBox.FormattingEnabled = true;
    121       this.TimeframeComboBox.Location = new System.Drawing.Point(344, 30);
    122       this.TimeframeComboBox.Name = "TimeframeComboBox";
    123       this.TimeframeComboBox.Size = new System.Drawing.Size(131, 21);
    124       this.TimeframeComboBox.TabIndex = 19;
    125       this.TimeframeComboBox.SelectionChangeCommitted += new System.EventHandler(this.TimeframeComboBox_SelectedChangeCommitted);
     119      this.TimeframeTextbox.Location = new System.Drawing.Point(344, 30);
     120      this.TimeframeTextbox.Name = "TimeframeTextbox";
     121      this.TimeframeTextbox.Size = new System.Drawing.Size(131, 21);
     122      this.TimeframeTextbox.TabIndex = 19;
     123      this.TimeframeTextbox.Text = "5";
     124      this.TimeframeTextbox.KeyDown += new System.Windows.Forms.KeyEventHandler(TimeframeTextbox_KeyDown);
    126125      //
    127126      // TimeframeFeatureCorrelationView
     
    146145    protected System.Windows.Forms.ComboBox VariableSelectionComboBox;
    147146    protected System.Windows.Forms.Label TimeFrameLabel;
    148     protected System.Windows.Forms.ComboBox TimeframeComboBox;
     147    protected System.Windows.Forms.TextBox TimeframeTextbox;
    149148  }
    150149}
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs

    r8729 r8863  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Windows.Forms;
    25 using HeuristicLab.Analysis;
    2626using HeuristicLab.Data;
    2727using HeuristicLab.MainForm;
     28using HeuristicLab.PluginInfrastructure;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3637    public TimeframeFeatureCorrelationView() {
    3738      InitializeComponent();
    38       TimeframeComboBox.DataSource = Enumerable.Range(0, 16).ToList<int>();
    3939      correlationTimeframCache = new FeatureCorrelationTimeframeCache();
    4040    }
     
    4343      correlationTimeframCache.Reset();
    4444      if (Content != null) {
     45        dataView.RowVisibility = SetInitialVariableVisibility();
    4546        VariableSelectionComboBox.DataSource = Content.Dataset.DoubleVariables.ToList();
    4647      }
     
    5152      CalculateCorrelation();
    5253    }
    53     protected void TimeframeComboBox_SelectedChangeCommitted(object sender, EventArgs e) {
    54       CalculateCorrelation();
     54    protected void TimeframeTextbox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
     55      if (e.KeyCode == Keys.Enter) {
     56        CalculateCorrelation();
     57      }
    5558    }
    5659
    5760    protected override void CalculateCorrelation() {
    58       string variable = (string)VariableSelectionComboBox.SelectedItem;
    59       if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null && variable != null) {
    60         FeatureCorrelationEnums.CorrelationCalculators calc = (FeatureCorrelationEnums.CorrelationCalculators)CorrelationCalcComboBox.SelectedValue;
    61         FeatureCorrelationEnums.Partitions partition = (FeatureCorrelationEnums.Partitions)PartitionComboBox.SelectedValue;
    62         DataGridView.Columns.Clear();
    63         DataGridView.Enabled = false;
    64         int frames = (int)TimeframeComboBox.SelectedItem;
     61      if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null
     62        && VariableSelectionComboBox.SelectedItem != null && ValidateTimeframeTextbox()) {
     63        string variable = (string)VariableSelectionComboBox.SelectedItem;
     64        IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
     65        string partition = (string)PartitionComboBox.SelectedValue;
     66        int frames;
     67        int.TryParse(TimeframeTextbox.Text, out frames);
     68        dataView.Enabled = false;
    6569        double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable);
    6670        if (corr == null) {
     
    6973          fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr);
    7074        } else {
     75          fcc.TryCancelCalculation();
    7176          SetNewCorrelation(corr, calc, frames);
    72           UpdateDataGrid();
     77          UpdateDataView();
    7378        }
    7479      }
    7580    }
    7681
    77     private void SetNewCorrelation(double[,] elements, FeatureCorrelationEnums.CorrelationCalculators calc, int frames) {
     82    protected bool ValidateTimeframeTextbox() {
     83      int help;
     84      if (!int.TryParse(TimeframeTextbox.Text, out help)) {
     85        MessageBox.Show("Timeframe couldn't be parsed. Enter a valid integer value.", "Parse Error", MessageBoxButtons.OK);
     86        return false;
     87      } else {
     88        if (help > 50) {
     89          DialogResult dr = MessageBox.Show("The entered value is bigger than 50. Are you sure you want to calculate? " +
     90                                            "The calculation could take some time.", "Huge Value Warning", MessageBoxButtons.YesNo);
     91          return dr.Equals(DialogResult.Yes);
     92        }
     93      }
     94      return true;
     95    }
     96
     97    private void SetNewCorrelation(double[,] elements, IDependencyCalculator calc, int frames) {
    7898      double[,] neededValues = new double[elements.GetLength(0), frames + 1];
    7999      for (int i = 0; i < elements.GetLength(0); i++) {
    80100        Array.Copy(elements, i * elements.GetLength(1), neededValues, i * neededValues.GetLength(1), frames + 1);
    81101      }
    82       SetNewCorrelation(neededValues, calc);
     102      SetNewCorrelation(neededValues);
    83103    }
    84104
    85     private void SetNewCorrelation(double[,] elements, FeatureCorrelationEnums.CorrelationCalculators calc) {
    86       DoubleRange range = FeatureCorrelationEnums.calculatorInterval[calc];
    87       HeatMap hm = new HeatMap(elements, "", range.End, range.Start);
    88       hm.RowNames = Content.Dataset.DoubleVariables;
    89       hm.ColumnNames = Enumerable.Range(0, elements.GetLength(1)).Select(x => x.ToString());
    90       currentCorrelation = hm;
     105    private void SetNewCorrelation(double[,] elements) {
     106      currentCorrelation = new DoubleMatrix(elements,
     107                                            Enumerable.Range(0, elements.GetLength(1)).Select(x => x.ToString()),
     108                                            Content.Dataset.DoubleVariables);
    91109    }
    92110
     
    96114      } else {
    97115        correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation);
    98         SetNewCorrelation(e.Correlation, e.Calculcator);
    99         UpdateDataGrid();
     116        SetNewCorrelation(e.Correlation);
     117        UpdateDataView();
    100118      }
    101119    }
    102120
    103     protected override void UpdateColumnHeaders() {
    104       for (int i = 0; i < DataGridView.ColumnCount; i++) {
    105         DataGridView.Columns[i].HeaderText = i.ToString();
     121    [NonDiscoverableType]
     122    private class FeatureCorrelationTimeframeCache : Object {
     123      private Dictionary<Tuple<IDependencyCalculator, string, string>, double[,]> timeFrameCorrelationsCache;
     124
     125      public FeatureCorrelationTimeframeCache()
     126        : base() {
     127        InitializeCaches();
    106128      }
    107     }
    108129
    109     protected override void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e) {
    110       DataGridView.Rows[GetRowIndexOfVirtualindex(e.Index)].Visible = e.NewValue == CheckState.Checked;
     130      private void InitializeCaches() {
     131        timeFrameCorrelationsCache = new Dictionary<Tuple<IDependencyCalculator, string, string>, double[,]>();
     132      }
     133
     134      public void Reset() {
     135        InitializeCaches();
     136      }
     137
     138      public double[,] GetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable) {
     139        double[,] corr;
     140        var key = new Tuple<IDependencyCalculator, string, string>(calc, partition, variable);
     141        timeFrameCorrelationsCache.TryGetValue(key, out corr);
     142        return corr;
     143      }
     144
     145      public void SetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable, double[,] correlation) {
     146        var key = new Tuple<IDependencyCalculator, string, string>(calc, partition, variable);
     147        timeFrameCorrelationsCache[key] = correlation;
     148      }
    111149    }
    112150  }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r8814 r8863  
    227227      <DependentUpon>DataAnalysisSolutionEvaluationView.cs</DependentUpon>
    228228    </Compile>
     229    <Compile Include="FeatureCorrelation\EnhancedStringConvertibleMatrixView.cs">
     230      <SubType>UserControl</SubType>
     231    </Compile>
     232    <Compile Include="FeatureCorrelation\EnhancedStringConvertibleMatrixView.Designer.cs">
     233      <DependentUpon>EnhancedStringConvertibleMatrixView.cs</DependentUpon>
     234    </Compile>
    229235    <Compile Include="FeatureCorrelation\FeatureCorrelationCalculator.cs" />
    230     <Compile Include="FeatureCorrelation\FeatureCorrelationEnums.cs" />
    231     <Compile Include="FeatureCorrelation\VariableVisibilityDialog.cs">
    232       <SubType>Form</SubType>
    233     </Compile>
    234     <Compile Include="FeatureCorrelation\VariableVisibilityDialog.Designer.cs">
    235       <DependentUpon>VariableVisibilityDialog.cs</DependentUpon>
    236     </Compile>
     236    <Compile Include="FeatureCorrelation\FeatureCorrelationHelpers.cs" />
    237237    <Compile Include="FeatureCorrelation\FeatureCorrelationView.cs">
    238238      <SubType>UserControl</SubType>
     
    241241      <DependentUpon>FeatureCorrelationView.cs</DependentUpon>
    242242    </Compile>
    243     <Compile Include="FeatureCorrelation\FeatureCorrelationCache.cs" />
    244     <Compile Include="FeatureCorrelation\FeatureCorrelationTimeframeCache.cs" />
    245243    <Compile Include="Plugin.cs" />
    246244    <Compile Include="ProblemDataView.cs">
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs

    r8811 r8863  
    4545
    4646    protected void FeatureCorrelationButton_Click(object sender, System.EventArgs e) {
    47       Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(AbstractFeatureCorrelationView).IsAssignableFrom(t));
     47      Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(FeatureCorrelationView).IsAssignableFrom(t));
    4848      MainFormManager.MainForm.ShowContent(Content, viewType);
    4949    }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionFeatureCorrelationView.cs

    r8811 r8863  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionTimeframeFeatureCorrelationView.cs

    r8811 r8863  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r8814 r8863  
    199199    <Compile Include="Interfaces\Classification\IClassificationEnsembleSolutionWeightCalculator.cs" />
    200200    <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" />
     201    <Compile Include="Interfaces\IDependencyCalculator.cs" />
    201202    <Compile Include="Interfaces\Regression\IRegressionEnsembleModel.cs">
    202203      <SubType>Code</SubType>
     
    210211    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" />
    211212    <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" />
     213    <Compile Include="OnlineCalculators\DependencyCalculator\HoeffdingsDependenceCalculator.cs" />
     214    <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRDependenceCalculator.cs" />
     215    <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRSquaredDependenceCalculator.cs" />
     216    <Compile Include="OnlineCalculators\DependencyCalculator\SpearmansRankCorrelationCoefficientCalculator.cs" />
    212217    <Compile Include="OnlineCalculators\OnlineBoundedMeanSquaredErrorCalculator.cs" />
    213     <Compile Include="OnlineCalculators\HoeffdingsDependenceCalculator.cs" />
    214218    <Compile Include="OnlineCalculators\OnlineDirectionalSymmetryCalculator.cs" />
    215219    <Compile Include="OnlineCalculators\OnlineMaxAbsoluteErrorCalculator.cs" />
     
    253257    <Compile Include="OnlineCalculators\OnlineTheilsUStatisticCalculator.cs" />
    254258    <Compile Include="OnlineCalculators\OnlineWeightedDirectionalSymmetryCalculator.cs" />
    255     <Compile Include="OnlineCalculators\SpearmansRankCorrelationCoefficientCalculator.cs" />
    256259    <Compile Include="Plugin.cs" />
    257260    <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" />
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r8811 r8863  
    136136
    137137    public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) {
    138       return new DiscriminantFunctionClassificationSolution(this, problemData);
     138      return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData));
    139139    }
    140140
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/ConstantTimeSeriesPrognosisModel.cs

    r8458 r8863  
    4444
    4545    public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) {
    46       return new TimeSeriesPrognosisSolution(this, problemData);
     46      return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData));
    4747    }
    4848  }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs

    r8487 r8863  
    109109
    110110    public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) {
    111       return new TimeSeriesPrognosisSolution(this, problemData);
     111      return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData));
    112112    }
    113113    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs

    r8486 r8863  
    15951595    }
    15961596
     1597    public TimeSeriesPrognosisProblemData(ITimeSeriesPrognosisProblemData timeseriesProblemData)
     1598      : this(timeseriesProblemData.Dataset, timeseriesProblemData.AllowedInputVariables, timeseriesProblemData.TargetVariable) {
     1599
     1600      TestHorizon = timeseriesProblemData.TestHorizon;
     1601      TrainingHorizon = timeseriesProblemData.TestHorizon;
     1602    }
     1603
    15971604    [StorableHook(HookType.AfterDeserialization)]
    15981605    private void AfterDeserialization() {
Note: See TracChangeset for help on using the changeset viewer.