Changeset 13083 for branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
- Timestamp:
- 10/29/15 18:33:51 (8 years ago)
- Location:
- branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r10553 r13083 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 33 33 [Item("Dataset", "Represents a dataset containing data that should be analyzed.")] 34 34 [StorableClass] 35 public sealed class Dataset : NamedItem, IStringConvertibleMatrix{35 public class Dataset : NamedItem, IDataset { 36 36 [StorableConstructor] 37 pr ivateDataset(bool deserializing) : base(deserializing) { }38 pr ivateDataset(Dataset original, Cloner cloner)37 protected Dataset(bool deserializing) : base(deserializing) { } 38 protected Dataset(Dataset original, Cloner cloner) 39 39 : base(original, cloner) { 40 40 variableValues = new Dictionary<string, IList>(original.variableValues); … … 118 118 } 119 119 120 protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { } 121 120 122 #region Backwards compatible code, remove with 3.5 121 123 private double[,] storableData; … … 143 145 144 146 [Storable(Name = "VariableValues")] 145 pr ivateDictionary<string, IList> variableValues;146 147 pr ivateList<string> variableNames;147 protected Dictionary<string, IList> variableValues; 148 149 protected List<string> variableNames; 148 150 [Storable] 149 151 public IEnumerable<string> VariableNames { 150 152 get { return variableNames; } 151 pr ivateset {153 protected set { 152 154 if (variableNames != null) throw new InvalidOperationException(); 153 155 variableNames = new List<string>(value); 154 156 } 155 157 } 156 157 158 public IEnumerable<string> DoubleVariables { 158 159 get { return variableValues.Where(p => p.Value is List<double>).Select(p => p.Key); } 159 160 } 160 161 161 public IEnumerable<double> GetDoubleValues(string variableName) { 162 return GetValues<double>(variableName); 163 } 164 public IEnumerable<string> GetStringValues(string variableName) { 165 return GetValues<string>(variableName); 166 } 167 public IEnumerable<DateTime> GetDateTimeValues(string variableName) { 168 return GetValues<DateTime>(variableName); 169 } 170 171 public ReadOnlyCollection<double> GetReadOnlyDoubleValues(string variableName) { 172 var values = GetValues<double>(variableName); 173 return values.AsReadOnly(); 174 } 175 public double GetDoubleValue(string variableName, int row) { 176 var values = GetValues<double>(variableName); 177 return values[row]; 178 } 179 public IEnumerable<double> GetDoubleValues(string variableName, IEnumerable<int> rows) { 180 return GetValues<double>(variableName, rows); 181 } 182 private IEnumerable<T> GetValues<T>(string variableName, IEnumerable<int> rows) { 183 var values = GetValues<T>(variableName); 184 return rows.Select(x => values[x]); 185 } 186 private List<T> GetValues<T>(string variableName) { 162 187 IList list; 163 188 if (!variableValues.TryGetValue(variableName, out list)) 164 189 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 165 List<double> values = list as List<double>; 166 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 167 168 //mkommend yield return used to enable lazy evaluation 169 foreach (double value in values) 170 yield return value; 171 } 172 public ReadOnlyCollection<double> GetReadOnlyDoubleValues(string variableName) { 173 IList list; 174 if (!variableValues.TryGetValue(variableName, out list)) 175 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 176 List<double> values = list as List<double>; 177 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 178 return values.AsReadOnly(); 179 } 180 public double GetDoubleValue(string variableName, int row) { 181 IList list; 182 if (!variableValues.TryGetValue(variableName, out list)) 183 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 184 List<double> values = list as List<double>; 185 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 186 return values[row]; 187 } 188 public IEnumerable<double> GetDoubleValues(string variableName, IEnumerable<int> rows) { 189 IList list; 190 if (!variableValues.TryGetValue(variableName, out list)) 191 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 192 List<double> values = list as List<double>; 193 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 194 195 return rows.Select(index => values[index]); 190 List<T> values = list as List<T>; 191 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a " + typeof(T) + " variable."); 192 return values; 193 } 194 public bool VariableHasType<T>(string variableName) { 195 return variableValues[variableName] is IList<T>; 196 196 } 197 197 198 198 #region IStringConvertibleMatrix Members 199 199 [Storable] 200 pr ivateint rows;200 protected int rows; 201 201 public int Rows { 202 202 get { return rows; } … … 207 207 set { throw new NotSupportedException(); } 208 208 } 209 210 209 public bool SortableView { 211 210 get { return false; } … … 215 214 get { return true; } 216 215 } 217 218 216 IEnumerable<string> IStringConvertibleMatrix.ColumnNames { 219 217 get { return this.VariableNames; } … … 224 222 set { throw new NotSupportedException(); } 225 223 } 226 227 224 public string GetValue(int rowIndex, int columnIndex) { 228 225 return variableValues[variableNames[columnIndex]][rowIndex].ToString(); 229 226 } 230 public boolSetValue(string value, int rowIndex, int columnIndex) {227 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 231 228 throw new NotSupportedException(); 232 229 } 233 public boolValidate(string value, out string errorMessage) {230 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 234 231 throw new NotSupportedException(); 235 232 } 236 233 237 public event EventHandler ColumnsChanged { add { } remove { } }238 public event EventHandler RowsChanged { add { } remove { } }239 public event EventHandler ColumnNamesChanged { add { } remove { } }240 public event EventHandler RowNamesChanged { add { } remove { } }241 public event EventHandler SortableViewChanged { add { } remove { } }242 public event EventHandler<EventArgs<int, int>> ItemChanged { add { } remove { } }243 public event EventHandler Reset { add { } remove { } }234 public virtual event EventHandler ColumnsChanged { add { } remove { } } 235 public virtual event EventHandler RowsChanged { add { } remove { } } 236 public virtual event EventHandler ColumnNamesChanged { add { } remove { } } 237 public virtual event EventHandler RowNamesChanged { add { } remove { } } 238 public virtual event EventHandler SortableViewChanged { add { } remove { } } 239 public virtual event EventHandler<EventArgs<int, int>> ItemChanged { add { } remove { } } 240 public virtual event EventHandler Reset { add { } remove { } } 244 241 #endregion 245 242 }
Note: See TracChangeset
for help on using the changeset viewer.