Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17364


Ignore:
Timestamp:
11/22/19 10:06:42 (5 years ago)
Author:
pfleck
Message:

#3040

  • Added double vectors for Dataset. Extended the type-checks for DataAnalysisProblemData.
  • Added a small benchmark instance with data containing vectors. Adapted the ArtificialRegressionDataDescriptor to be able to specify non-double values.
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  
    142142        else if (iter.Current[i] is string s)
    143143          transposed.Add(new List<string>() { s });
     144        else if (iter.Current[i] is IReadOnlyList<double> dv)
     145          transposed.Add(new List<IReadOnlyList<double>>() { dv });
    144146        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()));
    145147      }
     
    212214      get { return variableValues.Where(p => p.Value is IList<double>).Select(p => p.Key); }
    213215    }
    214 
    215216    public IEnumerable<string> StringVariables {
    216217      get { return variableValues.Where(p => p.Value is IList<string>).Select(p => p.Key); }
    217218    }
    218 
    219219    public IEnumerable<string> DateTimeVariables {
    220220      get { return variableValues.Where(p => p.Value is IList<DateTime>).Select(p => p.Key); }
    221221    }
     222    public IEnumerable<string> DoubleVectorVariables {
     223      get { return variableValues.Where(p => p.Value is IList<IReadOnlyList<double>>).Select(p => p.Key); }
     224    }
    222225
    223226    public IEnumerable<double> GetDoubleValues(string variableName) {
     
    229232    public IEnumerable<DateTime> GetDateTimeValues(string variableName) {
    230233      return GetValues<DateTime>(variableName);
     234    }
     235    public IEnumerable<IReadOnlyList<double>> GetDoubleVectorValues(string variableName) {
     236      return GetValues<IReadOnlyList<double>>(variableName);
    231237    }
    232238
     
    247253      return values[row];
    248254    }
    249 
    250255    public IEnumerable<string> GetStringValues(string variableName, IEnumerable<int> rows) {
    251256      return GetValues<string>(variableName, rows);
     
    267272      return new ReadOnlyCollection<DateTime>(values);
    268273    }
     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
    269287    private IEnumerable<T> GetValues<T>(string variableName, IEnumerable<int> rows) {
    270288      var values = GetValues<T>(variableName);
     
    298316    }
    299317    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>);
    301319    }
    302320
     
    343361      if (dateTimeValues != null) return new List<DateTime>(dateTimeValues);
    344362
     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
    345366      throw new ArgumentException(string.Format("Unsupported variable type {0}.", GetElementType(values)));
    346367    }
     
    381402    }
    382403    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)}]";
    383407      return variableValues[variableNames[columnIndex]][rowIndex].ToString();
    384408    }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r17180 r17364  
    158158      if (allowedInputVariables == null) throw new ArgumentNullException("The allowed input variables must not be null.");
    159159
    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));
    164165      var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x).AsReadOnly()));
    165166      foreach (StringValue x in inputVariables)
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataset.cs

    r17180 r17364  
    3434    IEnumerable<string> StringVariables { get; }
    3535    IEnumerable<string> DateTimeVariables { get; }
     36    IEnumerable<string> DoubleVectorVariables { get; }
    3637
    3738    bool ContainsVariable(string variablename);
     
    4849    ReadOnlyCollection<string> GetReadOnlyStringValues(string VariableName);
    4950
    50     System.DateTime GetDateTimeValue(string variableName, int row);
     51    DateTime GetDateTimeValue(string variableName, int row);
    5152    IEnumerable<DateTime> GetDateTimeValues(string variableName);
    5253    IEnumerable<DateTime> GetDateTimeValues(string variableName, IEnumerable<int> rows);
    5354    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);
    5460  }
    5561}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj

    r16658 r17364  
    2424    <WarningLevel>4</WarningLevel>
    2525    <Prefer32Bit>false</Prefer32Bit>
    26     <LangVersion>5</LangVersion>
     26    <LangVersion>6</LangVersion>
    2727  </PropertyGroup>
    2828  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    3434    <WarningLevel>4</WarningLevel>
    3535    <Prefer32Bit>false</Prefer32Bit>
    36     <LangVersion>5</LangVersion>
     36    <LangVersion>6</LangVersion>
    3737  </PropertyGroup>
    3838  <PropertyGroup>
     
    243243    <Compile Include="Regression\Various\SpatialCoevolution.cs" />
    244244    <Compile Include="Regression\Various\VariousInstanceProvider.cs" />
     245    <Compile Include="Regression\VectorData\VariousInstanceProvider.cs" />
     246    <Compile Include="Regression\VectorData\VectorDataTestOne.cs" />
    245247    <Compile Include="Regression\Vladislavleva\KotanchekFunction.cs" />
    246248    <Compile Include="Regression\Vladislavleva\RationalPolynomialThreeDimensional.cs" />
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ArtificialRegressionDataDescriptor.cs

    r17180 r17364  
    2020#endregion
    2121
     22using System.Collections;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Problems.DataAnalysis;
     
    2627  public abstract class ArtificialRegressionDataDescriptor : RegressionDataDescriptor {
    2728    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());
    2933      return GenerateRegressionData(dataset);
    3034    }
    3135
    3236    protected abstract List<List<double>> GenerateValues();
     37
     38    protected virtual List<IList> GenerateValuesExtended() {
     39      return null;
     40    }
    3341  }
    3442}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VectorData/VariousInstanceProvider.cs

    r17362 r17364  
    2525
    2626namespace HeuristicLab.Problems.Instances.DataAnalysis {
    27   public class VariousInstanceProvider : ArtificialRegressionInstanceProvider {
     27  public class VectorDataInstanceProvider : ArtificialRegressionInstanceProvider {
    2828    public override string Name {
    29       get { return "Various Benchmark Problems"; }
     29      get { return "Vector Data Benchmark Problems"; }
    3030    }
    3131    public override string Description {
     
    4040    public int Seed { get; private set; }
    4141
    42     public VariousInstanceProvider() : this((int)DateTime.Now.Ticks) { }
     42    public VectorDataInstanceProvider()
     43      : this((int)DateTime.Now.Ticks) { }
    4344
    44     public VariousInstanceProvider(int seed) : base() {
     45    public VectorDataInstanceProvider(int seed)
     46      : base() {
    4547      Seed = seed;
    4648    }
    4749    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    48       List<IDataDescriptor> descriptorList = new List<IDataDescriptor>();
    4950      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      };
    5654    }
    5755  }
Note: See TracChangeset for help on using the changeset viewer.