Changeset 10908 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/PreprocessingFeatureCorrelationView.cs
- Timestamp:
- 05/28/14 15:09:26 (10 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/PreprocessingFeatureCorrelationView.cs
r10870 r10908 28 28 using HeuristicLab.MainForm.WindowsForms; 29 29 using HeuristicLab.PluginInfrastructure; 30 using System; 31 using HeuristicLab.DataPreprocessing; 30 32 31 33 namespace HeuristicLab.Problems.DataAnalysis.Views { 32 [View(" Feature Correlation View")]33 [Content(typeof( DataAnalysisProblemData), false)]34 public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView {34 [View("Preprocessing Feature Correlation View")] 35 [Content(typeof(CorrelationMatrixContent), false)] 36 public partial class PreprocessingFeatureCorrelationView : AsynchronousContentView { 35 37 public const string ALLSAMPLES = "All Samples"; 36 38 public const string TRAININGSAMPLES = "Training Samples"; … … 41 43 protected FeatureCorrelationCalculator fcc; 42 44 43 public new DataAnalysisProblemData Content { 44 get { return (DataAnalysisProblemData)base.Content; } 45 public new CorrelationMatrixContent Content 46 { 47 get { return (CorrelationMatrixContent) base.Content; } 45 48 set { base.Content = value; } 46 49 } 47 50 48 protected AbstractFeatureCorrelationView() { 51 private FeatureCorrelationCache correlationCache; 52 53 public PreprocessingFeatureCorrelationView() { 54 55 correlationCache = new FeatureCorrelationCache(); 49 56 InitializeComponent(); 50 57 fcc = new FeatureCorrelationCalculator(); … … 75 82 fcc.TryCancelCalculation(); 76 83 if (Content != null) { 77 fcc.ProblemData = Content ;84 fcc.ProblemData = Content.ProblemData; 78 85 CalculateCorrelation(); 79 86 } else { … … 86 93 87 94 protected virtual bool[] SetInitialVariableVisibility() { 88 bool[] initialVisibility = new bool[Content. Dataset.DoubleVariables.Count()];95 bool[] initialVisibility = new bool[Content.ProblemData.Dataset.DoubleVariables.Count()]; 89 96 int i = 0; 90 foreach (var variable in Content. Dataset.DoubleVariables) {91 initialVisibility[i] = Content. AllowedInputVariables.Contains(variable);97 foreach (var variable in Content.ProblemData.Dataset.DoubleVariables) { 98 initialVisibility[i] = Content.ProblemData.AllowedInputVariables.Contains(variable); 92 99 i++; 93 100 } … … 102 109 } 103 110 104 protected abstract void CalculateCorrelation(); 105 protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e); 111 protected void CalculateCorrelation() { 112 if (correlationCalcComboBox.SelectedItem == null) return; 113 if (partitionComboBox.SelectedItem == null) return; 114 115 IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue; 116 string partition = (string)partitionComboBox.SelectedValue; 117 dataView.Enabled = false; 118 double[,] corr = correlationCache.GetCorrelation(calc, partition); 119 if (corr == null) { 120 fcc.CalculateElements(calc, partition); 121 } else { 122 fcc.TryCancelCalculation(); 123 var correlation = new DoubleMatrix(corr, Content.ProblemData.Dataset.DoubleVariables, Content.ProblemData.Dataset.DoubleVariables); 124 UpdateDataView(correlation); 125 } 126 } 127 128 protected void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) { 129 if (InvokeRequired) { 130 Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e); 131 return; 132 } 133 correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation); 134 var correlation = new DoubleMatrix(e.Correlation, Content.ProblemData.Dataset.DoubleVariables, Content.ProblemData.Dataset.DoubleVariables); 135 UpdateDataView(correlation); 136 } 106 137 107 138 protected void UpdateDataView(DoubleMatrix correlation) { … … 125 156 progressBar.Value = e.ProgressPercentage; 126 157 } 158 159 [NonDiscoverableType] 160 private class FeatureCorrelationCache : Object { 161 private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache; 162 163 public FeatureCorrelationCache() 164 : base() { 165 InitializeCaches(); 166 } 167 168 private void InitializeCaches() { 169 correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>(); 170 } 171 172 public void Reset() { 173 InitializeCaches(); 174 } 175 176 public double[,] GetCorrelation(IDependencyCalculator calc, string partition) { 177 double[,] corr; 178 var key = new Tuple<IDependencyCalculator, string>(calc, partition); 179 correlationsCache.TryGetValue(key, out corr); 180 return corr; 181 } 182 183 public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) { 184 var key = new Tuple<IDependencyCalculator, string>(calc, partition); 185 correlationsCache[key] = correlation; 186 } 187 } 127 188 } 128 189 }
Note: See TracChangeset
for help on using the changeset viewer.