Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingData.cs @ 10185

Last change on this file since 10185 was 10185, checked in by pfleck, 10 years ago

Implemented constructors of PreprocessingData.

File size: 5.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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;
23using System.Collections;
24using System.Collections.Generic;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.DataPreprocessing;
29using HeuristicLab.Problems.DataAnalysis;
30
31namespace HeuristicLab.DataPreprocessing {
32  [Item("PreprocessingData", "Represents data used for preprocessing.")]
33  public class PreprocessingData : NamedItem, IPreprocessingData {
34
35    private IDictionary<string, IList> variableValues;
36
37    private IDictionary<string, int> variableNameIndices;
38
39    private double trainingToTestRatio;
40
41    private PreprocessingData(PreprocessingData original, Cloner cloner)
42      : base(original, cloner) {
43      variableValues = new Dictionary<string, IList>(variableValues);
44      variableNameIndices = new Dictionary<string, int>(variableNameIndices);
45    }
46   
47    public PreprocessingData(IDataAnalysisProblemData problemData)
48      : base() {
49      Name = "-";
50
51      // create dictionary from variable name to index
52      variableNameIndices = new Dictionary<string, int>();
53      var variableNamesList = problemData.Dataset.VariableNames.ToList();
54      for (int i = 0; i < variableNamesList.Count; i++) {
55        variableNameIndices.Add(variableNamesList[i], i);
56      }
57     
58      // copy values
59      variableValues = new Dictionary<string, IList>();
60      foreach (var variableName in problemData.Dataset.VariableNames) {
61        if (problemData.Dataset.IsType<double>(variableName)) {
62          variableValues[variableName] = problemData.Dataset.GetDoubleValues(variableName).ToList();
63        } else if (problemData.Dataset.IsType<string>(variableName)) {
64          variableValues[variableName] = CreateColumn<string>(problemData.Dataset, variableNameIndices[variableName], x => x);
65        } else if (problemData.Dataset.IsType<DateTime>(variableName)) {
66          variableValues[variableName] = CreateColumn<DateTime>(problemData.Dataset, variableNameIndices[variableName], x => DateTime.Parse(x));
67        } else {
68          throw new ArgumentException("The datatype of column " + variableName + " must be of type List<double>, List<string> or List<DateTime>");
69        }
70      }
71
72      trainingToTestRatio = (double)problemData.TrainingPartition.Size / problemData.TestPartition.Size;
73    }
74
75    private static IList CreateColumn<T>(Dataset ds, int column, Func<string, T> selector) {
76      var list = new List<T>(ds.Rows);
77      for (int row = 0; row < ds.Rows; row++) {
78        list[row] = selector(ds.GetValue(row, column));
79      }
80      return list;
81    }
82
83    #region NamedItem abstract Member Implementations
84
85    public override IDeepCloneable Clone(Cloner cloner) {
86      return new PreprocessingData(this, cloner);
87    }
88
89    #endregion
90
91    #region IPreprocessingData Members
92
93    public T GetCell<T>(int columnIndex, int rowIndex) {
94      throw new NotImplementedException();
95    }
96
97    public void SetCell<T>(int columnIndex, int rowIndex, T value) {
98      throw new NotImplementedException();
99    }
100
101    public T GetCell<T>(string variableName, int row) {
102      throw new NotImplementedException();
103    }
104
105    public void SetCell<T>(string variableName, int row, T value) {
106      throw new NotImplementedException();
107    }
108
109    public IEnumerable<T> GetValues<T>(int columnIndex) {
110      throw new NotImplementedException();
111    }
112
113    public IEnumerable<T> GetValues<T>(string variableName) {
114      throw new NotImplementedException();
115    }
116
117    public void SetValues<T>(int columnIndex, IEnumerable<T> values) {
118      throw new NotImplementedException();
119    }
120
121    public void SetValues<T>(string variableName, IEnumerable<T> values) {
122      throw new NotImplementedException();
123    }
124
125    public void InsertRow(int rowIndex) {
126      throw new NotImplementedException();
127    }
128
129    public void DeleteRow(int rowIndex) {
130      throw new NotImplementedException();
131    }
132
133    public void InsertColumn(string variableName, int columnIndex) {
134      throw new NotImplementedException();
135    }
136
137    public void DeleteColumn(int columnIndex) {
138      throw new NotImplementedException();
139    }
140
141    public void DeleteColumn(string variableName) {
142      throw new NotImplementedException();
143    }
144
145    IEnumerable<string> IPreprocessingData.VariableNames {
146      get { throw new NotImplementedException(); }
147    }
148
149    public bool IsType<T>(int columnIndex) {
150      throw new NotImplementedException();
151    }
152
153    public bool IsType<T>(string variableName) {
154      throw new NotImplementedException();
155    }
156
157    public int Columns {
158      get { throw new NotImplementedException(); }
159    }
160
161    public int Rows {
162      get { throw new NotImplementedException(); }
163    }
164
165    public void ExportTo(IDataAnalysisProblemData problemData) {
166      throw new NotImplementedException();
167    }
168
169    #endregion
170  }
171}
Note: See TracBrowser for help on using the repository browser.