Changeset 17364
- Timestamp:
- 11/22/19 10:06:42 (5 years ago)
- Location:
- branches/3040_VectorBasedGP
- Files:
-
- 2 added
- 5 edited
- 1 copied
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 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj
r16658 r17364 24 24 <WarningLevel>4</WarningLevel> 25 25 <Prefer32Bit>false</Prefer32Bit> 26 <LangVersion> 5</LangVersion>26 <LangVersion>6</LangVersion> 27 27 </PropertyGroup> 28 28 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 34 34 <WarningLevel>4</WarningLevel> 35 35 <Prefer32Bit>false</Prefer32Bit> 36 <LangVersion> 5</LangVersion>36 <LangVersion>6</LangVersion> 37 37 </PropertyGroup> 38 38 <PropertyGroup> … … 243 243 <Compile Include="Regression\Various\SpatialCoevolution.cs" /> 244 244 <Compile Include="Regression\Various\VariousInstanceProvider.cs" /> 245 <Compile Include="Regression\VectorData\VariousInstanceProvider.cs" /> 246 <Compile Include="Regression\VectorData\VectorDataTestOne.cs" /> 245 247 <Compile Include="Regression\Vladislavleva\KotanchekFunction.cs" /> 246 248 <Compile Include="Regression\Vladislavleva\RationalPolynomialThreeDimensional.cs" /> -
branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ArtificialRegressionDataDescriptor.cs
r17180 r17364 20 20 #endregion 21 21 22 using System.Collections; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Problems.DataAnalysis; … … 26 27 public abstract class ArtificialRegressionDataDescriptor : RegressionDataDescriptor { 27 28 public IRegressionProblemData GenerateRegressionData() { 28 Dataset dataset = new Dataset(VariableNames, this.GenerateValues()); 29 var values = GenerateValues(); 30 Dataset dataset = values != null 31 ? new Dataset(VariableNames, GenerateValues()) 32 : new Dataset(VariableNames, GenerateValuesExtended()); 29 33 return GenerateRegressionData(dataset); 30 34 } 31 35 32 36 protected abstract List<List<double>> GenerateValues(); 37 38 protected virtual List<IList> GenerateValuesExtended() { 39 return null; 40 } 33 41 } 34 42 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VectorData/VariousInstanceProvider.cs
r17362 r17364 25 25 26 26 namespace HeuristicLab.Problems.Instances.DataAnalysis { 27 public class V ariousInstanceProvider : ArtificialRegressionInstanceProvider {27 public class VectorDataInstanceProvider : ArtificialRegressionInstanceProvider { 28 28 public override string Name { 29 get { return "V ariousBenchmark Problems"; }29 get { return "Vector Data Benchmark Problems"; } 30 30 } 31 31 public override string Description { … … 40 40 public int Seed { get; private set; } 41 41 42 public VariousInstanceProvider() : this((int)DateTime.Now.Ticks) { } 42 public VectorDataInstanceProvider() 43 : this((int)DateTime.Now.Ticks) { } 43 44 44 public VariousInstanceProvider(int seed) : base() { 45 public VectorDataInstanceProvider(int seed) 46 : base() { 45 47 Seed = seed; 46 48 } 47 49 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 48 List<IDataDescriptor> descriptorList = new List<IDataDescriptor>();49 50 var rand = new MersenneTwister((uint)Seed); 50 descriptorList.Add(new BreimanOne(rand.Next())); 51 descriptorList.Add(new FriedmanOne(rand.Next())); 52 descriptorList.Add(new FriedmanTwo(rand.Next())); 53 descriptorList.Add(new PolyTen(rand.Next())); 54 descriptorList.Add(new SpatialCoevolution(rand.Next())); 55 return descriptorList; 51 return new List<IDataDescriptor> { 52 new VectorDataTestOne(rand.Next()) 53 }; 56 54 } 57 55 }
Note: See TracChangeset
for help on using the changeset viewer.