Free cookie consent management tool by TermsFeed Policy Generator

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/HeuristicLab.Problems.DataAnalysis/3.4
Files:
3 edited

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}
Note: See TracChangeset for help on using the changeset viewer.