Changeset 10978 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs
- Timestamp:
- 06/11/14 12:36:39 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs
r10842 r10978 33 33 34 34 [Item("PreprocessingData", "Represents data used for preprocessing.")] 35 public class PreprocessingData : NamedItem, IPreprocessingData { 35 public abstract class PreprocessingData : NamedItem, IPreprocessingData { 36 37 protected double trainingToTestRatio; 38 public IntRange TrainingPartition { 39 get { return new IntRange(0, (int)(Rows * trainingToTestRatio)); } 40 } 41 public IntRange TestPartition { 42 get { return new IntRange((int)(Rows * trainingToTestRatio), Rows); } 43 } 44 45 protected IList<ITransformation> transformations; 46 public IList<ITransformation> Transformations { 47 get { return transformations; } 48 } 36 49 37 50 protected IList<IList> variableValues; 38 39 51 protected IList<string> variableNames; 40 52 41 protected double trainingToTestRatio; 42 43 protected IList<ITransformation> transformations; 44 45 protected IDictionary<int, IList<int>> currentSelection; 53 public IEnumerable<string> VariableNames { 54 get { return variableNames; } 55 } 56 57 public int Columns { 58 get { return variableNames.Count; } 59 } 60 61 public int Rows { 62 get { return variableValues.Count > 0 ? variableValues[0].Count : 0; } 63 } 64 65 protected IDictionary<int, IList<int>> selection; 66 public IDictionary<int, IList<int>> Selection { 67 get { return selection; } 68 set { 69 selection = value; 70 OnSelectionChanged(); 71 } 72 } 46 73 47 74 protected PreprocessingData(PreprocessingData original, Cloner cloner) … … 53 80 } 54 81 55 p ublicPreprocessingData(IDataAnalysisProblemData problemData)82 protected PreprocessingData(IDataAnalysisProblemData problemData) 56 83 : base() { 57 84 Name = "Preprocessing Data"; 58 85 59 86 transformations = new List<ITransformation>(); 60 currentSelection = new Dictionary<int, IList<int>>();87 selection = new Dictionary<int, IList<int>>(); 61 88 62 89 variableNames = new List<string>(problemData.Dataset.VariableNames); 63 // create dictionary from variable name to index64 90 65 91 int columnIndex = 0; … … 73 99 variableValues.Insert(columnIndex, CreateColumn<DateTime>(problemData.Dataset, columnIndex, x => DateTime.Parse(x))); 74 100 } else { 75 throw new ArgumentException("The datatype of column " + variableName + " must be of type List<double>, List<string> or List<DateTime>");101 throw new ArgumentException("The datatype of column " + variableName + " must be of type double, string or DateTime"); 76 102 } 77 103 ++columnIndex; … … 97 123 } 98 124 99 #region NamedItem abstract Member Implementations100 101 public override IDeepCloneable Clone(Cloner cloner) {102 return new PreprocessingData(this, cloner);103 }104 105 #endregion106 125 107 126 #region IPreprocessingData Members … … 111 130 } 112 131 113 114 132 public virtual void SetCell<T>(int columnIndex, int rowIndex, T value) { 115 133 variableValues[columnIndex][rowIndex] = value; 116 134 } 117 135 118 119 136 public string GetCellAsString(int columnIndex, int rowIndex) { 120 137 return variableValues[columnIndex][rowIndex].ToString(); 121 138 } 122 139 140 public string GetVariableName(int columnIndex) { 141 return variableNames[columnIndex]; 142 } 143 144 public int GetColumnIndex(string variableName) { 145 return variableNames.IndexOf(variableName); 146 } 147 148 public bool IsType<T>(int columnIndex) { 149 return variableValues[columnIndex] is List<T>; 150 } 123 151 124 152 [Obsolete("use the index based variant, is faster")] … … 130 158 if (considerSelection) { 131 159 var list = new List<T>(); 132 foreach (var rowIdx in currentSelection[columnIndex]) {160 foreach (var rowIdx in selection[columnIndex]) { 133 161 list.Add((T)variableValues[columnIndex][rowIdx]); 134 162 } … … 170 198 } 171 199 172 public IntRange TrainingPartition {173 get { return new IntRange(0, (int)(Rows * trainingToTestRatio)); }174 }175 176 public IntRange TestPartition {177 get { return new IntRange((int)(Rows * trainingToTestRatio), Rows); }178 }179 180 public IList<ITransformation> Transformations {181 get { return transformations; }182 }183 184 public string GetVariableName(int columnIndex) {185 return variableNames[columnIndex];186 }187 188 public IEnumerable<string> VariableNames {189 get { return variableNames; }190 }191 192 public int GetColumnIndex(string variableName) {193 return variableNames.IndexOf(variableName);194 }195 196 public bool IsType<T>(int columnIndex) {197 return variableValues[columnIndex] is List<T>;198 }199 200 public int Columns {201 get { return variableNames.Count; }202 }203 204 public int Rows {205 get { return variableValues.Count > 0 ? variableValues[0].Count : 0; }206 }207 208 200 public Dataset ExportToDataset() { 209 201 IList<IList> values = new List<IList>(); … … 217 209 } 218 210 219 public void SetSelection(IDictionary<int, IList<int>> selection) {220 currentSelection = selection;221 if (SelectionChanged != null) {222 SelectionChanged(this, new EventArgs());223 }224 }225 226 public IDictionary<int, IList<int>> GetSelection() {227 return currentSelection;228 }229 230 211 public void ClearSelection() { 231 currentSelection = new Dictionary<int, IList<int>>();212 Selection = new Dictionary<int, IList<int>>(); 232 213 } 233 214 234 215 public event EventHandler SelectionChanged; 235 216 protected virtual void OnSelectionChanged() { 217 var listeners = SelectionChanged; 218 if (listeners != null) listeners(this, EventArgs.Empty); 219 } 220 221 public event DataPreprocessingChangedEventHandler Changed; 222 protected virtual void OnChanged(DataPreprocessingChangedEventType type, int column, int row) { 223 var listeners = Changed; 224 if (listeners != null) listeners(this, new DataPreprocessingChangedEventArgs(type, column, row)); 225 } 236 226 #endregion 237 227 }
Note: See TracChangeset
for help on using the changeset viewer.