Changeset 13938 for trunk/sources
- Timestamp:
- 06/27/16 15:28:26 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs
r12151 r13938 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(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs
r12509 r13938 24 24 using System.ComponentModel; 25 25 using System.Linq; 26 using System.Threading.Tasks; 26 27 using HeuristicLab.PluginInfrastructure; 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.Views { 29 30 [NonDiscoverableType] 30 public class FeatureCorrelationCalculator : Object { 31 public sealed class FeatureCorrelationCalculator : AbstractFeatureCorrelationCalculator { 32 public FeatureCorrelationCalculator() : base() { } 31 33 32 private BackgroundWorker bw; 33 private BackgroundWorkerInfo bwInfo; 34 public void CalculateElements(IDataAnalysisProblemData problemData, IDependencyCalculator calc, string partition, bool ignoreMissingValues) { 35 var indices = GetRelevantIndices(problemData, partition); 36 var info = new BackgroundWorkerInfo { 37 Dataset = problemData.Dataset, Calculator = calc, Partition = partition, Indices = indices, IgnoreMissingValues = ignoreMissingValues 38 }; 34 39 35 private IDataAnalysisProblemData problemData; 36 public IDataAnalysisProblemData ProblemData { 37 set { 38 if (bw != null) { 39 bw.CancelAsync(); 40 } 41 problemData = value; 42 } 40 StartCalculation(info); 43 41 } 44 42 45 public FeatureCorrelationCalculator() 46 : base() { } 43 protected override void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { 44 BackgroundWorker worker = (BackgroundWorker)sender; 45 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument; 47 46 48 public FeatureCorrelationCalculator(IDataAnalysisProblemData problemData)49 : base() {50 this.problemData = problemData;51 }52 53 public void CalculateElements(IDependencyCalculator calc, string partition) {54 CalculateElements(problemData.Dataset, calc, partition);55 }56 57 // returns true if any calculation takes place58 public bool CalculateTimeframeElements(IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null) {59 if (correlation == null || correlation.GetLength(1) <= frames) {60 CalculateElements(problemData.Dataset, calc, partition, variable, frames, correlation);61 return true;62 } else {63 return false;64 }65 }66 67 public void TryCancelCalculation() {68 if (bw != null && bw.IsBusy) {69 bwInfo = null;70 bw.CancelAsync();71 }72 }73 74 private void CalculateElements(IDataset dataset, IDependencyCalculator calc, string partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null) {75 var indices = GetRelevantIndices(problemData, partition);76 bwInfo = new BackgroundWorkerInfo {77 Dataset = dataset, Calculator = calc, Partition = partition, Indices = indices,78 Variable = variable, Frames = frames, AlreadyCalculated = alreadyCalculated79 };80 if (bw == null) {81 bw = new BackgroundWorker();82 bw.WorkerReportsProgress = true;83 bw.WorkerSupportsCancellation = true;84 bw.DoWork += new DoWorkEventHandler(BwDoWork);85 bw.ProgressChanged += new ProgressChangedEventHandler(BwProgressChanged);86 bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BwRunWorkerCompleted);87 }88 if (bw.IsBusy) {89 bw.CancelAsync();90 } else {91 bw.RunWorkerAsync(bwInfo);92 }93 }94 95 private IEnumerable<int> GetRelevantIndices(IDataAnalysisProblemData problemData, string partition) {96 IEnumerable<int> var;97 if (partition.Equals(AbstractFeatureCorrelationView.TRAININGSAMPLES))98 var = problemData.TrainingIndices;99 else if (partition.Equals(AbstractFeatureCorrelationView.TESTSAMPLES))100 var = problemData.TestIndices;101 else var = Enumerable.Range(0, problemData.Dataset.Rows);102 return var;103 }104 105 #region backgroundworker106 private void BwDoWork(object sender, DoWorkEventArgs e) {107 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;108 if (bwInfo.Variable == null) {109 BwCalculateCorrelation(sender, e);110 } else {111 BwCalculateTimeframeCorrelation(sender, e);112 }113 }114 115 private void BwCalculateCorrelation(object sender, DoWorkEventArgs e) {116 BackgroundWorker worker = sender as BackgroundWorker;117 118 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;119 47 var dataset = bwInfo.Dataset; 120 IEnumerable<int> indices = bwInfo.Indices;48 var indices = bwInfo.Indices.ToArray(); 121 49 IDependencyCalculator calc = bwInfo.Calculator; 122 50 … … 125 53 int length = doubleVariableNames.Count; 126 54 double[,] elements = new double[length, length]; 127 double calculations = (Math.Pow(length, 2) + length) / 2;128 55 129 56 worker.ReportProgress(0); 130 57 131 for (int i = 0; i < length; i++) { 132 for (int j = 0; j < i + 1; j++) { 133 if (worker.CancellationPending) { 134 worker.ReportProgress(100); 135 e.Cancel = true; 136 return; 137 } 138 IEnumerable<double> var1 = problemData.Dataset.GetDoubleValues(doubleVariableNames[i], indices); 139 IEnumerable<double> var2 = problemData.Dataset.GetDoubleValues(doubleVariableNames[j], indices); 58 for (int counter = 0; counter < length; counter++) { 59 if (worker.CancellationPending) { 60 worker.ReportProgress(100); 61 e.Cancel = true; 62 return; 63 } 140 64 141 elements[i, j] = calc.Calculate(var1, var2, out error); 65 var i = counter; 66 Parallel.ForEach(Enumerable.Range(i, length - i), j => { 67 var var1 = dataset.GetDoubleValues(doubleVariableNames[i], indices); 68 var var2 = dataset.GetDoubleValues(doubleVariableNames[j], indices); 69 70 if (bwInfo.IgnoreMissingValues) { 71 var filtered = FilterNaNValues(var1, var2); 72 elements[i, j] = calc.Calculate(filtered, out error); 73 } else 74 elements[i, j] = calc.Calculate(var1, var2, out error); 142 75 143 76 if (!error.Equals(OnlineCalculatorError.None)) { … … 145 78 } 146 79 elements[j, i] = elements[i, j]; 147 worker.ReportProgress((int)Math.Round((((Math.Pow(i, 2) + i) / 2 + j + 1.0) / calculations) * 100)); 148 } 80 81 }); 82 worker.ReportProgress((int)(((double)counter) / length * 100)); 149 83 } 150 84 e.Result = elements; … … 152 86 } 153 87 154 private void BwCalculateTimeframeCorrelation(object sender, DoWorkEventArgs e) {155 BackgroundWorker worker = sender as BackgroundWorker;156 88 157 BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument; 158 var dataset = bwInfo.Dataset; 159 IEnumerable<int> indices = bwInfo.Indices; 160 IDependencyCalculator calc = bwInfo.Calculator; 161 string variable = bwInfo.Variable; 162 int frames = bwInfo.Frames; 163 double[,] alreadyCalculated = bwInfo.AlreadyCalculated; 89 private static IEnumerable<Tuple<double, double>> FilterNaNValues(IEnumerable<double> first, IEnumerable<double> second) { 90 var firstEnumerator = first.GetEnumerator(); 91 var secondEnumerator = second.GetEnumerator(); 164 92 165 IList<string> doubleVariableNames = dataset.DoubleVariables.ToList(); 166 OnlineCalculatorError error = OnlineCalculatorError.None; 167 int length = doubleVariableNames.Count; 168 double[,] elements = new double[length, frames + 1]; 169 double calculations = (frames + 1) * length; 93 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 94 var firstValue = firstEnumerator.Current; 95 var secondValue = secondEnumerator.Current; 170 96 171 worker.ReportProgress(0); 97 if (double.IsNaN(firstValue)) continue; 98 if (double.IsNaN(secondValue)) continue; 172 99 173 int start = 0; 174 if (alreadyCalculated != null) { 175 for (int i = 0; i < alreadyCalculated.GetLength(0); i++) { 176 Array.Copy(alreadyCalculated, i * alreadyCalculated.GetLength(1), elements, i * elements.GetLength(1), alreadyCalculated.GetLength(1)); 177 } 178 start = alreadyCalculated.GetLength(1); 100 yield return Tuple.Create(firstValue, secondValue); 179 101 } 180 102 181 for (int i = 0; i < length; i++) { 182 for (int j = start; j <= frames; j++) { 183 if (worker.CancellationPending) { 184 worker.ReportProgress(100); 185 e.Cancel = true; 186 return; 187 } 188 189 IEnumerable<double> var1 = problemData.Dataset.GetDoubleValues(variable, indices); 190 IEnumerable<double> var2 = problemData.Dataset.GetDoubleValues(doubleVariableNames[i], indices); 191 192 var valuesInFrame = var1.Take(j); 193 var help = var1.Skip(j).ToList(); 194 help.AddRange(valuesInFrame); 195 var1 = help; 196 197 elements[i, j] = calc.Calculate(var1, var2, out error); 198 199 if (!error.Equals(OnlineCalculatorError.None)) { 200 elements[i, j] = double.NaN; 201 } 202 worker.ReportProgress((int)((100.0 / calculations) * (i * (frames + 1) + j + 1))); 203 } 103 if (firstEnumerator.MoveNext() || secondEnumerator.MoveNext()) { 104 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 204 105 } 205 e.Result = elements;206 worker.ReportProgress(100);207 }208 209 private void BwRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {210 BackgroundWorker worker = sender as BackgroundWorker;211 if (!e.Cancelled && !worker.CancellationPending) {212 if (e.Error != null) {213 ErrorHandling.ShowErrorDialog(e.Error);214 } else {215 OnCorrelationCalculationFinished((double[,])e.Result, bwInfo.Calculator, bwInfo.Partition, bwInfo.Variable);216 }217 } else if (bwInfo != null) {218 bw.RunWorkerAsync(bwInfo);219 }220 }221 #endregion222 223 #region events224 public class CorrelationCalculationFinishedArgs : EventArgs {225 public double[,] Correlation { get; private set; }226 public IDependencyCalculator Calculcator { get; private set; }227 public string Partition { get; private set; }228 public string Variable { get; private set; }229 230 public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {231 this.Correlation = correlation;232 this.Calculcator = calculator;233 this.Partition = partition;234 this.Variable = variable;235 }236 }237 238 public delegate void CorrelationCalculationFinishedHandler(object sender, CorrelationCalculationFinishedArgs e);239 public event CorrelationCalculationFinishedHandler CorrelationCalculationFinished;240 protected virtual void OnCorrelationCalculationFinished(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {241 var handler = CorrelationCalculationFinished;242 if (handler != null)243 handler(this, new CorrelationCalculationFinishedArgs(correlation, calculator, partition, variable));244 }245 246 public delegate void ProgressCalculationHandler(object sender, ProgressChangedEventArgs e);247 public event ProgressCalculationHandler ProgressCalculation;248 protected void BwProgressChanged(object sender, ProgressChangedEventArgs e) {249 BackgroundWorker worker = sender as BackgroundWorker;250 if (ProgressCalculation != null) {251 ProgressCalculation(sender, e);252 }253 }254 #endregion255 256 private class BackgroundWorkerInfo {257 public IDataset Dataset { get; set; }258 public IDependencyCalculator Calculator { get; set; }259 public string Partition { get; set; }260 public IEnumerable<int> Indices { get; set; }261 public string Variable { get; set; }262 public int Frames { get; set; }263 public double[,] AlreadyCalculated { get; set; }264 106 } 265 107 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.Designer.cs
r12012 r13938 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 = "ignoreMissingValues"; 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 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs
r12012 r13938 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 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs
r12012 r13938 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); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r13705 r13938 120 120 </ItemGroup> 121 121 <ItemGroup> 122 <Compile Include="FeatureCorrelation\TimeframeFeatureCorrelationCalculator.cs" /> 123 <Compile Include="FeatureCorrelation\AbstractFeatureCorrelationCalculator.cs" /> 122 124 <Compile Include="Classification\ClassificationEnsembleSolutionEstimatedClassValuesView.cs"> 123 125 <SubType>UserControl</SubType> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs
r12012 r13938 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 … … 29 30 30 31 double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState); 32 double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState); 31 33 } 32 34 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/HoeffdingsDependenceCalculator.cs
r12012 r13938 41 41 if (errorState != OnlineCalculatorError.None) return double.NaN; 42 42 return d; 43 } 44 45 public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) { 46 return HoeffD(values.Select(v => v.Item1), values.Select(v => v.Item2), out errorState); 43 47 } 44 48 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs
r12492 r13938 35 35 return OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState); 36 36 } 37 38 public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) { 39 var calculator = new OnlinePearsonsRCalculator(); 40 foreach (var tuple in values) { 41 calculator.Add(tuple.Item1, tuple.Item2); 42 if (calculator.ErrorState != OnlineCalculatorError.None) break; 43 } 44 errorState = calculator.ErrorState; 45 return calculator.R; 46 } 37 47 } 38 48 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs
r12641 r13938 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 … … 35 36 return r * r; 36 37 } 38 39 public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) { 40 var calculator = new OnlinePearsonsRCalculator(); 41 foreach (var tuple in values) { 42 calculator.Add(tuple.Item1, tuple.Item2); 43 if (calculator.ErrorState != OnlineCalculatorError.None) break; 44 } 45 errorState = calculator.ErrorState; 46 var r = calculator.R; 47 return r * r; 48 } 37 49 } 38 50 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs
r12817 r13938 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 33 34 34 35 public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 35 return SpearmansRankCorrelationCoefficientCalculator.CalculateSpearmansRank(originalValues, estimatedValues, out errorState); 36 return CalculateSpearmansRank(originalValues, estimatedValues, out errorState); 37 } 38 public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) { 39 return CalculateSpearmansRank(values.Select(v => v.Item1), values.Select(v => v.Item2), out errorState); 36 40 } 37 41 … … 50 54 return rs; 51 55 } 56 57 52 58 } 53 59 }
Note: See TracChangeset
for help on using the changeset viewer.