Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 9 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationCalculator.cs
r15674 r15973 26 26 using System.ComponentModel; 27 27 using System.Linq; 28 using HeuristicLab.MainForm; 28 29 using HeuristicLab.PluginInfrastructure; 29 30 … … 77 78 if (!e.Cancelled && !worker.CancellationPending) { 78 79 if (e.Error != null) { 79 ErrorHandling.ShowErrorDialog(e.Error);80 MainFormManager.MainForm.ShowError(e.Error.Message, e.Error); 80 81 } else { 81 82 OnCorrelationCalculationFinished((double[,])e.Result, bwInfo.Calculator, bwInfo.Partition, bwInfo.IgnoreMissingValues, bwInfo.Variable); -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.Designer.cs
r12012 r15973 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs
r12151 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 37 37 public const string TESTSAMPLES = "Test Samples"; 38 38 39 public static readonly IList<string> Partitions = new List<string>() { ALLSAMPLES, TRAININGSAMPLES, TESTSAMPLES } ;39 public static readonly IList<string> Partitions = new List<string>() { ALLSAMPLES, TRAININGSAMPLES, TESTSAMPLES }.AsReadOnly(); 40 40 41 protected FeatureCorrelationCalculator fcc;41 protected AbstractFeatureCorrelationCalculator CorrelationCalculator { get; set; } 42 42 43 43 public new DataAnalysisProblemData Content { … … 49 49 InitializeComponent(); 50 50 dataView.FormatPattern = "0.000"; 51 fcc = new FeatureCorrelationCalculator();52 51 var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>(); 53 52 var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList(); … … 55 54 correlationCalcComboBox.DisplayMember = "Name"; 56 55 correlationCalcComboBox.DataSource = calcList; 57 correlationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType() .Equals(typeof(PearsonsRDependenceCalculator)));56 correlationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType() == typeof(PearsonsRDependenceCalculator)); 58 57 partitionComboBox.DataSource = Partitions; 59 58 partitionComboBox.SelectedItem = TRAININGSAMPLES; … … 61 60 } 62 61 62 protected override void OnClosing(FormClosingEventArgs e) { 63 base.OnClosing(e); 64 CorrelationCalculator.TryCancelCalculation(); 65 } 66 63 67 protected override void RegisterContentEvents() { 64 68 base.RegisterContentEvents(); 65 fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);66 fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);69 CorrelationCalculator.ProgressChanged += FeatureCorrelation_ProgressChanged; 70 CorrelationCalculator.CorrelationCalculationFinished += FeatureCorrelation_CalculationFinished; 67 71 } 68 72 69 73 protected override void DeregisterContentEvents() { 70 fcc.CorrelationCalculationFinished -= new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);71 fcc.ProgressCalculation -= new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);74 CorrelationCalculator.ProgressChanged -= FeatureCorrelation_ProgressChanged; 75 CorrelationCalculator.CorrelationCalculationFinished -= FeatureCorrelation_CalculationFinished; 72 76 base.DeregisterContentEvents(); 73 77 } … … 75 79 protected override void OnContentChanged() { 76 80 base.OnContentChanged(); 77 fcc.TryCancelCalculation();81 CorrelationCalculator.TryCancelCalculation(); 78 82 if (Content != null) { 79 fcc.ProblemData = Content;80 83 CalculateCorrelation(); 81 84 } else { … … 106 109 107 110 protected abstract void CalculateCorrelation(); 108 protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e); 111 112 protected abstract void FeatureCorrelation_CalculationFinished(object sender, 113 AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e); 109 114 110 115 protected void UpdateDataView(DoubleMatrix correlation) { … … 121 126 } 122 127 123 protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {128 protected void FeatureCorrelation_ProgressChanged(object sender, ProgressChangedEventArgs e) { 124 129 if (!progressPanel.Visible && e.ProgressPercentage != progressBar.Maximum) { 125 130 progressPanel.Show(); -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs
r13338 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.ComponentModel; 25 25 using System.Linq; 26 using System.Threading.Tasks; 26 27 using HeuristicLab.MainForm; 27 28 using HeuristicLab.PluginInfrastructure; … … 29 30 namespace HeuristicLab.Problems.DataAnalysis.Views { 30 31 [NonDiscoverableType] 31 public class FeatureCorrelationCalculator : Object { 32 public sealed class FeatureCorrelationCalculator : AbstractFeatureCorrelationCalculator { 33 public FeatureCorrelationCalculator() : base() { } 32 34 33 private BackgroundWorker bw; 34 private BackgroundWorkerInfo bwInfo; 35 public void CalculateElements(IDataAnalysisProblemData problemData, IDependencyCalculator calc, string partition, bool ignoreMissingValues) { 36 var indices = GetRelevantIndices(problemData, partition); 37 var info = new BackgroundWorkerInfo { 38 Dataset = problemData.Dataset, Calculator = calc, Partition = partition, Indices = indices, IgnoreMissingValues = ignoreMissingValues 39 }; 35 40 36 private IDataAnalysisProblemData problemData; 37 public IDataAnalysisProblemData ProblemData { 38 set { 39 if (bw != null) { 40 bw.CancelAsync(); 41 } 42 problemData = value; 43 } 41 StartCalculation(info); 44 42 } 45 43 46 public FeatureCorrelationCalculator() 47 : base() { } 44 protected override void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { 45 BackgroundWorker worker = (BackgroundWorker)sender; 46 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument; 48 47 49 public FeatureCorrelationCalculator(IDataAnalysisProblemData problemData)50 : base() {51 this.problemData = problemData;52 }53 54 public void CalculateElements(IDependencyCalculator calc, string partition) {55 CalculateElements(problemData.Dataset, calc, partition);56 }57 58 // returns true if any calculation takes place59 public bool CalculateTimeframeElements(IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null) {60 if (correlation == null || correlation.GetLength(1) <= frames) {61 CalculateElements(problemData.Dataset, calc, partition, variable, frames, correlation);62 return true;63 } else {64 return false;65 }66 }67 68 public void TryCancelCalculation() {69 if (bw != null && bw.IsBusy) {70 bwInfo = null;71 bw.CancelAsync();72 }73 }74 75 private void CalculateElements(IDataset dataset, IDependencyCalculator calc, string partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null) {76 var indices = GetRelevantIndices(problemData, partition);77 bwInfo = new BackgroundWorkerInfo {78 Dataset = dataset, Calculator = calc, Partition = partition, Indices = indices,79 Variable = variable, Frames = frames, AlreadyCalculated = alreadyCalculated80 };81 if (bw == null) {82 bw = new BackgroundWorker();83 bw.WorkerReportsProgress = true;84 bw.WorkerSupportsCancellation = true;85 bw.DoWork += new DoWorkEventHandler(BwDoWork);86 bw.ProgressChanged += new ProgressChangedEventHandler(BwProgressChanged);87 bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BwRunWorkerCompleted);88 }89 if (bw.IsBusy) {90 bw.CancelAsync();91 } else {92 bw.RunWorkerAsync(bwInfo);93 }94 }95 96 private IEnumerable<int> GetRelevantIndices(IDataAnalysisProblemData problemData, string partition) {97 IEnumerable<int> var;98 if (partition.Equals(AbstractFeatureCorrelationView.TRAININGSAMPLES))99 var = problemData.TrainingIndices;100 else if (partition.Equals(AbstractFeatureCorrelationView.TESTSAMPLES))101 var = problemData.TestIndices;102 else var = Enumerable.Range(0, problemData.Dataset.Rows);103 return var;104 }105 106 #region backgroundworker107 private void BwDoWork(object sender, DoWorkEventArgs e) {108 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;109 if (bwInfo.Variable == null) {110 BwCalculateCorrelation(sender, e);111 } else {112 BwCalculateTimeframeCorrelation(sender, e);113 }114 }115 116 private void BwCalculateCorrelation(object sender, DoWorkEventArgs e) {117 BackgroundWorker worker = sender as BackgroundWorker;118 119 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;120 48 var dataset = bwInfo.Dataset; 121 IEnumerable<int> indices = bwInfo.Indices;49 var indices = bwInfo.Indices.ToArray(); 122 50 IDependencyCalculator calc = bwInfo.Calculator; 123 51 124 52 IList<string> doubleVariableNames = dataset.DoubleVariables.ToList(); 125 OnlineCalculatorError error = OnlineCalculatorError.None; 53 126 54 int length = doubleVariableNames.Count; 127 55 double[,] elements = new double[length, length]; 128 double calculations = (Math.Pow(length, 2) + length) / 2;129 56 130 57 worker.ReportProgress(0); 131 58 132 for (int i = 0; i < length; i++) { 133 for (int j = 0; j < i + 1; j++) { 134 if (worker.CancellationPending) { 135 worker.ReportProgress(100); 136 e.Cancel = true; 137 return; 138 } 139 IEnumerable<double> var1 = problemData.Dataset.GetDoubleValues(doubleVariableNames[i], indices); 140 IEnumerable<double> var2 = problemData.Dataset.GetDoubleValues(doubleVariableNames[j], indices); 59 for (int counter = 0; counter < length; counter++) { 60 if (worker.CancellationPending) { 61 worker.ReportProgress(100); 62 e.Cancel = true; 63 return; 64 } 141 65 142 elements[i, j] = calc.Calculate(var1, var2, out error); 66 var i = counter; 67 Parallel.ForEach(Enumerable.Range(i, length - i), j => { 68 var var1 = dataset.GetDoubleValues(doubleVariableNames[i], indices); 69 var var2 = dataset.GetDoubleValues(doubleVariableNames[j], indices); 70 71 OnlineCalculatorError error = OnlineCalculatorError.None; 72 if (bwInfo.IgnoreMissingValues) { 73 var filtered = FilterNaNValues(var1, var2); 74 elements[i, j] = calc.Calculate(filtered, out error); 75 } else 76 elements[i, j] = calc.Calculate(var1, var2, out error); 143 77 144 78 if (!error.Equals(OnlineCalculatorError.None)) { … … 146 80 } 147 81 elements[j, i] = elements[i, j]; 148 worker.ReportProgress((int)Math.Round((((Math.Pow(i, 2) + i) / 2 + j + 1.0) / calculations) * 100));149 }82 }); 83 worker.ReportProgress((int)(((double)counter) / length * 100)); 150 84 } 85 151 86 e.Result = elements; 152 87 worker.ReportProgress(100); 153 88 } 154 89 155 private void BwCalculateTimeframeCorrelation(object sender, DoWorkEventArgs e) {156 BackgroundWorker worker = sender as BackgroundWorker;157 90 158 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument; 159 var dataset = bwInfo.Dataset; 160 IEnumerable<int> indices = bwInfo.Indices; 161 IDependencyCalculator calc = bwInfo.Calculator; 162 string variable = bwInfo.Variable; 163 int frames = bwInfo.Frames; 164 double[,] alreadyCalculated = bwInfo.AlreadyCalculated; 91 private static IEnumerable<Tuple<double, double>> FilterNaNValues(IEnumerable<double> first, IEnumerable<double> second) { 92 var firstEnumerator = first.GetEnumerator(); 93 var secondEnumerator = second.GetEnumerator(); 165 94 166 IList<string> doubleVariableNames = dataset.DoubleVariables.ToList(); 167 OnlineCalculatorError error = OnlineCalculatorError.None; 168 int length = doubleVariableNames.Count; 169 double[,] elements = new double[length, frames + 1]; 170 double calculations = (frames + 1) * length; 95 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 96 var firstValue = firstEnumerator.Current; 97 var secondValue = secondEnumerator.Current; 171 98 172 worker.ReportProgress(0); 99 if (double.IsNaN(firstValue)) continue; 100 if (double.IsNaN(secondValue)) continue; 173 101 174 int start = 0; 175 if (alreadyCalculated != null) { 176 for (int i = 0; i < alreadyCalculated.GetLength(0); i++) { 177 Array.Copy(alreadyCalculated, i * alreadyCalculated.GetLength(1), elements, i * elements.GetLength(1), alreadyCalculated.GetLength(1)); 178 } 179 start = alreadyCalculated.GetLength(1); 102 yield return Tuple.Create(firstValue, secondValue); 180 103 } 181 104 182 for (int i = 0; i < length; i++) { 183 for (int j = start; j <= frames; j++) { 184 if (worker.CancellationPending) { 185 worker.ReportProgress(100); 186 e.Cancel = true; 187 return; 188 } 189 190 IEnumerable<double> var1 = problemData.Dataset.GetDoubleValues(variable, indices); 191 IEnumerable<double> var2 = problemData.Dataset.GetDoubleValues(doubleVariableNames[i], indices); 192 193 var valuesInFrame = var1.Take(j); 194 var help = var1.Skip(j).ToList(); 195 help.AddRange(valuesInFrame); 196 var1 = help; 197 198 elements[i, j] = calc.Calculate(var1, var2, out error); 199 200 if (!error.Equals(OnlineCalculatorError.None)) { 201 elements[i, j] = double.NaN; 202 } 203 worker.ReportProgress((int)((100.0 / calculations) * (i * (frames + 1) + j + 1))); 204 } 105 if (firstEnumerator.MoveNext() || secondEnumerator.MoveNext()) { 106 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 205 107 } 206 e.Result = elements;207 worker.ReportProgress(100);208 }209 210 private void BwRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {211 BackgroundWorker worker = sender as BackgroundWorker;212 if (!e.Cancelled && !worker.CancellationPending) {213 if (e.Error != null) {214 MainFormManager.MainForm.ShowError(e.Error.Message, e.Error);215 } else {216 OnCorrelationCalculationFinished((double[,])e.Result, bwInfo.Calculator, bwInfo.Partition, bwInfo.Variable);217 }218 } else if (bwInfo != null) {219 bw.RunWorkerAsync(bwInfo);220 }221 }222 #endregion223 224 #region events225 public class CorrelationCalculationFinishedArgs : EventArgs {226 public double[,] Correlation { get; private set; }227 public IDependencyCalculator Calculcator { get; private set; }228 public string Partition { get; private set; }229 public string Variable { get; private set; }230 231 public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {232 this.Correlation = correlation;233 this.Calculcator = calculator;234 this.Partition = partition;235 this.Variable = variable;236 }237 }238 239 public delegate void CorrelationCalculationFinishedHandler(object sender, CorrelationCalculationFinishedArgs e);240 public event CorrelationCalculationFinishedHandler CorrelationCalculationFinished;241 protected virtual void OnCorrelationCalculationFinished(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {242 var handler = CorrelationCalculationFinished;243 if (handler != null)244 handler(this, new CorrelationCalculationFinishedArgs(correlation, calculator, partition, variable));245 }246 247 public delegate void ProgressCalculationHandler(object sender, ProgressChangedEventArgs e);248 public event ProgressCalculationHandler ProgressCalculation;249 protected void BwProgressChanged(object sender, ProgressChangedEventArgs e) {250 BackgroundWorker worker = sender as BackgroundWorker;251 if (ProgressCalculation != null) {252 ProgressCalculation(sender, e);253 }254 }255 #endregion256 257 private class BackgroundWorkerInfo {258 public IDataset Dataset { get; set; }259 public IDependencyCalculator Calculator { get; set; }260 public string Partition { get; set; }261 public IEnumerable<int> Indices { get; set; }262 public string Variable { get; set; }263 public int Frames { get; set; }264 public double[,] AlreadyCalculated { get; set; }265 108 } 266 109 } -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.Designer.cs
r12012 r15973 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. … … 47 47 /// </summary> 48 48 private void InitializeComponent() { 49 this.ignoreMissingValuesCheckbox = new System.Windows.Forms.CheckBox(); 50 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); 51 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 52 this.splitContainer.Panel1.SuspendLayout(); 53 this.splitContainer.Panel2.SuspendLayout(); 54 this.splitContainer.SuspendLayout(); 55 this.progressPanel.SuspendLayout(); 49 56 this.SuspendLayout(); 57 // 58 // minimumLabel 59 // 60 this.minimumLabel.Location = new System.Drawing.Point(707, 434); 61 // 62 // maximumLabel 63 // 64 this.maximumLabel.Location = new System.Drawing.Point(707, 2); 65 // 66 // pictureBox 67 // 68 this.pictureBox.Location = new System.Drawing.Point(727, 30); 69 this.pictureBox.Size = new System.Drawing.Size(35, 401); 70 // 71 // splitContainer 72 // 73 // 74 // splitContainer.Panel1 75 // 76 this.splitContainer.Panel1.Controls.Add(this.ignoreMissingValuesCheckbox); 77 this.splitContainer.Size = new System.Drawing.Size(695, 450); 78 // 79 // dataView 80 // 81 this.dataView.Size = new System.Drawing.Size(695, 421); 82 // 83 // ignoreMissingValuesCheckbox 84 // 85 this.ignoreMissingValuesCheckbox.AutoSize = true; 86 this.ignoreMissingValuesCheckbox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; 87 this.ignoreMissingValuesCheckbox.Location = new System.Drawing.Point(481, 6); 88 this.ignoreMissingValuesCheckbox.Name = "ignoreMissingValuesCheckbox"; 89 this.ignoreMissingValuesCheckbox.Size = new System.Drawing.Size(122, 17); 90 this.ignoreMissingValuesCheckbox.TabIndex = 11; 91 this.ignoreMissingValuesCheckbox.Text = "Ignore missing values"; 92 this.ignoreMissingValuesCheckbox.UseVisualStyleBackColor = true; 93 this.ignoreMissingValuesCheckbox.CheckedChanged += new System.EventHandler(this.ignoreMissingValuesCheckbox_CheckedChanged); 50 94 // 51 95 // FeatureCorrelationView … … 54 98 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 55 99 this.Name = "FeatureCorrelationView"; 56 this.Size = new System.Drawing.Size(569, 336); 100 this.Size = new System.Drawing.Size(789, 456); 101 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); 102 this.splitContainer.Panel1.ResumeLayout(false); 103 this.splitContainer.Panel1.PerformLayout(); 104 this.splitContainer.Panel2.ResumeLayout(false); 105 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 106 this.splitContainer.ResumeLayout(false); 107 this.progressPanel.ResumeLayout(false); 108 this.progressPanel.PerformLayout(); 57 109 this.ResumeLayout(false); 110 58 111 } 59 112 #endregion 113 114 private System.Windows.Forms.CheckBox ignoreMissingValuesCheckbox; 60 115 } 61 116 } -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs
r12012 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 34 34 35 35 private FeatureCorrelationCache correlationCache; 36 private new FeatureCorrelationCalculator CorrelationCalculator { 37 get { return (FeatureCorrelationCalculator)base.CorrelationCalculator; } 38 set { base.CorrelationCalculator = value; } 39 } 36 40 37 41 public FeatureCorrelationView() 38 42 : base() { 39 43 InitializeComponent(); 44 CorrelationCalculator = new FeatureCorrelationCalculator(); 40 45 correlationCache = new FeatureCorrelationCache(); 41 46 } … … 49 54 } 50 55 56 private void ignoreMissingValuesCheckbox_CheckedChanged(object sender, EventArgs e) { 57 CalculateCorrelation(); 58 } 59 51 60 protected override void CalculateCorrelation() { 52 61 if (correlationCalcComboBox.SelectedItem == null) return; … … 56 65 string partition = (string)partitionComboBox.SelectedValue; 57 66 dataView.Enabled = false; 58 double[,] corr = correlationCache.GetCorrelation(calc, partition );67 double[,] corr = correlationCache.GetCorrelation(calc, partition, ignoreMissingValuesCheckbox.Checked); 59 68 if (corr == null) { 60 fcc.CalculateElements(calc, partition);69 CorrelationCalculator.CalculateElements(Content, calc, partition, ignoreMissingValuesCheckbox.Checked); 61 70 } else { 62 fcc.TryCancelCalculation();71 CorrelationCalculator.TryCancelCalculation(); 63 72 var correlation = new DoubleMatrix(corr, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables); 64 73 UpdateDataView(correlation); … … 66 75 } 67 76 68 69 70 protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) { 77 protected override void FeatureCorrelation_CalculationFinished(object sender, AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) { 71 78 if (InvokeRequired) { 72 Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);79 Invoke(new AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(FeatureCorrelation_CalculationFinished), sender, e); 73 80 return; 74 81 } 75 correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation); 82 correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.IgnoreMissingValues, e.Correlation); 83 76 84 var correlation = new DoubleMatrix(e.Correlation, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables); 77 85 UpdateDataView(correlation); … … 80 88 [NonDiscoverableType] 81 89 private class FeatureCorrelationCache : Object { 82 private Dictionary<Tuple<IDependencyCalculator, string >, double[,]> correlationsCache;90 private Dictionary<Tuple<IDependencyCalculator, string, bool>, double[,]> correlationsCache; 83 91 84 92 public FeatureCorrelationCache() … … 88 96 89 97 private void InitializeCaches() { 90 correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string >, double[,]>();98 correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string, bool>, double[,]>(); 91 99 } 92 100 … … 95 103 } 96 104 97 public double[,] GetCorrelation(IDependencyCalculator calc, string partition ) {105 public double[,] GetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues) { 98 106 double[,] corr; 99 var key = new Tuple<IDependencyCalculator, string>(calc, partition);107 var key = Tuple.Create(calc, partition, ignoreMissingValues); 100 108 correlationsCache.TryGetValue(key, out corr); 101 109 return corr; 102 110 } 103 111 104 public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {105 var key = new Tuple<IDependencyCalculator, string>(calc, partition);112 public void SetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues, double[,] correlation) { 113 var key = Tuple.Create(calc, partition, ignoreMissingValues); 106 114 correlationsCache[key] = correlation; 107 115 } -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.Designer.cs
r12012 r15973 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs
r12012 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 36 36 private string lastFramesValue; 37 37 38 private new TimeframeFeatureCorrelationCalculator CorrelationCalculator { 39 get { return (TimeframeFeatureCorrelationCalculator)base.CorrelationCalculator; } 40 set { base.CorrelationCalculator = value; } 41 } 42 43 38 44 public TimeframeFeatureCorrelationView() { 39 45 InitializeComponent(); 46 CorrelationCalculator = new TimeframeFeatureCorrelationCalculator(); 40 47 correlationTimeframCache = new FeatureCorrelationTimeframeCache(); 41 48 errorProvider.SetIconAlignment(timeframeTextbox, ErrorIconAlignment.MiddleRight); … … 93 100 94 101 protected override void CalculateCorrelation() { 95 if (correlationCalcComboBox.SelectedItem != null && partitionComboBox.SelectedItem != null 96 && variableSelectionComboBox.SelectedItem != null) { 97 string variable = (string)variableSelectionComboBox.SelectedItem; 98 IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue; 99 string partition = (string)partitionComboBox.SelectedValue; 100 int frames; 101 int.TryParse(timeframeTextbox.Text, out frames); 102 dataView.Enabled = false; 103 double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable); 104 if (corr == null) { 105 fcc.CalculateTimeframeElements(calc, partition, variable, frames); 106 } else if (corr.GetLength(1) <= frames) { 107 fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr); 108 } else { 109 fcc.TryCancelCalculation(); 110 var columnNames = Enumerable.Range(0, corr.GetLength(1)).Select(x => x.ToString()); 111 var correlation = new DoubleMatrix(corr, columnNames, Content.Dataset.DoubleVariables); 112 ((IStringConvertibleMatrix)correlation).Columns = frames + 1; 113 UpdateDataView(correlation); 114 } 102 if (correlationCalcComboBox.SelectedItem == null) return; 103 if (partitionComboBox.SelectedItem == null) return; 104 if (variableSelectionComboBox.SelectedItem == null) return; 105 106 string variable = (string)variableSelectionComboBox.SelectedItem; 107 IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue; 108 string partition = (string)partitionComboBox.SelectedValue; 109 int frames; 110 int.TryParse(timeframeTextbox.Text, out frames); 111 dataView.Enabled = false; 112 double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable); 113 if (corr == null) { 114 CorrelationCalculator.CalculateTimeframeElements(Content, calc, partition, variable, frames); 115 } else if (corr.GetLength(1) <= frames) { 116 CorrelationCalculator.CalculateTimeframeElements(Content, calc, partition, variable, frames, corr); 117 } else { 118 CorrelationCalculator.TryCancelCalculation(); 119 var columnNames = Enumerable.Range(0, corr.GetLength(1)).Select(x => x.ToString()); 120 var correlation = new DoubleMatrix(corr, columnNames, Content.Dataset.DoubleVariables); 121 ((IStringConvertibleMatrix)correlation).Columns = frames + 1; 122 UpdateDataView(correlation); 115 123 } 116 124 } 117 125 118 protected override void Content_CorrelationCalculationFinished(object sender,FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {126 protected override void FeatureCorrelation_CalculationFinished(object sender, AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) { 119 127 if (InvokeRequired) { 120 Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);128 Invoke(new AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(FeatureCorrelation_CalculationFinished), sender, e); 121 129 } else { 122 130 correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation);
Note: See TracChangeset
for help on using the changeset viewer.