- Timestamp:
- 11/22/19 10:06:42 (5 years ago)
- Location:
- branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r17180 r17364 142 142 else if (iter.Current[i] is string s) 143 143 transposed.Add(new List<string>() { s }); 144 else if (iter.Current[i] is IReadOnlyList<double> dv) 145 transposed.Add(new List<IReadOnlyList<double>>() { dv }); 144 146 else throw new NotSupportedException(string.Format("Variable {0} has type {1}. This is not supported when converting from row-wise data.", vnames[i], iter.Current[i].GetType())); 145 147 } … … 212 214 get { return variableValues.Where(p => p.Value is IList<double>).Select(p => p.Key); } 213 215 } 214 215 216 public IEnumerable<string> StringVariables { 216 217 get { return variableValues.Where(p => p.Value is IList<string>).Select(p => p.Key); } 217 218 } 218 219 219 public IEnumerable<string> DateTimeVariables { 220 220 get { return variableValues.Where(p => p.Value is IList<DateTime>).Select(p => p.Key); } 221 221 } 222 public IEnumerable<string> DoubleVectorVariables { 223 get { return variableValues.Where(p => p.Value is IList<IReadOnlyList<double>>).Select(p => p.Key); } 224 } 222 225 223 226 public IEnumerable<double> GetDoubleValues(string variableName) { … … 229 232 public IEnumerable<DateTime> GetDateTimeValues(string variableName) { 230 233 return GetValues<DateTime>(variableName); 234 } 235 public IEnumerable<IReadOnlyList<double>> GetDoubleVectorValues(string variableName) { 236 return GetValues<IReadOnlyList<double>>(variableName); 231 237 } 232 238 … … 247 253 return values[row]; 248 254 } 249 250 255 public IEnumerable<string> GetStringValues(string variableName, IEnumerable<int> rows) { 251 256 return GetValues<string>(variableName, rows); … … 267 272 return new ReadOnlyCollection<DateTime>(values); 268 273 } 274 275 public IReadOnlyList<double> GetDoubleVectorValue(string variableName, int row) { 276 var values = GetValues<IReadOnlyList<double>>(variableName); 277 return values[row]; 278 } 279 public IEnumerable<IReadOnlyList<double>> GetDoubleVectorValues(string variableName, IEnumerable<int> rows) { 280 return GetValues<IReadOnlyList<double>>(variableName, rows); 281 } 282 public ReadOnlyCollection<IReadOnlyList<double>> GetReadOnlyDoubleVectorValues(string variableName) { 283 var values = GetValues<IReadOnlyList<double>>(variableName); 284 return new ReadOnlyCollection<IReadOnlyList<double>>(values); 285 } 286 269 287 private IEnumerable<T> GetValues<T>(string variableName, IEnumerable<int> rows) { 270 288 var values = GetValues<T>(variableName); … … 298 316 } 299 317 protected static bool IsAllowedType(Type type) { 300 return type == typeof(double) || type == typeof(string) || type == typeof(DateTime) ;318 return type == typeof(double) || type == typeof(string) || type == typeof(DateTime) || type == typeof(IReadOnlyList<double>); 301 319 } 302 320 … … 343 361 if (dateTimeValues != null) return new List<DateTime>(dateTimeValues); 344 362 363 var doubleVectorValues = values as IList<IReadOnlyList<double>>; 364 if (doubleVectorValues != null) return doubleVectorValues.Select(x => new List<double>(x)).Cast<IReadOnlyList<double>>().ToList(); 365 345 366 throw new ArgumentException(string.Format("Unsupported variable type {0}.", GetElementType(values))); 346 367 } … … 381 402 } 382 403 string IStringConvertibleMatrix.GetValue(int rowIndex, int columnIndex) { 404 var value = variableValues[variableNames[columnIndex]][rowIndex]; 405 if (value is IReadOnlyList<double> doubleVector) 406 return $"[{string.Join(", ", doubleVector)}]"; 383 407 return variableValues[variableNames[columnIndex]][rowIndex].ToString(); 384 408 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r17180 r17364 158 158 if (allowedInputVariables == null) throw new ArgumentNullException("The allowed input variables must not be null."); 159 159 160 if (allowedInputVariables.Except(dataset.DoubleVariables).Except(dataset.StringVariables).Any()) 161 throw new ArgumentException("All allowed input variables must be present in the dataset and of type double or string."); 162 163 var variables = dataset.VariableNames.Where(variable => dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable)); 160 if (allowedInputVariables.Except(dataset.DoubleVariables).Except(dataset.StringVariables).Except(dataset.DoubleVectorVariables).Any()) 161 throw new ArgumentException("All allowed input variables must be present in the dataset and of type double, string or double-vector."); 162 163 var variables = dataset.VariableNames.Where(variable => 164 dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable) || dataset.VariableHasType<IReadOnlyList<double>>(variable)); 164 165 var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x).AsReadOnly())); 165 166 foreach (StringValue x in inputVariables) -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataset.cs
r17180 r17364 34 34 IEnumerable<string> StringVariables { get; } 35 35 IEnumerable<string> DateTimeVariables { get; } 36 IEnumerable<string> DoubleVectorVariables { get; } 36 37 37 38 bool ContainsVariable(string variablename); … … 48 49 ReadOnlyCollection<string> GetReadOnlyStringValues(string VariableName); 49 50 50 System.DateTime GetDateTimeValue(string variableName, int row);51 DateTime GetDateTimeValue(string variableName, int row); 51 52 IEnumerable<DateTime> GetDateTimeValues(string variableName); 52 53 IEnumerable<DateTime> GetDateTimeValues(string variableName, IEnumerable<int> rows); 53 54 ReadOnlyCollection<DateTime> GetReadOnlyDateTimeValues(string variableName); 55 56 IReadOnlyList<double> GetDoubleVectorValue(string variableName, int row); 57 IEnumerable<IReadOnlyList<double>> GetDoubleVectorValues(string variableName); 58 IEnumerable<IReadOnlyList<double>> GetDoubleVectorValues(string variableName, IEnumerable<int> rows); 59 ReadOnlyCollection<IReadOnlyList<double>> GetReadOnlyDoubleVectorValues(string variableName); 54 60 } 55 61 }
Note: See TracChangeset
for help on using the changeset viewer.