Changeset 8863
- Timestamp:
- 10/30/12 16:22:04 (12 years ago)
- Location:
- branches/ClassificationEnsembleVoting
- Files:
-
- 4 deleted
- 24 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis merged: 8833,8857,8861
- Property svn:mergeinfo changed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Views merged: 8831,8833,8840,8859,8861
- Property svn:mergeinfo changed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionAccuracyToCoveredSamples.cs
r8862 r8863 118 118 } 119 119 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 } 131 133 } 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(); 132 140 } 133 141 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!"; 139 167 } 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;164 168 } 165 169 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs
r8814 r8863 133 133 int row = indizes[i]; 134 134 values[i, 0] = row.ToString(); 135 values[i, 1] = target[ i].ToString();135 values[i, 1] = target[row].ToString(); 136 136 //display only indices and target values if no models are present 137 137 if (solutionsCount > 0) { 138 138 values[i, 2] = estimatedClassValues[i].ToString(); 139 correctClassified = target[ i].IsAlmost(estimatedClassValues[i]);139 correctClassified = target[row].IsAlmost(estimatedClassValues[i]); 140 140 values[i, 3] = correctClassified.ToString(); 141 141 curConfidence = confidences[i]; -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationFeatureCorrelationView.cs
r8811 r8863 37 37 } 38 38 39 protected override bool[] SetInitialV isibilityOfColumns() {39 protected override bool[] SetInitialVariableVisibility() { 40 40 int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable); 41 var initialVisibility = base.SetInitialV isibilityOfColumns();41 var initialVisibility = base.SetInitialVariableVisibility(); 42 42 initialVisibility[i] = true; 43 43 return initialVisibility; -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationTimeframeFeatureCorrelationView.cs
r8811 r8863 37 37 } 38 38 39 protected override bool[] SetInitialV isibilityOfColumns() {39 protected override bool[] SetInitialVariableVisibility() { 40 40 int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable); 41 var initialVisibility = base.SetInitialV isibilityOfColumns();41 var initialVisibility = base.SetInitialVariableVisibility(); 42 42 initialVisibility[i] = true; 43 43 return initialVisibility; -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationRocCurvesView.cs
r8811 r8863 114 114 maxThreshold += thresholdIncrement; 115 115 116 List<double> classValues = Content. Model.ClassValues.ToList();116 List<double> classValues = Content.ProblemData.ClassValues.ToList(); 117 117 118 118 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 { 1 using System.Windows.Forms.DataVisualization.Charting; 2 namespace HeuristicLab.Problems.DataAnalysis.Views { 2 3 partial class DiscriminantFunctionClassificationSolutionThresholdView { 3 4 /// <summary> … … 53 54 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 54 55 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); 55 57 // 56 58 // JitterTrackBar … … 92 94 93 95 } 94 95 96 #endregion 96 97 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs
r8811 r8863 40 40 private const string TestLabelText = "Test Samples"; 41 41 42 private const double ClassNameLeftOffset = 10.0; 43 private const double ClassNameBottomOffset = 5.0; 44 42 45 public new IDiscriminantFunctionClassificationSolution Content { 43 46 get { return (IDiscriminantFunctionClassificationSolution)base.Content; } … … 47 50 private Dictionary<double, Series> classValueSeriesMapping; 48 51 private Random random; 49 private bool updateInProgress ;52 private bool updateInProgress, updateThresholds; 50 53 51 54 public DiscriminantFunctionClassificationSolutionThresholdView() … … 126 129 FillSeriesWithDataPoints(series); 127 130 } 128 AddThresholds();131 updateThresholds = true; 129 132 } 130 133 chart.ChartAreas[0].RecalculateAxesScale(); … … 166 169 } 167 170 171 private void chart_PostPaint(object sender, ChartPaintEventArgs e) { 172 if (updateThresholds) { 173 AddThresholds(); 174 updateThresholds = false; 175 } 176 } 177 168 178 private void AddThresholds() { 169 179 chart.Annotations.Clear(); 170 180 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; 171 188 foreach (double threshold in Content.Model.Thresholds) { 172 189 if (!double.IsInfinity(threshold)) { … … 176 193 annotation.LineWidth = 2; 177 194 annotation.LineColor = Color.Red; 178 179 195 annotation.IsInfinitive = true; 180 196 annotation.ClipToChartArea = chart.ChartAreas[0].Name; 181 197 annotation.Tag = classIndex; //save classIndex as Tag to avoid moving the threshold accross class bounderies 182 183 198 annotation.AxisX = chart.ChartAreas[0].AxisX; 184 annotation.AxisY = chart.ChartAreas[0].AxisY;199 annotation.AxisY = y; 185 200 annotation.Y = threshold; 186 201 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 187 226 chart.Annotations.Add(annotation); 227 chart.Annotations.Add(beneathLeft); 228 chart.Annotations.Add(aboveLeft); 229 chart.Annotations.Add(beneathRigth); 230 chart.Annotations.Add(aboveRight); 188 231 classIndex++; 189 232 } 190 233 } 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; 191 247 } 192 248 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.Designer.cs
r8689 r8863 21 21 22 22 #endregion 23 23 24 namespace HeuristicLab.Problems.DataAnalysis.Views { 24 25 partial class AbstractFeatureCorrelationView { … … 48 49 this.components = new System.ComponentModel.Container(); 49 50 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AbstractFeatureCorrelationView)); 50 this.DataGridView = new System.Windows.Forms.DataGridView();51 51 this.HeatMapProgressBar = new System.Windows.Forms.ProgressBar(); 52 52 this.PartitionComboBox = new System.Windows.Forms.ComboBox(); … … 60 60 this.CalculatingPanel = new System.Windows.Forms.Panel(); 61 61 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(); 65 63 ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).BeginInit(); 66 64 ((System.ComponentModel.ISupportInitialize)(this.SplitContainer)).BeginInit(); … … 69 67 this.SplitContainer.SuspendLayout(); 70 68 this.CalculatingPanel.SuspendLayout(); 71 this.contextMenu.SuspendLayout();72 69 this.SuspendLayout(); 73 //74 // DataGridView75 //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);91 70 // 92 71 // HeatMapProgressBar … … 162 141 // 163 142 this.PictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 164 143 | System.Windows.Forms.AnchorStyles.Right))); 165 144 this.PictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 166 145 this.PictureBox.Image = ((System.Drawing.Image)(resources.GetObject("PictureBox.Image"))); … … 175 154 // 176 155 this.SplitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 177 178 156 | System.Windows.Forms.AnchorStyles.Left) 157 | System.Windows.Forms.AnchorStyles.Right))); 179 158 this.SplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; 180 159 this.SplitContainer.IsSplitterFixed = true; … … 193 172 // 194 173 this.SplitContainer.Panel2.Controls.Add(this.CalculatingPanel); 195 this.SplitContainer.Panel2.Controls.Add(this. DataGridView);174 this.SplitContainer.Panel2.Controls.Add(this.dataView); 196 175 this.SplitContainer.Size = new System.Drawing.Size(475, 330); 197 176 this.SplitContainer.SplitterDistance = 25; … … 217 196 this.CalculatingLabel.Text = "Calculating correlation..."; 218 197 // 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; 232 206 // 233 207 // AbstractFeatureCorrelationView … … 241 215 this.Name = "AbstractFeatureCorrelationView"; 242 216 this.Size = new System.Drawing.Size(569, 336); 243 ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();244 217 ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).EndInit(); 245 218 this.SplitContainer.Panel1.ResumeLayout(false); … … 250 223 this.CalculatingPanel.ResumeLayout(false); 251 224 this.CalculatingPanel.PerformLayout(); 252 this.contextMenu.ResumeLayout(false);253 225 this.ResumeLayout(false); 254 226 … … 257 229 #endregion 258 230 259 protected System.Windows.Forms.DataGridView DataGridView;260 231 protected System.Windows.Forms.ProgressBar HeatMapProgressBar; 261 232 protected System.Windows.Forms.ComboBox PartitionComboBox; … … 269 240 protected System.Windows.Forms.Panel CalculatingPanel; 270 241 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; 273 243 274 244 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs
r8729 r8863 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using System.ComponentModel; 25 using System.Drawing;26 23 using System.Linq; 27 using System.Text;28 24 using System.Windows.Forms; 29 using HeuristicLab.Analysis; 30 using HeuristicLab.Common; 31 using HeuristicLab.Data.Views; 32 using HeuristicLab.DataAnalysis.Views; 25 using HeuristicLab.Data; 33 26 using HeuristicLab.MainForm; 34 27 using HeuristicLab.MainForm.WindowsForms; 28 using HeuristicLab.PluginInfrastructure; 35 29 36 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 38 32 [Content(typeof(DataAnalysisProblemData), false)] 39 33 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 46 34 protected FeatureCorrelationCalculator fcc; 47 protected HeatMapcurrentCorrelation;35 protected DoubleMatrix currentCorrelation; 48 36 49 37 public new DataAnalysisProblemData Content { … … 54 42 protected AbstractFeatureCorrelationView() { 55 43 InitializeComponent(); 56 sortedColumnIndices = new List<KeyValuePair<int, SortOrder>>();57 rowComparer = new StringConvertibleMatrixView.RowComparer();58 44 fcc = new FeatureCorrelationCalculator(); 59 var calculator List = 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.D ataSource = 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.D isplayMember = "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; 67 53 } 68 54 … … 81 67 protected override void OnContentChanged() { 82 68 base.OnContentChanged(); 69 fcc.TryCancelCalculation(); 83 70 if (Content != null) { 84 71 fcc.ProblemData = Content; 85 bool[] initialVisibility = SetInitialVisibilityOfColumns();86 87 variableVisibility = new VariableVisibilityDialog(Content.Dataset.DoubleVariables, initialVisibility);88 variableVisibility.VariableVisibilityChanged += new ItemCheckEventHandler(variableVisibility_VariableVisibilityChanged);89 72 CalculateCorrelation(); 90 73 } else { 91 DataGridView.Columns.Clear(); 92 DataGridView.Rows.Clear(); 74 dataView.Maximum = 0; 75 dataView.Minimum = 0; 76 dataView.Content = null; 77 dataView.ResetVisibility(); 93 78 } 94 79 } 95 80 96 protected virtual bool[] SetInitialV isibilityOfColumns() {81 protected virtual bool[] SetInitialVariableVisibility() { 97 82 bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()]; 98 83 int i = 0; … … 103 88 return initialVisibility; 104 89 } 105 106 protected abstract void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e);107 90 108 91 protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) { … … 116 99 protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e); 117 100 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(); 126 105 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; 155 111 } 156 112 … … 163 119 HeatMapProgressBar.Value = e.ProgressPercentage; 164 120 } 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 sort200 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 else219 sortedColumnIndices.RemoveAt(sortedIndex);220 } else221 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 #endregion257 258 #region copy259 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 names287 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 tab298 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 tab319 s.Append(Environment.NewLine);320 }321 Clipboard.SetText(s.ToString());322 }323 #endregion324 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 }347 121 } 348 122 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs
r8729 r8863 51 51 } 52 52 53 public void CalculateElements( FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitionspartition) {53 public void CalculateElements(IDependencyCalculator calc, string partition) { 54 54 CalculateElements(problemData.Dataset, calc, partition); 55 55 } 56 56 57 // returns if any calculation takes place58 public bool CalculateTimeframeElements( FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitionspartition, 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) { 59 59 if (correlation == null || correlation.GetLength(1) <= frames) { 60 60 CalculateElements(problemData.Dataset, calc, partition, variable, frames, correlation); … … 65 65 } 66 66 67 public void TryCancelCalculation() { 68 if (bw != null && bw.IsBusy) { 69 bwInfo = null; 70 bw.CancelAsync(); 71 } 72 } 73 67 74 private double[,] GetElementsOfCorrelation(double[,] corr, int frames) { 68 75 double[,] elements = new double[corr.GetLength(0), frames + 1]; … … 75 82 } 76 83 77 private void CalculateElements(Dataset dataset, FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitionspartition, 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) { 78 85 bwInfo = new BackgroundWorkerInfo { Dataset = dataset, Calculator = calc, Partition = partition, Variable = variable, Frames = frames, AlreadyCalculated = alreadyCalculated }; 79 86 if (bw == null) { … … 107 114 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument; 108 115 Dataset dataset = bwInfo.Dataset; 109 FeatureCorrelationEnums.Partitionspartition = bwInfo.Partition;110 FeatureCorrelationEnums.CorrelationCalculatorscalc = bwInfo.Calculator;116 string partition = bwInfo.Partition; 117 IDependencyCalculator calc = bwInfo.Calculator; 111 118 112 119 IList<string> doubleVariableNames = dataset.DoubleVariables.ToList(); … … 121 128 for (int j = 0; j < i + 1; j++) { 122 129 if (worker.CancellationPending) { 130 worker.ReportProgress(100); 123 131 e.Cancel = true; 124 132 return; … … 127 135 IEnumerable<double> var2 = GetRelevantValues(problemData, partition, doubleVariableNames[j]); 128 136 129 elements[i, j] = CalculateElementWithCalculator(calc,var1, var2, out error);137 elements[i, j] = calc.Calculate(var1, var2, out error); 130 138 131 139 if (!error.Equals(OnlineCalculatorError.None)) { … … 137 145 } 138 146 e.Result = elements; 147 worker.ReportProgress(100); 139 148 } 140 149 … … 144 153 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument; 145 154 Dataset dataset = bwInfo.Dataset; 146 FeatureCorrelationEnums.Partitionspartition = bwInfo.Partition;147 FeatureCorrelationEnums.CorrelationCalculatorscalc = bwInfo.Calculator;155 string partition = bwInfo.Partition; 156 IDependencyCalculator calc = bwInfo.Calculator; 148 157 string variable = bwInfo.Variable; 149 158 int frames = bwInfo.Frames; … … 169 178 for (int j = start; j <= frames; j++) { 170 179 if (worker.CancellationPending) { 180 worker.ReportProgress(100); 171 181 e.Cancel = true; 172 182 return; … … 181 191 var1 = help; 182 192 183 elements[i, j] = CalculateElementWithCalculator(calc,var1, var2, out error);193 elements[i, j] = calc.Calculate(var1, var2, out error); 184 194 185 195 if (!error.Equals(OnlineCalculatorError.None)) { … … 190 200 } 191 201 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) { 195 206 IEnumerable<double> var = problemData.Dataset.GetDoubleValues(variable); 196 if (partition.Equals(FeatureCorrelation Enums.Partitions.TrainingSamples)) {207 if (partition.Equals(FeatureCorrelationPartitions.TRAININGSAMPLES)) { 197 208 var = var.Skip(problemData.TrainingPartition.Start).Take(problemData.TrainingPartition.End - problemData.TrainingPartition.Start); 198 } else if (partition.Equals(FeatureCorrelation Enums.Partitions.TestSamples)) {209 } else if (partition.Equals(FeatureCorrelationPartitions.TESTSAMPLES)) { 199 210 var = var.Skip(problemData.TestPartition.Start).Take(problemData.TestPartition.End - problemData.TestPartition.Start); 200 211 } 201 212 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 }214 213 } 215 214 … … 222 221 OnCorrelationCalculationFinished((double[,])e.Result, bwInfo.Calculator, bwInfo.Partition, bwInfo.Variable); 223 222 } 224 } else {223 } else if (bwInfo != null) { 225 224 bw.RunWorkerAsync(bwInfo); 226 225 } … … 231 230 public class CorrelationCalculationFinishedArgs : EventArgs { 232 231 public double[,] Correlation { get; private set; } 233 public FeatureCorrelationEnums.CorrelationCalculatorsCalculcator { get; private set; }234 public FeatureCorrelationEnums.PartitionsPartition { get; private set; }232 public IDependencyCalculator Calculcator { get; private set; } 233 public string Partition { get; private set; } 235 234 public string Variable { get; private set; } 236 235 237 public CorrelationCalculationFinishedArgs(double[,] correlation, FeatureCorrelationEnums.CorrelationCalculators calculator, FeatureCorrelationEnums.Partitionspartition, string variable = null) {236 public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) { 238 237 this.Correlation = correlation; 239 238 this.Calculcator = calculator; … … 245 244 public delegate void CorrelationCalculationFinishedHandler(object sender, CorrelationCalculationFinishedArgs e); 246 245 public event CorrelationCalculationFinishedHandler CorrelationCalculationFinished; 247 protected virtual void OnCorrelationCalculationFinished(double[,] correlation, FeatureCorrelationEnums.CorrelationCalculators calculator, FeatureCorrelationEnums.Partitionspartition, string variable = null) {246 protected virtual void OnCorrelationCalculationFinished(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) { 248 247 var handler = CorrelationCalculationFinished; 249 248 if (handler != null) … … 255 254 protected void BwProgressChanged(object sender, ProgressChangedEventArgs e) { 256 255 BackgroundWorker worker = sender as BackgroundWorker; 257 if ( !worker.CancellationPending &&ProgressCalculation != null) {256 if (ProgressCalculation != null) { 258 257 ProgressCalculation(sender, e); 259 258 } … … 263 262 private class BackgroundWorkerInfo { 264 263 public Dataset Dataset { get; set; } 265 public FeatureCorrelationEnums.CorrelationCalculatorsCalculator { get; set; }266 public FeatureCorrelationEnums.PartitionsPartition { get; set; }264 public IDependencyCalculator Calculator { get; set; } 265 public string Partition { get; set; } 267 266 public string Variable { get; set; } 268 267 public int Frames { get; set; } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs
r8729 r8863 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Windows.Forms; 23 using HeuristicLab.Analysis;24 25 using HeuristicLab.Data; 25 26 using HeuristicLab.MainForm; 26 27 using HeuristicLab.MainForm.WindowsForms; 28 using HeuristicLab.PluginInfrastructure; 27 29 28 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 40 42 41 43 protected override void OnContentChanged() { 44 if (Content != null) { 45 dataView.RowVisibility = SetInitialVariableVisibility(); 46 dataView.ColumnVisibility = SetInitialVariableVisibility(); 47 } 42 48 correlationCache.Reset(); 43 49 base.OnContentChanged(); … … 46 52 protected override void CalculateCorrelation() { 47 53 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; 52 57 double[,] corr = correlationCache.GetCorrelation(calc, partition); 53 58 if (corr == null) { 54 59 fcc.CalculateElements(calc, partition); 55 60 } else { 56 SetNewCorrelation(corr, calc); 57 UpdateDataGrid(); 61 fcc.TryCancelCalculation(); 62 SetNewCorrelation(corr); 63 UpdateDataView(); 58 64 } 59 65 } 60 66 } 61 67 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); 68 72 } 69 73 … … 73 77 } else { 74 78 correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation); 75 SetNewCorrelation(e.Correlation , e.Calculcator);76 UpdateData Grid();79 SetNewCorrelation(e.Correlation); 80 UpdateDataView(); 77 81 } 78 82 } 79 83 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 } 83 112 } 84 113 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.Designer.cs
r8578 r8863 49 49 this.VariableSelectionComboBox = new System.Windows.Forms.ComboBox(); 50 50 this.TimeFrameLabel = new System.Windows.Forms.Label(); 51 this.Timeframe ComboBox = new System.Windows.Forms.ComboBox();51 this.TimeframeTextbox = new System.Windows.Forms.TextBox(); 52 52 ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).BeginInit(); 53 53 ((System.ComponentModel.ISupportInitialize)(this.SplitContainer)).BeginInit(); … … 78 78 // 79 79 this.SplitContainer.Panel1.Controls.Add(this.VariableSelectionComboBox); 80 this.SplitContainer.Panel1.Controls.Add(this.Timeframe ComboBox);80 this.SplitContainer.Panel1.Controls.Add(this.TimeframeTextbox); 81 81 this.SplitContainer.Panel1.Controls.Add(this.TimeFrameLabel); 82 82 this.SplitContainer.Panel1.Controls.Add(this.VariableSelectionLabel); … … 117 117 // TimeframeComboBox 118 118 // 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); 126 125 // 127 126 // TimeframeFeatureCorrelationView … … 146 145 protected System.Windows.Forms.ComboBox VariableSelectionComboBox; 147 146 protected System.Windows.Forms.Label TimeFrameLabel; 148 protected System.Windows.Forms. ComboBox TimeframeComboBox;147 protected System.Windows.Forms.TextBox TimeframeTextbox; 149 148 } 150 149 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs
r8729 r8863 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Windows.Forms; 25 using HeuristicLab.Analysis;26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.MainForm; 28 using HeuristicLab.PluginInfrastructure; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 36 37 public TimeframeFeatureCorrelationView() { 37 38 InitializeComponent(); 38 TimeframeComboBox.DataSource = Enumerable.Range(0, 16).ToList<int>();39 39 correlationTimeframCache = new FeatureCorrelationTimeframeCache(); 40 40 } … … 43 43 correlationTimeframCache.Reset(); 44 44 if (Content != null) { 45 dataView.RowVisibility = SetInitialVariableVisibility(); 45 46 VariableSelectionComboBox.DataSource = Content.Dataset.DoubleVariables.ToList(); 46 47 } … … 51 52 CalculateCorrelation(); 52 53 } 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 } 55 58 } 56 59 57 60 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; 65 69 double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable); 66 70 if (corr == null) { … … 69 73 fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr); 70 74 } else { 75 fcc.TryCancelCalculation(); 71 76 SetNewCorrelation(corr, calc, frames); 72 UpdateData Grid();77 UpdateDataView(); 73 78 } 74 79 } 75 80 } 76 81 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) { 78 98 double[,] neededValues = new double[elements.GetLength(0), frames + 1]; 79 99 for (int i = 0; i < elements.GetLength(0); i++) { 80 100 Array.Copy(elements, i * elements.GetLength(1), neededValues, i * neededValues.GetLength(1), frames + 1); 81 101 } 82 SetNewCorrelation(neededValues , calc);102 SetNewCorrelation(neededValues); 83 103 } 84 104 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); 91 109 } 92 110 … … 96 114 } else { 97 115 correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation); 98 SetNewCorrelation(e.Correlation , e.Calculcator);99 UpdateData Grid();116 SetNewCorrelation(e.Correlation); 117 UpdateDataView(); 100 118 } 101 119 } 102 120 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(); 106 128 } 107 }108 129 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 } 111 149 } 112 150 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r8814 r8863 227 227 <DependentUpon>DataAnalysisSolutionEvaluationView.cs</DependentUpon> 228 228 </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> 229 235 <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" /> 237 237 <Compile Include="FeatureCorrelation\FeatureCorrelationView.cs"> 238 238 <SubType>UserControl</SubType> … … 241 241 <DependentUpon>FeatureCorrelationView.cs</DependentUpon> 242 242 </Compile> 243 <Compile Include="FeatureCorrelation\FeatureCorrelationCache.cs" />244 <Compile Include="FeatureCorrelation\FeatureCorrelationTimeframeCache.cs" />245 243 <Compile Include="Plugin.cs" /> 246 244 <Compile Include="ProblemDataView.cs"> -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs
r8811 r8863 45 45 46 46 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)); 48 48 MainFormManager.MainForm.ShowContent(Content, viewType); 49 49 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionFeatureCorrelationView.cs
r8811 r8863 37 37 } 38 38 39 protected override bool[] SetInitialV isibilityOfColumns() {39 protected override bool[] SetInitialVariableVisibility() { 40 40 int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable); 41 var initialVisibility = base.SetInitialV isibilityOfColumns();41 var initialVisibility = base.SetInitialVariableVisibility(); 42 42 initialVisibility[i] = true; 43 43 return initialVisibility; -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionTimeframeFeatureCorrelationView.cs
r8811 r8863 37 37 } 38 38 39 protected override bool[] SetInitialV isibilityOfColumns() {39 protected override bool[] SetInitialVariableVisibility() { 40 40 int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable); 41 var initialVisibility = base.SetInitialV isibilityOfColumns();41 var initialVisibility = base.SetInitialVariableVisibility(); 42 42 initialVisibility[i] = true; 43 43 return initialVisibility; -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r8814 r8863 199 199 <Compile Include="Interfaces\Classification\IClassificationEnsembleSolutionWeightCalculator.cs" /> 200 200 <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" /> 201 <Compile Include="Interfaces\IDependencyCalculator.cs" /> 201 202 <Compile Include="Interfaces\Regression\IRegressionEnsembleModel.cs"> 202 203 <SubType>Code</SubType> … … 210 211 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" /> 211 212 <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" /> 212 217 <Compile Include="OnlineCalculators\OnlineBoundedMeanSquaredErrorCalculator.cs" /> 213 <Compile Include="OnlineCalculators\HoeffdingsDependenceCalculator.cs" />214 218 <Compile Include="OnlineCalculators\OnlineDirectionalSymmetryCalculator.cs" /> 215 219 <Compile Include="OnlineCalculators\OnlineMaxAbsoluteErrorCalculator.cs" /> … … 253 257 <Compile Include="OnlineCalculators\OnlineTheilsUStatisticCalculator.cs" /> 254 258 <Compile Include="OnlineCalculators\OnlineWeightedDirectionalSymmetryCalculator.cs" /> 255 <Compile Include="OnlineCalculators\SpearmansRankCorrelationCoefficientCalculator.cs" />256 259 <Compile Include="Plugin.cs" /> 257 260 <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" /> -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r8811 r8863 136 136 137 137 public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) { 138 return new DiscriminantFunctionClassificationSolution(this, problemData);138 return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData)); 139 139 } 140 140 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/ConstantTimeSeriesPrognosisModel.cs
r8458 r8863 44 44 45 45 public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) { 46 return new TimeSeriesPrognosisSolution(this, problemData);46 return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData)); 47 47 } 48 48 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r8487 r8863 109 109 110 110 public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) { 111 return new TimeSeriesPrognosisSolution(this, problemData);111 return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData)); 112 112 } 113 113 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs
r8486 r8863 1595 1595 } 1596 1596 1597 public TimeSeriesPrognosisProblemData(ITimeSeriesPrognosisProblemData timeseriesProblemData) 1598 : this(timeseriesProblemData.Dataset, timeseriesProblemData.AllowedInputVariables, timeseriesProblemData.TargetVariable) { 1599 1600 TestHorizon = timeseriesProblemData.TestHorizon; 1601 TrainingHorizon = timeseriesProblemData.TestHorizon; 1602 } 1603 1597 1604 [StorableHook(HookType.AfterDeserialization)] 1598 1605 private void AfterDeserialization() {
Note: See TracChangeset
for help on using the changeset viewer.