- Timestamp:
- 11/22/19 13:23:49 (5 years ago)
- Location:
- branches/3040_VectorBasedGP
- Files:
-
- 6 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r17364 r17365 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 else if (iter.Current[i] is DoubleVector dv) 145 transposed.Add(new List<DoubleVector>() { dv }); 146 else if (iter.Current[i] is StringVector sv) 147 transposed.Add(new List<StringVector>() { sv }); 148 else if (iter.Current[i] is DateTimeVector dtv) 149 transposed.Add(new List<DateTimeVector>() { dtv }); 146 150 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())); 147 151 } … … 221 225 } 222 226 public IEnumerable<string> DoubleVectorVariables { 223 get { return variableValues.Where(p => p.Value is IList<IReadOnlyList<double>>).Select(p => p.Key); } 227 get { return variableValues.Where(p => p.Value is IList<DoubleVector>).Select(p => p.Key); } 228 } 229 public IEnumerable<string> StringVectorVariables { 230 get { return variableValues.Where(p => p.Value is IList<StringVector>).Select(p => p.Key); } 231 } 232 public IEnumerable<string> DateTimeVectorVariables { 233 get { return variableValues.Where(p => p.Value is IList<DateTimeVector>).Select(p => p.Key); } 224 234 } 225 235 … … 233 243 return GetValues<DateTime>(variableName); 234 244 } 235 public IEnumerable<IReadOnlyList<double>> GetDoubleVectorValues(string variableName) { 236 return GetValues<IReadOnlyList<double>>(variableName); 245 public IEnumerable<DoubleVector> GetDoubleVectorValues(string variableName) { 246 return GetValues<DoubleVector>(variableName); 247 } 248 public IEnumerable<StringVector> GetStringVectorValues(string variableName) { 249 return GetValues<StringVector>(variableName); 250 } 251 public IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName) { 252 return GetValues<DateTimeVector>(variableName); 237 253 } 238 254 … … 273 289 } 274 290 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); 291 public DoubleVector GetDoubleVectorValue(string variableName, int row) { 292 var values = GetValues<DoubleVector>(variableName); 293 return values[row]; 294 } 295 public IEnumerable<DoubleVector> GetDoubleVectorValues(string variableName, IEnumerable<int> rows) { 296 return GetValues<DoubleVector>(variableName, rows); 297 } 298 public ReadOnlyCollection<DoubleVector> GetReadOnlyDoubleVectorValues(string variableName) { 299 var values = GetValues<DoubleVector>(variableName); 300 return new ReadOnlyCollection<DoubleVector>(values); 301 } 302 303 public StringVector GetStringVectorValue(string variableName, int row) { 304 var values = GetValues<StringVector>(variableName); 305 return values[row]; 306 } 307 public IEnumerable<StringVector> GetStringVectorValues(string variableName, IEnumerable<int> rows) { 308 return GetValues<StringVector>(variableName, rows); 309 } 310 public ReadOnlyCollection<StringVector> GetReadOnlyStringVectorValues(string variableName) { 311 var values = GetValues<StringVector>(variableName); 312 return new ReadOnlyCollection<StringVector>(values); 313 } 314 315 public DateTimeVector GetDateTimeVectorValue(string variableName, int row) { 316 var values = GetValues<DateTimeVector>(variableName); 317 return values[row]; 318 } 319 public IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName, IEnumerable<int> rows) { 320 return GetValues<DateTimeVector>(variableName, rows); 321 } 322 public ReadOnlyCollection<DateTimeVector> GetReadOnlyDateTimeVectorValues(string variableName) { 323 var values = GetValues<DateTimeVector>(variableName); 324 return new ReadOnlyCollection<DateTimeVector>(values); 285 325 } 286 326 … … 316 356 } 317 357 protected static bool IsAllowedType(Type type) { 318 return type == typeof(double) || type == typeof(string) || type == typeof(DateTime) || type == typeof(IReadOnlyList<double>); 358 return type == typeof(double) || type == typeof(string) || type == typeof(DateTime) 359 || type == typeof(DoubleVector) || type == typeof(StringVector) || type == typeof(DateTimeVector); 319 360 } 320 361 … … 361 402 if (dateTimeValues != null) return new List<DateTime>(dateTimeValues); 362 403 363 var doubleVectorValues = values as IList<IReadOnlyList<double>>; 364 if (doubleVectorValues != null) return doubleVectorValues.Select(x => new List<double>(x)).Cast<IReadOnlyList<double>>().ToList(); 404 var doubleVectorValues = values as IList<DoubleVector>; 405 if (doubleVectorValues != null) return doubleVectorValues.Select(x => new DoubleVector(x)).ToList(); 406 407 var stringVectorValues = values as IList<StringVector>; 408 if (stringVectorValues != null) return stringVectorValues.Select(x => new StringVector(x)).ToList(); 409 410 var dateTimeVectorValues = values as IList<DateTimeVector>; 411 if (dateTimeVectorValues != null) return dateTimeVectorValues.Select(x => new DateTimeVector(x)).ToList(); 365 412 366 413 throw new ArgumentException(string.Format("Unsupported variable type {0}.", GetElementType(values))); … … 403 450 string IStringConvertibleMatrix.GetValue(int rowIndex, int columnIndex) { 404 451 var value = variableValues[variableNames[columnIndex]][rowIndex]; 405 if (value is I ReadOnlyList<double> doubleVector)406 return $"[{string.Join(", ", doubleVector)}]";407 return va riableValues[variableNames[columnIndex]][rowIndex].ToString();452 if (value is IVector vector) 453 return $"[{string.Join(", ", vector.Cast<object>())}]"; 454 return value.ToString(); 408 455 } 409 456 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r16788 r17365 167 167 <Compile Include="Implementation\Transformations\ShiftToRangeTransformation.cs" /> 168 168 <Compile Include="Implementation\Transformations\Transformation.cs" /> 169 <Compile Include="Implementation\Vectors\DateTimeVector.cs" /> 170 <Compile Include="Implementation\Vectors\StringVector.cs" /> 171 <Compile Include="Implementation\Vectors\DoubleVector.cs" /> 172 <Compile Include="Implementation\Vectors\Vector.cs" /> 169 173 <Compile Include="Interfaces\Classification\IClassificationEnsembleModel.cs"> 170 174 <SubType>Code</SubType> … … 179 183 <Compile Include="Interfaces\ITransformation.cs" /> 180 184 <Compile Include="Interfaces\ITransformationMapper.cs" /> 185 <Compile Include="Interfaces\IVector.cs" /> 181 186 <Compile Include="Interfaces\Regression\IConfidenceRegressionModel.cs" /> 182 187 <Compile Include="Interfaces\Regression\IConfidenceRegressionSolution.cs" /> -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r17364 r17365 162 162 163 163 var variables = dataset.VariableNames.Where(variable => 164 dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable) || dataset.VariableHasType< IReadOnlyList<double>>(variable));164 dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable) || dataset.VariableHasType<DoubleVector> (variable)); 165 165 var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x).AsReadOnly())); 166 166 foreach (StringValue x in inputVariables) -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataset.cs
r17364 r17365 35 35 IEnumerable<string> DateTimeVariables { get; } 36 36 IEnumerable<string> DoubleVectorVariables { get; } 37 IEnumerable<string> StringVectorVariables { get; } 38 IEnumerable<string> DateTimeVectorVariables { get; } 37 39 38 40 bool ContainsVariable(string variablename); … … 54 56 ReadOnlyCollection<DateTime> GetReadOnlyDateTimeValues(string variableName); 55 57 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); 58 DoubleVector GetDoubleVectorValue(string variableName, int row); 59 IEnumerable<DoubleVector> GetDoubleVectorValues(string variableName); 60 IEnumerable<DoubleVector> GetDoubleVectorValues(string variableName, IEnumerable<int> rows); 61 ReadOnlyCollection<DoubleVector> GetReadOnlyDoubleVectorValues(string variableName); 62 63 StringVector GetStringVectorValue(string variableName, int row); 64 IEnumerable<StringVector> GetStringVectorValues(string variableName); 65 IEnumerable<StringVector> GetStringVectorValues(string variableName, IEnumerable<int> rows); 66 ReadOnlyCollection<StringVector> GetReadOnlyStringVectorValues(string variableName); 67 68 DateTimeVector GetDateTimeVectorValue(string variableName, int row); 69 IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName); 70 IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName, IEnumerable<int> rows); 71 ReadOnlyCollection<DateTimeVector> GetReadOnlyDateTimeVectorValues(string variableName); 60 72 } 61 73 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VectorData/VectorDataTestOne.cs
r17364 r17365 24 24 using System.Collections.Generic; 25 25 using System.Linq; 26 using System.Runtime.Remoting.Messaging;27 26 using HeuristicLab.Core; 27 using HeuristicLab.Problems.DataAnalysis; 28 28 using HeuristicLab.Random; 29 29 … … 57 57 58 58 double x1, x2, x3; 59 IReadOnlyList<double>v1, v2;59 DoubleVector v1, v2; 60 60 double y; 61 61 … … 63 63 var x2Column = new List<double>(100); 64 64 var x3Column = new List<double>(100); 65 var v1Column = new List< IReadOnlyList<double>>(100);66 var v2Column = new List< IReadOnlyList<double>>(100);65 var v1Column = new List<DoubleVector>(100); 66 var v2Column = new List<DoubleVector>(100); 67 67 var yColumn = new List<double>(100); 68 68 … … 91 91 return (max - min) * rand.NextDouble() + min; 92 92 } 93 private static double[]GetRandomDoubleVector(double min, double max, int length, IRandom rand) {93 private static DoubleVector GetRandomDoubleVector(double min, double max, int length, IRandom rand) { 94 94 var values = new double[length]; 95 95 for (int i = 0; i < values.Length; i++) { 96 96 values[i] = GetRandomDouble(min, max, rand); 97 97 } 98 return values;98 return new DoubleVector(values); 99 99 } 100 100 }
Note: See TracChangeset
for help on using the changeset viewer.