[10539] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10539] | 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 |
|
---|
[10992] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[10539] | 24 | using System.Drawing;
|
---|
[15110] | 25 | using System.Linq;
|
---|
[10992] | 26 | using HeuristicLab.Analysis;
|
---|
[10539] | 27 | using HeuristicLab.Common;
|
---|
[15110] | 28 | using HeuristicLab.Common.Resources;
|
---|
[10245] | 29 | using HeuristicLab.Core;
|
---|
[10818] | 30 | using HeuristicLab.Data;
|
---|
[10242] | 31 |
|
---|
[10539] | 32 | namespace HeuristicLab.DataPreprocessing {
|
---|
[10658] | 33 | [Item("PreprocessingChart", "Represents a preprocessing chart.")]
|
---|
[15110] | 34 | public class PreprocessingChartContent : Item, IViewShortcut {
|
---|
| 35 | public enum LegendOrder {
|
---|
[15210] | 36 | Alphabetically,
|
---|
| 37 | Appearance
|
---|
[10992] | 38 | }
|
---|
[10252] | 39 |
|
---|
[15110] | 40 | public static new Image StaticItemImage {
|
---|
| 41 | get { return VSImageLibrary.PieChart; }
|
---|
[10992] | 42 | }
|
---|
[10818] | 43 |
|
---|
| 44 | private ICheckedItemList<StringValue> variableItemList = null;
|
---|
[10992] | 45 | public ICheckedItemList<StringValue> VariableItemList {
|
---|
[15110] | 46 | get {
|
---|
| 47 | if (variableItemList == null)
|
---|
| 48 | variableItemList = CreateVariableItemList(PreprocessingData);
|
---|
| 49 | return this.variableItemList;
|
---|
| 50 | }
|
---|
[10992] | 51 | }
|
---|
[10818] | 52 |
|
---|
[10992] | 53 | public IFilteredPreprocessingData PreprocessingData { get; private set; }
|
---|
[15110] | 54 | public event DataPreprocessingChangedEventHandler Changed {
|
---|
| 55 | add { PreprocessingData.Changed += value; }
|
---|
| 56 | remove { PreprocessingData.Changed -= value; }
|
---|
| 57 | }
|
---|
[10818] | 58 |
|
---|
[10992] | 59 | public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
|
---|
| 60 | PreprocessingData = preprocessingData;
|
---|
[10252] | 61 | }
|
---|
| 62 |
|
---|
[10658] | 63 | public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
|
---|
[10539] | 64 | : base(content, cloner) {
|
---|
[10995] | 65 | this.PreprocessingData = content.PreprocessingData;
|
---|
[10992] | 66 | this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
|
---|
[10245] | 67 | }
|
---|
[10992] | 68 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 69 | return new PreprocessingChartContent(this, cloner);
|
---|
| 70 | }
|
---|
[10245] | 71 |
|
---|
[10992] | 72 | public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
|
---|
[15110] | 73 | return CreateDataRow(PreprocessingData, variableName, chartType);
|
---|
[10252] | 74 | }
|
---|
| 75 |
|
---|
[15110] | 76 | public static DataRow CreateDataRow(IFilteredPreprocessingData preprocessingData, string variableName, DataRowVisualProperties.DataRowChartType chartType) {
|
---|
| 77 | IList<double> values = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableName));
|
---|
| 78 | DataRow row = new DataRow(variableName, "", values);
|
---|
[10992] | 79 | row.VisualProperties.ChartType = chartType;
|
---|
| 80 | return row;
|
---|
[10573] | 81 | }
|
---|
[10818] | 82 |
|
---|
[15110] | 83 | private static ICheckedItemList<StringValue> CreateVariableItemList(IPreprocessingData preprocessingData) {
|
---|
[10992] | 84 | ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
|
---|
[15110] | 85 | foreach (string name in preprocessingData.GetDoubleVariableNames()) {
|
---|
[12676] | 86 | var n = new StringValue(name);
|
---|
[15110] | 87 | bool isInputTarget = preprocessingData.InputVariables.Contains(name) || preprocessingData.TargetVariable == name;
|
---|
| 88 | itemList.Add(n, isInputTarget);
|
---|
[10992] | 89 | }
|
---|
| 90 | return new ReadOnlyCheckedItemList<StringValue>(itemList);
|
---|
[10818] | 91 | }
|
---|
[10992] | 92 |
|
---|
[15210] | 93 | public static IEnumerable<string> GetVariableNamesForGrouping(IPreprocessingData preprocessingData, int maxDistinctValues = 20) {
|
---|
[15110] | 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 |
|
---|
[15210] | 105 | if (distinctValues <= maxDistinctValues)
|
---|
[15110] | 106 | variableNames.Add(preprocessingData.GetVariableName(i));
|
---|
| 107 | }
|
---|
| 108 | return variableNames;
|
---|
[10992] | 109 | }
|
---|
[10242] | 110 | }
|
---|
| 111 | }
|
---|