Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/14/17 10:29:51 (7 years ago)
Author:
pfleck
Message:

#2709 merged to stable

Location:
stable
Files:
2 deleted
14 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.DataPreprocessing

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessingmergedeligible
      /branches/crossvalidation-2434/HeuristicLab.DataPreprocessingmergedeligible
      /trunk/sources/HeuristicLab.DataPreprocessingmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.DataPreprocessing10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.DataPreprocessing5516-5520
      /branches/Benchmarking/sources/HeuristicLab.DataPreprocessing6917-7005
      /branches/CloningRefactoring/HeuristicLab.DataPreprocessing4656-4721
      /branches/CodeEditor/HeuristicLab.DataPreprocessing11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.DataPreprocessing5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.DataPreprocessing5815-6180
      /branches/DataAnalysis/HeuristicLab.DataPreprocessing4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.DataPreprocessing10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.DataPreprocessing6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.DataPreprocessing5060
      /branches/HLScript/HeuristicLab.DataPreprocessing10331-10358
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.DataPreprocessing11570-12508
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.DataPreprocessing6123-9799
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.DataPreprocessing11130-12721
      /branches/HiveStatistics/sources/HeuristicLab.DataPreprocessing12440-12877
      /branches/LogResidualEvaluator/HeuristicLab.DataPreprocessing10202-10483
      /branches/NET40/sources/HeuristicLab.DataPreprocessing5138-5162
      /branches/NSGA-II Changes/HeuristicLab.DataPreprocessing12033-12122
      /branches/ParallelEngine/HeuristicLab.DataPreprocessing5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.DataPreprocessing7568-7810
      /branches/QAPAlgorithms/HeuristicLab.DataPreprocessing6350-6627
      /branches/Restructure trunk solution/HeuristicLab.DataPreprocessing6828
      /branches/RuntimeOptimizer/HeuristicLab.DataPreprocessing8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.DataPreprocessing7787-8333
      /branches/SlaveShutdown/HeuristicLab.DataPreprocessing8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.DataPreprocessing10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.DataPreprocessing5370-5682
      /branches/Trunk/HeuristicLab.DataPreprocessing6829-6865
      /branches/UnloadJobs/HeuristicLab.DataPreprocessing9168-9215
      /branches/VNS/HeuristicLab.DataPreprocessing5594-5752
      /branches/histogram/HeuristicLab.DataPreprocessing5959-6341
      /branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing14232-14825
      /trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/HeuristicLab.DataPreprocessing14175
  • stable/HeuristicLab.DataPreprocessing/3.4

  • stable/HeuristicLab.DataPreprocessing/3.4/Content/CorrelationMatrixContent.cs

    r14186 r15242  
    2727namespace HeuristicLab.DataPreprocessing {
    2828  [Item("Feature Correlation Matrix", "Represents the feature correlation matrix.")]
    29   public class CorrelationMatrixContent : Item, IViewChartShortcut {
     29  public class CorrelationMatrixContent : Item, IViewShortcut {
    3030    public static new Image StaticItemImage {
    3131      get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; }
    3232    }
    3333
    34     private PreprocessingContext Context { get; set; }
    35     private ITransactionalPreprocessingData PreprocessingData {
     34    public PreprocessingContext Context { get; private set; }
     35    public ITransactionalPreprocessingData PreprocessingData {
    3636      get { return Context.Data; }
    3737    }
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/DataCompletenessChartContent.cs

    r13508 r15242  
    1 using System.Drawing;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Drawing;
    223using HeuristicLab.Common;
    324using HeuristicLab.Core;
    425
    526namespace HeuristicLab.DataPreprocessing {
    6   [Item("DataCompletenessChart", "Represents a datacompleteness chart.")]
     27  [Item("Data Completeness Chart", "Represents a datacompleteness chart.")]
    728
    8   public class DataCompletenessChartContent : Item, IViewChartShortcut {
     29  public class DataCompletenessChartContent : Item, IViewShortcut {
    930    public static new Image StaticItemImage {
    1031      get { return HeuristicLab.Common.Resources.VSImageLibrary.EditBrightnessContrast; }
    1132    }
    1233
    13     //public DataGridLogic DataGridLogic { get; private set; }
    1434    public SearchLogic SearchLogic { get; private set; }
    1535
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/DataGridContent.cs

    r14186 r15242  
    3030namespace HeuristicLab.DataPreprocessing {
    3131
    32   [Item("DataGrid", "Represents a data grid.")]
     32  [Item("Data Grid", "Represents a data grid.")]
    3333  public class DataGridContent : Item, IStringConvertibleMatrix, IViewShortcut {
    34 
    35     public ITransactionalPreprocessingData PreProcessingData { get; private set; }
    36 
    3734    public static new Image StaticItemImage {
    3835      get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
    3936    }
     37
     38    public ITransactionalPreprocessingData PreProcessingData { get; private set; }
    4039
    4140    public ManipulationLogic ManipulationLogic { get; private set; }
     
    4342
    4443    public int Rows {
    45       get {
    46         return PreProcessingData.Rows;
    47       }
    48       set {
    49         //does nothing
    50       }
     44      get { return PreProcessingData.Rows; }
     45      set { }
    5146    }
    5247
    5348    public int Columns {
    54       get {
    55         return PreProcessingData.Columns;
    56       }
    57       set {
    58         //does nothing
    59       }
     49      get { return PreProcessingData.Columns; }
     50      set { }
    6051    }
    6152
    6253    public IEnumerable<string> ColumnNames {
    63       get {
    64         return PreProcessingData.VariableNames;
    65       }
    66       set {
    67 
    68       }
     54      get { return PreProcessingData.VariableNames; }
     55      set { }
    6956    }
    7057
    7158    public IEnumerable<string> RowNames {
    72       get {
    73         return Enumerable.Range(1, Rows).Select(n => n.ToString());
    74       }
    75       set {
    76         throw new NotSupportedException();
    77       }
     59      get { return Enumerable.Range(1, Rows).Select(n => n.ToString()); }
     60      set { throw new NotSupportedException(); }
    7861    }
    7962
    8063    public bool SortableView {
    81       get {
    82         return true;
    83       }
    84       set {
    85         throw new NotSupportedException();
    86       }
     64      get { return true; }
     65      set { throw new NotSupportedException(); }
    8766    }
    8867
     
    9170    }
    9271
    93 
    9472    public IDictionary<int, IList<int>> Selection {
    9573      get { return PreProcessingData.Selection; }
    9674      set { PreProcessingData.Selection = value; }
    9775    }
    98 
    9976
    10077    public DataGridContent(ITransactionalPreprocessingData preProcessingData, ManipulationLogic theManipulationLogic, FilterLogic theFilterLogic) {
     
    137114    }
    138115
    139 
    140116    #region unused stuff/not implemented but necessary due to IStringConvertibleMatrix
    141117#pragma warning disable 0067
     
    154130    public event EventHandler<EventArgs<int, int>> ItemChanged;
    155131    public event EventHandler Reset;
    156 
    157132#pragma warning restore 0067
    158133    #endregion
    159 
    160134  }
    161135}
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/FilterContent.cs

    r14186 r15242  
    2828  [Item("Filter", "Represents the filter grid.")]
    2929  public class FilterContent : Item, IViewShortcut {
    30 
    3130    public static new Image StaticItemImage {
    3231      get { return HeuristicLab.Common.Resources.VSImageLibrary.Filter; }
    3332    }
    3433
    35     private ICheckedItemCollection<IFilter> filters = new CheckedItemCollection<IFilter>();
    36 
    3734    public FilterLogic FilterLogic { get; private set; }
    3835
    39     public ICheckedItemCollection<IFilter> Filters {
    40       get {
    41         return this.filters;
    42       }
    43       set {
    44         this.filters = value;
    45       }
    46     }
     36    public ICheckedItemCollection<IFilter> Filters { get; private set; }
    4737
    48     private bool isAndCombination = true;
    49     public bool IsAndCombination {
    50       get {
    51         return this.isAndCombination;
    52       }
    53       set {
    54         this.isAndCombination = value;
    55       }
    56     }
     38    public bool IsAndCombination { get; set; }
    5739
    5840    public FilterContent(FilterLogic filterLogic) {
     41      Filters = new CheckedItemCollection<IFilter>();
     42      IsAndCombination = true;
    5943      FilterLogic = filterLogic;
    6044    }
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs

    r14186 r15242  
    2020#endregion
    2121
    22 using System.Collections.Generic;
     22using System;
    2323using System.Drawing;
    2424using System.Linq;
     25using HeuristicLab.Analysis;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2930  [Item("Histogram", "Represents the histogram grid.")]
    3031  public class HistogramContent : PreprocessingChartContent {
    31 
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.Statistics; }
    3434    }
    35     private const int MAX_DISTINCT_VALUES_FOR_CLASSIFCATION = 20;
    3635
    37     private int classifierVariableIndex = 0;
     36    public string GroupingVariableName { get; set; }
    3837
    39     public int ClassifierVariableIndex {
    40       get { return this.classifierVariableIndex; }
    41       set { this.classifierVariableIndex = value; }
    42     }
    43     public bool IsDetailedChartViewEnabled { get; set; }
     38    public int Bins { get; set; }
     39    public bool ExactBins { get; set; }
    4440
     41    public LegendOrder Order { get; set; }
    4542
    4643    public HistogramContent(IFilteredPreprocessingData preprocessingData)
    4744      : base(preprocessingData) {
    48       AllInOneMode = false;
     45      Bins = 10;
     46      ExactBins = false;
    4947    }
    5048
     
    5654    }
    5755
    58     public IEnumerable<string> GetVariableNamesForHistogramClassification() {
    59       List<string> doubleVariableNames = new List<string>();
     56    public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataTableVisualProperties.DataTableHistogramAggregation aggregation, LegendOrder legendOrder = LegendOrder.Alphabetically) {
     57      var dataTable = new DataTable {
     58        VisualProperties = { Title = variableName, HistogramAggregation = aggregation },
     59      };
    6060
    61       //only return variable names from type double
    62       for (int i = 0; i < PreprocessingData.Columns; ++i) {
    63         if (PreprocessingData.VariableHasType<double>(i)) {
    64           double distinctValueCount = PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
    65           bool distinctValuesOk = distinctValueCount <= MAX_DISTINCT_VALUES_FOR_CLASSIFCATION;
    66           if (distinctValuesOk)
    67             doubleVariableNames.Add(PreprocessingData.GetVariableName(i));
    68         }
     61      if (string.IsNullOrEmpty(groupingVariableName)) {
     62        var row = PreprocessingChartContent.CreateDataRow(preprocessingData, variableName, DataRowVisualProperties.DataRowChartType.Histogram);
     63        row.VisualProperties.IsVisibleInLegend = false;
     64        dataTable.Rows.Add(row);
     65        return dataTable;
    6966      }
    70       return doubleVariableNames;
     67
     68      int variableIndex = preprocessingData.GetColumnIndex(variableName);
     69      var variableValues = preprocessingData.GetValues<double>(variableIndex);
     70      int groupVariableIndex = preprocessingData.GetColumnIndex(groupingVariableName);
     71      var groupingValues = Enumerable.Empty<string>();
     72
     73      if (preprocessingData.VariableHasType<double>(groupVariableIndex)) {
     74        groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString());
     75      } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) {
     76        groupingValues = preprocessingData.GetValues<string>(groupVariableIndex);
     77      } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) {
     78        groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString());
     79      }
     80
     81      var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);
     82
     83      if (legendOrder == LegendOrder.Alphabetically)
     84        groups = groups.OrderBy(x => x.Key, new NaturalStringComparer());
     85
     86      foreach (var group in groups) {
     87        var classRow = new DataRow {
     88          Name = group.Key,
     89          VisualProperties = {
     90              ChartType = DataRowVisualProperties.DataRowChartType.Histogram,
     91              IsVisibleInLegend = !string.IsNullOrEmpty(groupingVariableName)
     92            }
     93        };
     94        classRow.Values.AddRange(group);
     95        dataTable.Rows.Add(classRow);
     96      }
     97      return dataTable;
    7198    }
    72 
    7399  }
    74100}
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/LineChartContent.cs

    r14186 r15242  
    2626namespace HeuristicLab.DataPreprocessing {
    2727
    28   [Item("LineChart", "Represents the line chart grid.")]
     28  [Item("Line Chart", "Represents the line chart grid.")]
    2929  public class LineChartContent : PreprocessingChartContent {
     30    public bool AllInOneMode { get; set; }
    3031
    3132    public static new Image StaticItemImage {
     
    3536    public LineChartContent(IFilteredPreprocessingData preprocessingData)
    3637      : base(preprocessingData) {
     38      AllInOneMode = true;
    3739    }
    3840
    3941    public LineChartContent(LineChartContent content, Cloner cloner)
    4042      : base(content, cloner) {
     43      this.AllInOneMode = content.AllInOneMode;
    4144    }
    4245    public override IDeepCloneable Clone(Cloner cloner) {
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/ManipulationContent.cs

    r14186 r15242  
    2828  [Item("Manipulation", "Represents the available manipulations on a data set.")]
    2929  public class ManipulationContent : Item, IViewShortcut {
    30 
    31     private ManipulationLogic manipulationLogic;
    32     private SearchLogic searchLogic;
    33     private FilterLogic filterLogic;
    34 
    35     public ManipulationLogic ManipulationLogic { get { return manipulationLogic; } }
    36     public SearchLogic SearchLogic { get { return searchLogic; } }
    37     public FilterLogic FilterLogic { get { return filterLogic; } }
    38 
    3930    public static new Image StaticItemImage {
    4031      get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; }
    4132    }
    4233
    43     public ManipulationContent(ManipulationLogic theManipulationLogic, SearchLogic theSearchLogic, FilterLogic theFilterLogic) {
    44       manipulationLogic = theManipulationLogic;
    45       searchLogic = theSearchLogic;
    46       filterLogic = theFilterLogic;
     34    public ManipulationLogic ManipulationLogic { get; private set; }
     35    public SearchLogic SearchLogic { get; private set; }
     36    public FilterLogic FilterLogic { get; private set; }
     37
     38    public ManipulationContent(ManipulationLogic manipulationLogic, SearchLogic searchLogic, FilterLogic filterLogic) {
     39      ManipulationLogic = manipulationLogic;
     40      SearchLogic = searchLogic;
     41      FilterLogic = filterLogic;
    4742    }
    4843
     
    5247      return new ManipulationContent(this, cloner);
    5348    }
    54 
    55 
    5649  }
    5750}
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs

    r14963 r15242  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.Linq;
    2526using HeuristicLab.Analysis;
    2627using HeuristicLab.Common;
     28using HeuristicLab.Common.Resources;
    2729using HeuristicLab.Core;
    2830using HeuristicLab.Data;
     
    3032namespace HeuristicLab.DataPreprocessing {
    3133  [Item("PreprocessingChart", "Represents a preprocessing chart.")]
    32   public class PreprocessingChartContent : Item, IViewChartShortcut {
    33     public static new Image StaticItemImage {
    34       get { return HeuristicLab.Common.Resources.VSImageLibrary.PieChart; }
     34  public class PreprocessingChartContent : Item, IViewShortcut {
     35    public enum LegendOrder {
     36      Alphabetically,
     37      Appearance
    3538    }
    3639
    37     private bool allInOneMode = true;
    38     public bool AllInOneMode {
    39       get { return this.allInOneMode; }
    40       set { this.allInOneMode = value; }
     40    public static new Image StaticItemImage {
     41      get { return VSImageLibrary.PieChart; }
    4142    }
    4243
    4344    private ICheckedItemList<StringValue> variableItemList = null;
    4445    public ICheckedItemList<StringValue> VariableItemList {
    45       get { return this.variableItemList; }
    46       set { this.variableItemList = value; }
     46      get {
     47        if (variableItemList == null)
     48          variableItemList = CreateVariableItemList(PreprocessingData);
     49        return this.variableItemList;
     50      }
    4751    }
    4852
    4953    public IFilteredPreprocessingData PreprocessingData { get; private set; }
     54    public event DataPreprocessingChangedEventHandler Changed {
     55      add { PreprocessingData.Changed += value; }
     56      remove { PreprocessingData.Changed -= value; }
     57    }
    5058
    5159    public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
     
    5563    public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
    5664      : base(content, cloner) {
    57       this.allInOneMode = content.allInOneMode;
    5865      this.PreprocessingData = content.PreprocessingData;
    5966      this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
     
    6370    }
    6471
     72    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     73      return CreateDataRow(PreprocessingData, variableName, chartType);
     74    }
    6575
    66     public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
    67       IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
     76    public static DataRow CreateDataRow(IFilteredPreprocessingData preprocessingData, string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     77      IList<double> values = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableName));
    6878      DataRow row = new DataRow(variableName, "", values);
    6979      row.VisualProperties.ChartType = chartType;
     
    7181    }
    7282
    73     public List<DataRow> CreateAllDataRows(DataRowVisualProperties.DataRowChartType chartType) {
    74       List<DataRow> dataRows = new List<DataRow>();
    75       foreach (var name in PreprocessingData.GetDoubleVariableNames())
    76         dataRows.Add(CreateDataRow(name, chartType));
    77       return dataRows;
    78     }
    79 
    80     public DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
    81 
    82       IDictionary<int, IList<int>> selection = PreprocessingData.Selection;
    83       int variableIndex = PreprocessingData.GetColumnIndex(variableName);
    84 
    85       if (selection.Keys.Contains(variableIndex)) {
    86         List<int> selectedIndices = new List<int>(selection[variableIndex]);
    87         //need selection with more than 1 value
    88         if (selectedIndices.Count < 2)
    89           return null;
    90 
    91         selectedIndices.Sort();
    92         int start = selectedIndices[0];
    93         int end = selectedIndices[selectedIndices.Count - 1];
    94 
    95         DataRow rowSelect = CreateDataRowRange(variableName, start, end, chartType);
    96         return rowSelect;
    97       } else
    98         return null;
    99     }
    100 
    101     public DataRow CreateDataRowRange(string variableName, int start, int end, DataRowVisualProperties.DataRowChartType chartType) {
    102       IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
    103       IList<double> valuesRange = new List<double>();
    104       for (int i = 0; i < values.Count; i++) {
    105         if (i >= start && i <= end)
    106           valuesRange.Add(values[i]);
    107         else
    108           valuesRange.Add(Double.NaN);
    109       }
    110 
    111       DataRow row = new DataRow(variableName, "", valuesRange);
    112       row.VisualProperties.ChartType = chartType;
    113       return row;
    114     }
    115 
    116     public List<DataRow> CreateAllSelectedDataRows(DataRowVisualProperties.DataRowChartType chartType) {
    117       List<DataRow> dataRows = new List<DataRow>();
    118       foreach (var name in PreprocessingData.GetDoubleVariableNames()) {
    119         DataRow row = CreateSelectedDataRow(name, chartType);
    120         if (row != null)
    121           dataRows.Add(row);
    122       }
    123       return dataRows;
    124     }
    125 
    126 
    127     public ICheckedItemList<StringValue> CreateVariableItemList(IList<string> checkedItems = null) {
    128       if (checkedItems == null) checkedItems = new string[0];
     83    private static ICheckedItemList<StringValue> CreateVariableItemList(IPreprocessingData preprocessingData) {
    12984      ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
    130       foreach (string name in PreprocessingData.GetDoubleVariableNames()) {
     85      foreach (string name in preprocessingData.GetDoubleVariableNames()) {
    13186        var n = new StringValue(name);
    132         itemList.Add(n, checkedItems.Contains(name));
     87        bool isInputTarget = preprocessingData.InputVariables.Contains(name) || preprocessingData.TargetVariable == name;
     88        itemList.Add(n, isInputTarget);
    13389      }
    13490      return new ReadOnlyCheckedItemList<StringValue>(itemList);
    13591    }
    13692
    137     public event DataPreprocessingChangedEventHandler Changed {
    138       add { PreprocessingData.Changed += value; }
    139       remove { PreprocessingData.Changed -= value; }
     93    public static IEnumerable<string> GetVariableNamesForGrouping(IPreprocessingData preprocessingData, int maxDistinctValues = 20) {
     94      var variableNames = new List<string>();
     95
     96      for (int i = 0; i < preprocessingData.Columns; ++i) {
     97        int distinctValues = Int32.MaxValue;
     98        if (preprocessingData.VariableHasType<double>(i))
     99          distinctValues = preprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
     100        else if (preprocessingData.VariableHasType<string>(i))
     101          distinctValues = preprocessingData.GetValues<string>(i).GroupBy(x => x).Count();
     102        else if (preprocessingData.VariableHasType<DateTime>(i))
     103          distinctValues = preprocessingData.GetValues<DateTime>(i).GroupBy(x => x).Count();
     104
     105        if (distinctValues <= maxDistinctValues)
     106          variableNames.Add(preprocessingData.GetVariableName(i));
     107      }
     108      return variableNames;
    140109    }
    141 
    142110  }
    143111}
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs

    r14186 r15242  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    23 using System.Drawing;
    2424using System.Linq;
    2525using HeuristicLab.Analysis;
    2626using HeuristicLab.Common;
    27 using HeuristicLab.Core;
     27using HeuristicLab.Visualization.ChartControlsExtensions;
    2828
    2929namespace HeuristicLab.DataPreprocessing {
    3030
    31   [Item("ScatterPlot", "Represents a scatter plot.")]
    32   public class ScatterPlotContent : PreprocessingChartContent {
     31  public abstract class ScatterPlotContent : PreprocessingChartContent {
     32    public string GroupingVariable { get; set; }
    3333
    34     public string SelectedXVariable { get; set; }
    35     public string SelectedYVariable { get; set; }
    36     public string SelectedColorVariable { get; set; }
    37 
    38     public ScatterPlotContent(IFilteredPreprocessingData preprocessingData)
     34    protected ScatterPlotContent(IFilteredPreprocessingData preprocessingData)
    3935      : base(preprocessingData) {
    4036    }
    4137
    42     public ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
     38    protected ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
    4339      : base(content, cloner) {
    44       this.SelectedXVariable = content.SelectedXVariable;
    45       this.SelectedYVariable = content.SelectedYVariable;
    46       this.SelectedColorVariable = content.SelectedColorVariable;
    4740    }
    4841
    49     public static new Image StaticItemImage {
    50       get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
    51     }
    52 
    53     public override IDeepCloneable Clone(Cloner cloner) {
    54       return new ScatterPlotContent(this, cloner);
    55     }
    56 
    57     public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameColor = "-") {
     42    public static ScatterPlot CreateScatterPlot(IFilteredPreprocessingData preprocessingData, string variableNameX, string variableNameY, string variableNameGroup = "-", LegendOrder legendOrder = LegendOrder.Alphabetically) {
    5843      ScatterPlot scatterPlot = new ScatterPlot();
    5944
    60       IList<double> xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));
    61       IList<double> yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));
    62       if (variableNameColor == null || variableNameColor == "-") {
    63         List<Point2D<double>> points = new List<Point2D<double>>();
     45      IList<double> xValues = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableNameX));
     46      IList<double> yValues = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableNameY));
    6447
    65         for (int i = 0; i < xValues.Count; i++) {
    66           Point2D<double> point = new Point2D<double>(xValues[i], yValues[i]);
    67           points.Add(point);
    68         }
     48      var points = xValues.Zip(yValues, (x, y) => new Point2D<double>(x, y)).ToList();
     49      var validPoints = points.Where(p => !double.IsNaN(p.X) && !double.IsNaN(p.Y) && !double.IsInfinity(p.X) && !double.IsInfinity(p.Y)).ToList();
     50      if (validPoints.Any()) {
     51        try {
     52          double axisMin, axisMax, axisInterval;
     53          ChartUtil.CalculateOptimalAxisInterval(validPoints.Min(p => p.X), validPoints.Max(p => p.X), out axisMin, out axisMax, out axisInterval);
     54          scatterPlot.VisualProperties.XAxisMinimumAuto = false;
     55          scatterPlot.VisualProperties.XAxisMaximumAuto = false;
     56          scatterPlot.VisualProperties.XAxisMinimumFixedValue = axisMin;
     57          scatterPlot.VisualProperties.XAxisMaximumFixedValue = axisMax;
     58        } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval
     59        try {
     60          double axisMin, axisMax, axisInterval;
     61          ChartUtil.CalculateOptimalAxisInterval(validPoints.Min(p => p.Y), validPoints.Max(p => p.Y), out axisMin, out axisMax, out axisInterval);
     62          scatterPlot.VisualProperties.YAxisMinimumAuto = false;
     63          scatterPlot.VisualProperties.YAxisMaximumAuto = false;
     64          scatterPlot.VisualProperties.YAxisMinimumFixedValue = axisMin;
     65          scatterPlot.VisualProperties.YAxisMaximumFixedValue = axisMax;
     66        } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval
     67      }
    6968
    70         ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
     69
     70      //No Grouping
     71      if (string.IsNullOrEmpty(variableNameGroup) || variableNameGroup == "-") {
     72        ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", validPoints);
     73        scdr.VisualProperties.IsVisibleInLegend = false;
    7174        scatterPlot.Rows.Add(scdr);
     75        return scatterPlot;
     76      }
    7277
    73       } else {
    74         var colorValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameColor));
    75         var data = xValues.Zip(yValues, (x, y) => new { x, y }).Zip(colorValues, (v, c) => new { v.x, v.y, c }).ToList();
    76         var gradients = ColorGradient.Colors;
    77         int curGradient = 0;
    78         int numColors = colorValues.Distinct().Count();
    79         foreach (var colorValue in colorValues.Distinct()) {
    80           var values = data.Where(x => x.c == colorValue);
    81           var row = new ScatterPlotDataRow(
    82             variableNameX + " - " + variableNameY + " (" + colorValue + ")",
    83             "",
    84             values.Select(v => new Point2D<double>(v.x, v.y)),
    85             new ScatterPlotDataRowVisualProperties() { Color = gradients[curGradient] });
    86           curGradient += gradients.Count / numColors;
    87           scatterPlot.Rows.Add(row);
    88         }
     78      //Grouping
     79      int groupVariableIndex = preprocessingData.GetColumnIndex(variableNameGroup);
     80      var groupingValues = Enumerable.Empty<string>();
     81
     82      if (preprocessingData.VariableHasType<double>(groupVariableIndex)) {
     83        groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString());
     84      } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) {
     85        groupingValues = preprocessingData.GetValues<string>(groupVariableIndex);
     86      } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) {
     87        groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString());
     88      }
     89      var groups = groupingValues.Zip(validPoints, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);
     90
     91      if (legendOrder == LegendOrder.Alphabetically)
     92        groups = groups.OrderBy(x => x.Key, new NaturalStringComparer());
     93
     94      foreach (var group in groups) {
     95        var scdr = new ScatterPlotDataRow {
     96          Name = group.Key,
     97          VisualProperties = {
     98            IsVisibleInLegend = true,
     99            PointSize = 6
     100          }
     101        };
     102        scdr.Points.AddRange(group);
     103        scatterPlot.Rows.Add(scdr);
    89104      }
    90105      return scatterPlot;
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/StatisticsContent.cs

    r14186 r15242  
    2727  [Item("Statistics", "Represents the statistics grid.")]
    2828  public class StatisticsContent : Item, IViewShortcut {
     29    public static new Image StaticItemImage {
     30      get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
     31    }
    2932
    30     private readonly StatisticsLogic statisticsLogic;
    31     public StatisticsContent(StatisticsLogic theStatisticsLogic) {
    32       statisticsLogic = theStatisticsLogic;
     33    public ITransactionalPreprocessingData PreprocessingData { get; private set; }
     34    public StatisticsLogic StatisticsLogic { get; private set; }
     35
     36    public StatisticsContent(ITransactionalPreprocessingData preProcessingData, StatisticsLogic statisticsLogic) {
     37      PreprocessingData = preProcessingData;
     38      StatisticsLogic = statisticsLogic;
    3339    }
    3440
    3541    public StatisticsContent(StatisticsContent content, Cloner cloner)
    3642      : base(content, cloner) {
    37 
    38     }
    39 
    40     public StatisticsLogic StatisticsLogic {
    41       get { return statisticsLogic; }
    42     }
    43 
    44     public static new Image StaticItemImage {
    45       get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
    4643    }
    4744
     
    5148
    5249    public event DataPreprocessingChangedEventHandler Changed {
    53       add { statisticsLogic.Changed += value; }
    54       remove { statisticsLogic.Changed -= value; }
     50      add { StatisticsLogic.Changed += value; }
     51      remove { StatisticsLogic.Changed -= value; }
    5552    }
    56 
    5753  }
    5854}
  • stable/HeuristicLab.DataPreprocessing/3.4/Content/TransformationContent.cs

    r14186 r15242  
    2828  [Item("Transformation", "Represents the transformation grid.")]
    2929  public class TransformationContent : Item, IViewShortcut {
     30    public static new Image StaticItemImage {
     31      get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; }
     32    }
    3033
    3134    public IPreprocessingData Data { get; private set; }
     
    3336
    3437    public ICheckedItemList<ITransformation> CheckedTransformationList { get; private set; }
    35 
    36     public static new Image StaticItemImage {
    37       get { return HeuristicLab.Common.Resources.VSImageLibrary.Method; }
    38     }
    3938
    4039    public TransformationContent(IPreprocessingData data, FilterLogic filterLogic) {
Note: See TracChangeset for help on using the changeset viewer.