Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/18 11:13:37 (6 years ago)
Author:
gkronber
Message:

#2522: merged trunk changes from r13402:15972 to branch resolving conflicts where necessary

Location:
branches/2522_RefactorPluginInfrastructure
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/2522_RefactorPluginInfrastructure

  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views

  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationCalculator.cs

    r15674 r15973  
    2626using System.ComponentModel;
    2727using System.Linq;
     28using HeuristicLab.MainForm;
    2829using HeuristicLab.PluginInfrastructure;
    2930
     
    7778      if (!e.Cancelled && !worker.CancellationPending) {
    7879        if (e.Error != null) {
    79           ErrorHandling.ShowErrorDialog(e.Error);
     80          MainFormManager.MainForm.ShowError(e.Error.Message, e.Error);
    8081        } else {
    8182          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  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs

    r12151 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3737    public const string TESTSAMPLES = "Test Samples";
    3838
    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();
    4040
    41     protected FeatureCorrelationCalculator fcc;
     41    protected AbstractFeatureCorrelationCalculator CorrelationCalculator { get; set; }
    4242
    4343    public new DataAnalysisProblemData Content {
     
    4949      InitializeComponent();
    5050      dataView.FormatPattern = "0.000";
    51       fcc = new FeatureCorrelationCalculator();
    5251      var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
    5352      var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
     
    5554      correlationCalcComboBox.DisplayMember = "Name";
    5655      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));
    5857      partitionComboBox.DataSource = Partitions;
    5958      partitionComboBox.SelectedItem = TRAININGSAMPLES;
     
    6160    }
    6261
     62    protected override void OnClosing(FormClosingEventArgs e) {
     63      base.OnClosing(e);
     64      CorrelationCalculator.TryCancelCalculation();
     65    }
     66
    6367    protected override void RegisterContentEvents() {
    6468      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;
    6771    }
    6872
    6973    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;
    7276      base.DeregisterContentEvents();
    7377    }
     
    7579    protected override void OnContentChanged() {
    7680      base.OnContentChanged();
    77       fcc.TryCancelCalculation();
     81      CorrelationCalculator.TryCancelCalculation();
    7882      if (Content != null) {
    79         fcc.ProblemData = Content;
    8083        CalculateCorrelation();
    8184      } else {
     
    106109
    107110    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);
    109114
    110115    protected void UpdateDataView(DoubleMatrix correlation) {
     
    121126    }
    122127
    123     protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {
     128    protected void FeatureCorrelation_ProgressChanged(object sender, ProgressChangedEventArgs e) {
    124129      if (!progressPanel.Visible && e.ProgressPercentage != progressBar.Maximum) {
    125130        progressPanel.Show();
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs

    r13338 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.ComponentModel;
    2525using System.Linq;
     26using System.Threading.Tasks;
    2627using HeuristicLab.MainForm;
    2728using HeuristicLab.PluginInfrastructure;
     
    2930namespace HeuristicLab.Problems.DataAnalysis.Views {
    3031  [NonDiscoverableType]
    31   public class FeatureCorrelationCalculator : Object {
     32  public sealed class FeatureCorrelationCalculator : AbstractFeatureCorrelationCalculator {
     33    public FeatureCorrelationCalculator() : base() { }
    3234
    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      };
    3540
    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);
    4442    }
    4543
    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;
    4847
    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 place
    59     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 = alreadyCalculated
    80       };
    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 backgroundworker
    107     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;
    12048      var dataset = bwInfo.Dataset;
    121       IEnumerable<int> indices = bwInfo.Indices;
     49      var indices = bwInfo.Indices.ToArray();
    12250      IDependencyCalculator calc = bwInfo.Calculator;
    12351
    12452      IList<string> doubleVariableNames = dataset.DoubleVariables.ToList();
    125       OnlineCalculatorError error = OnlineCalculatorError.None;
     53
    12654      int length = doubleVariableNames.Count;
    12755      double[,] elements = new double[length, length];
    128       double calculations = (Math.Pow(length, 2) + length) / 2;
    12956
    13057      worker.ReportProgress(0);
    13158
    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        }
    14165
    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);
    14377
    14478          if (!error.Equals(OnlineCalculatorError.None)) {
     
    14680          }
    14781          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));
    15084      }
     85
    15186      e.Result = elements;
    15287      worker.ReportProgress(100);
    15388    }
    15489
    155     private void BwCalculateTimeframeCorrelation(object sender, DoWorkEventArgs e) {
    156       BackgroundWorker worker = sender as BackgroundWorker;
    15790
    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();
    16594
    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;
    17198
    172       worker.ReportProgress(0);
     99        if (double.IsNaN(firstValue)) continue;
     100        if (double.IsNaN(secondValue)) continue;
    173101
    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);
    180103      }
    181104
    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.");
    205107      }
    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     #endregion
    223 
    224     #region events
    225     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     #endregion
    256 
    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; }
    265108    }
    266109  }
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.Designer.cs

    r12012 r15973  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    4747    /// </summary>
    4848    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();
    4956      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);
    5094      //
    5195      // FeatureCorrelationView
     
    5498      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    5599      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();
    57109      this.ResumeLayout(false);
     110
    58111    }
    59112    #endregion
     113
     114    private System.Windows.Forms.CheckBox ignoreMissingValuesCheckbox;
    60115  }
    61116}
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs

    r12012 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434
    3535    private FeatureCorrelationCache correlationCache;
     36    private new FeatureCorrelationCalculator CorrelationCalculator {
     37      get { return (FeatureCorrelationCalculator)base.CorrelationCalculator; }
     38      set { base.CorrelationCalculator = value; }
     39    }
    3640
    3741    public FeatureCorrelationView()
    3842      : base() {
    3943      InitializeComponent();
     44      CorrelationCalculator = new FeatureCorrelationCalculator();
    4045      correlationCache = new FeatureCorrelationCache();
    4146    }
     
    4954    }
    5055
     56    private void ignoreMissingValuesCheckbox_CheckedChanged(object sender, EventArgs e) {
     57      CalculateCorrelation();
     58    }
     59
    5160    protected override void CalculateCorrelation() {
    5261      if (correlationCalcComboBox.SelectedItem == null) return;
     
    5665      string partition = (string)partitionComboBox.SelectedValue;
    5766      dataView.Enabled = false;
    58       double[,] corr = correlationCache.GetCorrelation(calc, partition);
     67      double[,] corr = correlationCache.GetCorrelation(calc, partition, ignoreMissingValuesCheckbox.Checked);
    5968      if (corr == null) {
    60         fcc.CalculateElements(calc, partition);
     69        CorrelationCalculator.CalculateElements(Content, calc, partition, ignoreMissingValuesCheckbox.Checked);
    6170      } else {
    62         fcc.TryCancelCalculation();
     71        CorrelationCalculator.TryCancelCalculation();
    6372        var correlation = new DoubleMatrix(corr, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables);
    6473        UpdateDataView(correlation);
     
    6675    }
    6776
    68 
    69 
    70     protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
     77    protected override void FeatureCorrelation_CalculationFinished(object sender, AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
    7178      if (InvokeRequired) {
    72         Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);
     79        Invoke(new AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(FeatureCorrelation_CalculationFinished), sender, e);
    7380        return;
    7481      }
    75       correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation);
     82      correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.IgnoreMissingValues, e.Correlation);
     83
    7684      var correlation = new DoubleMatrix(e.Correlation, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables);
    7785      UpdateDataView(correlation);
     
    8088    [NonDiscoverableType]
    8189    private class FeatureCorrelationCache : Object {
    82       private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache;
     90      private Dictionary<Tuple<IDependencyCalculator, string, bool>, double[,]> correlationsCache;
    8391
    8492      public FeatureCorrelationCache()
     
    8896
    8997      private void InitializeCaches() {
    90         correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>();
     98        correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string, bool>, double[,]>();
    9199      }
    92100
     
    95103      }
    96104
    97       public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {
     105      public double[,] GetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues) {
    98106        double[,] corr;
    99         var key = new Tuple<IDependencyCalculator, string>(calc, partition);
     107        var key = Tuple.Create(calc, partition, ignoreMissingValues);
    100108        correlationsCache.TryGetValue(key, out corr);
    101109        return corr;
    102110      }
    103111
    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);
    106114        correlationsCache[key] = correlation;
    107115      }
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.Designer.cs

    r12012 r15973  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs

    r12012 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3636    private string lastFramesValue;
    3737
     38    private new TimeframeFeatureCorrelationCalculator CorrelationCalculator {
     39      get { return (TimeframeFeatureCorrelationCalculator)base.CorrelationCalculator; }
     40      set { base.CorrelationCalculator = value; }
     41    }
     42
     43
    3844    public TimeframeFeatureCorrelationView() {
    3945      InitializeComponent();
     46      CorrelationCalculator = new TimeframeFeatureCorrelationCalculator();
    4047      correlationTimeframCache = new FeatureCorrelationTimeframeCache();
    4148      errorProvider.SetIconAlignment(timeframeTextbox, ErrorIconAlignment.MiddleRight);
     
    93100
    94101    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);
    115123      }
    116124    }
    117125
    118     protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
     126    protected override void FeatureCorrelation_CalculationFinished(object sender, AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
    119127      if (InvokeRequired) {
    120         Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);
     128        Invoke(new AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(FeatureCorrelation_CalculationFinished), sender, e);
    121129      } else {
    122130        correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation);
Note: See TracChangeset for help on using the changeset viewer.