Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/28/14 15:09:26 (10 years ago)
Author:
mleitner
Message:

Add Feature correlation matrix, Add limit for distinct values in histogramm classification.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/PreprocessingFeatureCorrelationView.cs

    r10870 r10908  
    2828using HeuristicLab.MainForm.WindowsForms;
    2929using HeuristicLab.PluginInfrastructure;
     30using System;
     31using HeuristicLab.DataPreprocessing;
    3032
    3133namespace 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 {
    3537    public const string ALLSAMPLES = "All Samples";
    3638    public const string TRAININGSAMPLES = "Training Samples";
     
    4143    protected FeatureCorrelationCalculator fcc;
    4244
    43     public new DataAnalysisProblemData Content {
    44       get { return (DataAnalysisProblemData)base.Content; }
     45    public new CorrelationMatrixContent Content
     46    {
     47      get { return (CorrelationMatrixContent) base.Content; }
    4548      set { base.Content = value; }
    4649    }
    4750
    48     protected AbstractFeatureCorrelationView() {
     51    private FeatureCorrelationCache correlationCache;
     52
     53    public PreprocessingFeatureCorrelationView() {
     54
     55      correlationCache = new FeatureCorrelationCache();
    4956      InitializeComponent();
    5057      fcc = new FeatureCorrelationCalculator();
     
    7582      fcc.TryCancelCalculation();
    7683      if (Content != null) {
    77         fcc.ProblemData = Content;
     84        fcc.ProblemData = Content.ProblemData;
    7885        CalculateCorrelation();
    7986      } else {
     
    8693
    8794    protected virtual bool[] SetInitialVariableVisibility() {
    88       bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
     95      bool[] initialVisibility = new bool[Content.ProblemData.Dataset.DoubleVariables.Count()];
    8996      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);
    9299        i++;
    93100      }
     
    102109    }
    103110
    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    }
    106137
    107138    protected void UpdateDataView(DoubleMatrix correlation) {
     
    125156      progressBar.Value = e.ProgressPercentage;
    126157    }
     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      }
    127188  }
    128189}
Note: See TracChangeset for help on using the changeset viewer.