- Timestamp:
- 06/11/14 12:36:39 (10 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingFeatureCorrelationView.Designer.cs
r10908 r10978 47 47 /// </summary> 48 48 private void InitializeComponent() { 49 this.components = new System.ComponentModel.Container(); 50 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AbstractFeatureCorrelationView)); 51 this.progressBar = new System.Windows.Forms.ProgressBar(); 52 this.partitionComboBox = new System.Windows.Forms.ComboBox(); 53 this.correlationCalcLabel = new System.Windows.Forms.Label(); 54 this.correlationCalcComboBox = new System.Windows.Forms.ComboBox(); 55 this.partitionLabel = new System.Windows.Forms.Label(); 56 this.minimumLabel = new System.Windows.Forms.Label(); 57 this.maximumLabel = new System.Windows.Forms.Label(); 58 this.pictureBox = new System.Windows.Forms.PictureBox(); 59 this.splitContainer = new System.Windows.Forms.SplitContainer(); 60 this.progressPanel = new System.Windows.Forms.Panel(); 61 this.progressLabel = new System.Windows.Forms.Label(); 62 this.dataView = new HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView(); 63 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); 64 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 65 this.splitContainer.Panel1.SuspendLayout(); 66 this.splitContainer.Panel2.SuspendLayout(); 67 this.splitContainer.SuspendLayout(); 68 this.progressPanel.SuspendLayout(); 69 this.SuspendLayout(); 70 // 71 // HeatMapProgressBar 72 // 73 this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); 74 this.progressBar.Location = new System.Drawing.Point(25, 46); 75 this.progressBar.Name = "HeatMapProgressBar"; 76 this.progressBar.RightToLeft = System.Windows.Forms.RightToLeft.No; 77 this.progressBar.Size = new System.Drawing.Size(154, 21); 78 this.progressBar.TabIndex = 9; 79 // 80 // PartitionComboBox 81 // 82 this.partitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 83 this.partitionComboBox.FormattingEnabled = true; 84 this.partitionComboBox.Location = new System.Drawing.Point(333, 3); 85 this.partitionComboBox.Name = "PartitionComboBox"; 86 this.partitionComboBox.Size = new System.Drawing.Size(142, 21); 87 this.partitionComboBox.TabIndex = 8; 88 this.partitionComboBox.SelectionChangeCommitted += new System.EventHandler(this.PartitionComboBox_SelectedChangeCommitted); 89 // 90 // CorrelationCalcLabel 91 // 92 this.correlationCalcLabel.AutoSize = true; 93 this.correlationCalcLabel.Location = new System.Drawing.Point(0, 6); 94 this.correlationCalcLabel.Name = "CorrelationCalcLabel"; 95 this.correlationCalcLabel.Size = new System.Drawing.Size(104, 13); 96 this.correlationCalcLabel.TabIndex = 7; 97 this.correlationCalcLabel.Text = "Correlation Measure:"; 98 // 99 // CorrelationCalcComboBox 100 // 101 this.correlationCalcComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 102 this.correlationCalcComboBox.FormattingEnabled = true; 103 this.correlationCalcComboBox.Location = new System.Drawing.Point(110, 3); 104 this.correlationCalcComboBox.Name = "CorrelationCalcComboBox"; 105 this.correlationCalcComboBox.Size = new System.Drawing.Size(163, 21); 106 this.correlationCalcComboBox.TabIndex = 6; 107 this.correlationCalcComboBox.SelectionChangeCommitted += new System.EventHandler(this.CorrelationMeasureComboBox_SelectedChangeCommitted); 108 // 109 // PartitionLabel 110 // 111 this.partitionLabel.AutoSize = true; 112 this.partitionLabel.Location = new System.Drawing.Point(279, 6); 113 this.partitionLabel.Name = "PartitionLabel"; 114 this.partitionLabel.Size = new System.Drawing.Size(48, 13); 115 this.partitionLabel.TabIndex = 10; 116 this.partitionLabel.Text = "Partition:"; 117 // 118 // minimumLabel 119 // 120 this.minimumLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 121 this.minimumLabel.BackColor = System.Drawing.Color.Transparent; 122 this.minimumLabel.Location = new System.Drawing.Point(487, 314); 123 this.minimumLabel.Name = "minimumLabel"; 124 this.minimumLabel.Size = new System.Drawing.Size(73, 19); 125 this.minimumLabel.TabIndex = 13; 126 this.minimumLabel.Text = "0.0"; 127 this.minimumLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; 128 // 129 // maximumLabel 130 // 131 this.maximumLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 132 this.maximumLabel.BackColor = System.Drawing.Color.Transparent; 133 this.maximumLabel.Location = new System.Drawing.Point(487, 2); 134 this.maximumLabel.Name = "maximumLabel"; 135 this.maximumLabel.Size = new System.Drawing.Size(73, 25); 136 this.maximumLabel.TabIndex = 12; 137 this.maximumLabel.Text = "1.0"; 138 this.maximumLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter; 139 // 140 // PictureBox 141 // 142 this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 143 | System.Windows.Forms.AnchorStyles.Right))); 144 this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 145 this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("PictureBox.Image"))); 146 this.pictureBox.Location = new System.Drawing.Point(507, 30); 147 this.pictureBox.Name = "PictureBox"; 148 this.pictureBox.Size = new System.Drawing.Size(35, 281); 149 this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 150 this.pictureBox.TabIndex = 15; 151 this.pictureBox.TabStop = false; 152 // 153 // SplitContainer 154 // 155 this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 156 | System.Windows.Forms.AnchorStyles.Left) 157 | System.Windows.Forms.AnchorStyles.Right))); 158 this.splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; 159 this.splitContainer.IsSplitterFixed = true; 160 this.splitContainer.Location = new System.Drawing.Point(3, 3); 161 this.splitContainer.Name = "SplitContainer"; 162 this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal; 163 // 164 // SplitContainer.Panel1 165 // 166 this.splitContainer.Panel1.Controls.Add(this.correlationCalcLabel); 167 this.splitContainer.Panel1.Controls.Add(this.correlationCalcComboBox); 168 this.splitContainer.Panel1.Controls.Add(this.partitionComboBox); 169 this.splitContainer.Panel1.Controls.Add(this.partitionLabel); 170 // 171 // SplitContainer.Panel2 172 // 173 this.splitContainer.Panel2.Controls.Add(this.progressPanel); 174 this.splitContainer.Panel2.Controls.Add(this.dataView); 175 this.splitContainer.Size = new System.Drawing.Size(475, 330); 176 this.splitContainer.SplitterDistance = 25; 177 this.splitContainer.TabIndex = 16; 178 // 179 // CalculatingPanel 180 // 181 this.progressPanel.Anchor = System.Windows.Forms.AnchorStyles.None; 182 this.progressPanel.Controls.Add(this.progressLabel); 183 this.progressPanel.Controls.Add(this.progressBar); 184 this.progressPanel.Location = new System.Drawing.Point(138, 95); 185 this.progressPanel.Name = "CalculatingPanel"; 186 this.progressPanel.Size = new System.Drawing.Size(200, 81); 187 this.progressPanel.TabIndex = 10; 188 // 189 // CalculatingLabel 190 // 191 this.progressLabel.AutoSize = true; 192 this.progressLabel.Location = new System.Drawing.Point(42, 19); 193 this.progressLabel.Name = "CalculatingLabel"; 194 this.progressLabel.Size = new System.Drawing.Size(120, 13); 195 this.progressLabel.TabIndex = 10; 196 this.progressLabel.Text = "Calculating correlation..."; 197 // 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; 206 // 207 // AbstractFeatureCorrelationView 208 // 209 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 210 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 211 this.Controls.Add(this.splitContainer); 212 this.Controls.Add(this.minimumLabel); 213 this.Controls.Add(this.pictureBox); 214 this.Controls.Add(this.maximumLabel); 215 this.Name = "AbstractFeatureCorrelationView"; 216 this.Size = new System.Drawing.Size(569, 336); 217 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); 218 this.splitContainer.Panel1.ResumeLayout(false); 219 this.splitContainer.Panel1.PerformLayout(); 220 this.splitContainer.Panel2.ResumeLayout(false); 221 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 222 this.splitContainer.ResumeLayout(false); 223 this.progressPanel.ResumeLayout(false); 224 this.progressPanel.PerformLayout(); 49 this.components = new System.ComponentModel.Container(); 225 50 this.ResumeLayout(false); 226 227 51 } 228 52 229 53 #endregion 230 231 protected System.Windows.Forms.ProgressBar progressBar;232 protected System.Windows.Forms.ComboBox partitionComboBox;233 protected System.Windows.Forms.Label correlationCalcLabel;234 protected System.Windows.Forms.ComboBox correlationCalcComboBox;235 protected System.Windows.Forms.Label partitionLabel;236 protected System.Windows.Forms.Label minimumLabel;237 protected System.Windows.Forms.Label maximumLabel;238 protected System.Windows.Forms.PictureBox pictureBox;239 protected System.Windows.Forms.SplitContainer splitContainer;240 protected System.Windows.Forms.Panel progressPanel;241 protected System.Windows.Forms.Label progressLabel;242 protected HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView dataView;243 244 54 } 245 55 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingFeatureCorrelationView.cs
r10934 r10978 30 30 using System; 31 31 using HeuristicLab.DataPreprocessing; 32 using HeuristicLab.Problems.DataAnalysis.Views; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 35 36 [Content(typeof(CorrelationMatrixContent), false)] 36 37 public partial class PreprocessingFeatureCorrelationView : AsynchronousContentView { 37 public const string ALLSAMPLES = "All Samples";38 public const string TRAININGSAMPLES = "Training Samples";39 public const string TESTSAMPLES = "Test Samples";40 41 public static readonly IList<string> Partitions = new List<string>() { ALLSAMPLES, TRAININGSAMPLES, TESTSAMPLES };42 43 protected FeatureCorrelationCalculator fcc;44 38 45 39 public new CorrelationMatrixContent Content … … 49 43 } 50 44 51 private FeatureCorrelationCache correlationCache;45 FeatureCorrelationView correlationView; 52 46 53 47 public PreprocessingFeatureCorrelationView() { 54 55 correlationCache = new FeatureCorrelationCache();56 48 InitializeComponent(); 57 fcc = new FeatureCorrelationCalculator(); 58 var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>(); 59 var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList(); 60 correlationCalcComboBox.ValueMember = "Calculator"; 61 correlationCalcComboBox.DisplayMember = "Name"; 62 correlationCalcComboBox.DataSource = calcList; 63 correlationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator))); 64 partitionComboBox.DataSource = Partitions; 65 partitionComboBox.SelectedItem = TRAININGSAMPLES; 49 correlationView = new FeatureCorrelationView(); 50 correlationView.Dock = DockStyle.Fill; 51 this.Controls.Add(correlationView); 66 52 } 67 53 … … 69 55 protected override void RegisterContentEvents() { 70 56 base.RegisterContentEvents(); 71 Content.PreprocessingData.Changed += Data_Changed; 72 fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation); 73 fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished); 57 Content.Changed += Data_Changed; 74 58 } 75 59 76 60 protected override void DeregisterContentEvents() { 77 Content.PreprocessingData.Changed -= Data_Changed; 78 fcc.CorrelationCalculationFinished -= new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished); 79 fcc.ProgressCalculation -= new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation); 61 Content.Changed -= Data_Changed; 80 62 base.DeregisterContentEvents(); 81 63 } … … 87 69 protected override void OnContentChanged() { 88 70 base.OnContentChanged(); 89 fcc.TryCancelCalculation(); 90 if (Content != null) { 91 fcc.ProblemData = Content.ProblemData; 92 CalculateCorrelation(); 93 } else { 94 dataView.Maximum = 0; 95 dataView.Minimum = 0; 96 dataView.Content = null; 97 dataView.ResetVisibility(); 98 } 99 } 100 101 protected virtual bool[] SetInitialVariableVisibility() { 102 bool[] initialVisibility = new bool[Content.ProblemData.Dataset.DoubleVariables.Count()]; 103 int i = 0; 104 foreach (var variable in Content.ProblemData.Dataset.DoubleVariables) { 105 initialVisibility[i] = Content.ProblemData.AllowedInputVariables.Contains(variable); 106 i++; 107 } 108 return initialVisibility; 109 } 110 111 protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) { 112 CalculateCorrelation(); 113 } 114 protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) { 115 CalculateCorrelation(); 116 } 117 118 protected void CalculateCorrelation() { 119 if (correlationCalcComboBox.SelectedItem == null) return; 120 if (partitionComboBox.SelectedItem == null) return; 121 122 IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue; 123 string partition = (string)partitionComboBox.SelectedValue; 124 dataView.Enabled = false; 125 double[,] corr = correlationCache.GetCorrelation(calc, partition); 126 if (corr == null) { 127 fcc.CalculateElements(calc, partition); 128 } else { 129 fcc.TryCancelCalculation(); 130 var correlation = new DoubleMatrix(corr, Content.ProblemData.Dataset.DoubleVariables, Content.ProblemData.Dataset.DoubleVariables); 131 UpdateDataView(correlation); 132 } 133 } 134 135 protected void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) { 136 if (InvokeRequired) { 137 Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e); 71 if (Content == null) { 72 correlationView.Content = null; 138 73 return; 139 74 } 140 correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation); 141 var correlation = new DoubleMatrix(e.Correlation, Content.ProblemData.Dataset.DoubleVariables, Content.ProblemData.Dataset.DoubleVariables); 142 UpdateDataView(correlation); 75 76 correlationView.Content = Content.ProblemData; 143 77 } 144 145 protected void UpdateDataView(DoubleMatrix correlation) {146 IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;147 maximumLabel.Text = calc.Maximum.ToString();148 minimumLabel.Text = calc.Minimum.ToString();149 150 correlation.SortableView = true;151 dataView.Maximum = calc.Maximum;152 dataView.Minimum = calc.Minimum;153 dataView.Content = correlation;154 dataView.Enabled = true;155 }156 157 protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {158 if (!progressPanel.Visible && e.ProgressPercentage != progressBar.Maximum) {159 progressPanel.Show();160 } else if (e.ProgressPercentage == progressBar.Maximum) {161 progressPanel.Hide();162 }163 progressBar.Value = e.ProgressPercentage;164 }165 166 [NonDiscoverableType]167 private class FeatureCorrelationCache : Object {168 private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache;169 170 public FeatureCorrelationCache()171 : base() {172 InitializeCaches();173 }174 175 private void InitializeCaches() {176 correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>();177 }178 179 public void Reset() {180 InitializeCaches();181 }182 183 public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {184 double[,] corr;185 var key = new Tuple<IDependencyCalculator, string>(calc, partition);186 correlationsCache.TryGetValue(key, out corr);187 return corr;188 }189 190 public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {191 var key = new Tuple<IDependencyCalculator, string>(calc, partition);192 correlationsCache[key] = correlation;193 }194 }195 78 } 196 79 }
Note: See TracChangeset
for help on using the changeset viewer.