Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15159


Ignore:
Timestamp:
07/06/17 13:56:47 (7 years ago)
Author:
gkronber
Message:

#2723: merged r15013 and r15015 from trunk to stable

Location:
stable/HeuristicLab.Problems.DataAnalysis/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r15152 r15159  
    7474        throw new ArgumentException(message);
    7575      }
    76       DatasetUtil.ValidateInputData(variableValues); // the validation call checks if every values IList is actually a list of the supported type
    7776      rows = variableValues.First().Count;
    7877      this.variableNames = new List<string>(variableNames);
     
    115114      foreach (var v in variableNames) {
    116115        if (VariableHasType<double>(v)) {
    117           values.Add(new List<double>((List<double>)variableValues[v]));
     116          values.Add(new List<double>((IList<double>)variableValues[v]));
    118117        } else if (VariableHasType<string>(v)) {
    119           values.Add(new List<string>((List<string>)variableValues[v]));
     118          values.Add(new List<string>((IList<string>)variableValues[v]));
    120119        } else if (VariableHasType<DateTime>(v)) {
    121           values.Add(new List<DateTime>((List<DateTime>)variableValues[v]));
     120          values.Add(new List<DateTime>((IList<DateTime>)variableValues[v]));
    122121        } else {
    123122          throw new ArgumentException("Unknown variable type.");
     
    175174    }
    176175    public IEnumerable<string> DoubleVariables {
    177       get { return variableValues.Where(p => p.Value is List<double>).Select(p => p.Key); }
     176      get { return variableValues.Where(p => p.Value is IList<double>).Select(p => p.Key); }
    178177    }
    179178
    180179    public IEnumerable<string> StringVariables {
    181       get { return variableValues.Where(p => p.Value is List<string>).Select(p => p.Key); }
     180      get { return variableValues.Where(p => p.Value is IList<string>).Select(p => p.Key); }
    182181    }
    183182
     
    194193    public ReadOnlyCollection<double> GetReadOnlyDoubleValues(string variableName) {
    195194      var values = GetValues<double>(variableName);
    196       return values.AsReadOnly();
     195      return new ReadOnlyCollection<double>(values);
    197196    }
    198197    public double GetDoubleValue(string variableName, int row) {
     
    214213    public ReadOnlyCollection<string> GetReadOnlyStringValues(string variableName) {
    215214      var values = GetValues<string>(variableName);
    216       return values.AsReadOnly();
     215      return new ReadOnlyCollection<string>(values);
    217216    }
    218217
     
    221220      return rows.Select(x => values[x]);
    222221    }
    223     private List<T> GetValues<T>(string variableName) {
     222    private IList<T> GetValues<T>(string variableName) {
    224223      IList list;
    225224      if (!variableValues.TryGetValue(variableName, out list))
    226225        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
    227       List<T> values = list as List<T>;
     226      IList<T> values = list as IList<T>;
    228227      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a " + typeof(T) + " variable.");
    229228      return values;
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/DatasetUtil.cs

    r15152 r15159  
    3838    /// <returns>A new list containing shuffled copies of the original value lists.</returns>
    3939    public static List<IList> ShuffleLists(this List<IList> values, IRandom random) {
    40       ValidateInputData(values);
    41 
    4240      int count = values.First().Count;
    4341      int[] indices = Enumerable.Range(0, count).Shuffle(random).ToArray();
     
    4543      for (int col = 0; col < values.Count; col++) {
    4644
    47         if (values[col] is List<double>)
     45        if (values[col] is IList<double>)
    4846          shuffled.Add(new List<double>());
    49         else if (values[col] is List<DateTime>)
     47        else if (values[col] is IList<DateTime>)
    5048          shuffled.Add(new List<DateTime>());
    51         else if (values[col] is List<string>)
     49        else if (values[col] is IList<string>)
    5250          shuffled.Add(new List<string>());
    5351        else
     
    5957      }
    6058      return shuffled;
    61     }
    6259
    63     /// <summary>
    64     /// This method checks if the provided lists of values are actually of the type List<T>, where T is a double, string or DateTime
    65     /// </summary>
    66     /// <param name="values">The values lists</param>
    67     internal static void ValidateInputData(IEnumerable<IList> values) {
    68       if (!values.Any())
    69         throw new InvalidEnumArgumentException("The provided list of values is empty.");
    70 
    71       var errorIndices = new List<int>();
    72       int col = 0;
    73       foreach (var v in values) {
    74         var doubleList = v as List<double>;
    75         var stringList = v as List<string>;
    76         var dateTimeList = v as List<DateTime>;
    77 
    78         var typedCollections = new IList[] { doubleList, stringList, dateTimeList };
    79 
    80         if (typedCollections.All(x => x == null)) {
    81           errorIndices.Add(col); // the values are not a) a list and b) of any of the supported types
    82         }
    83         ++col;
    84       }
    85 
    86       if (errorIndices.Any()) {
    87         var sb = new StringBuilder();
    88         for (int i = 0; i < errorIndices.Count; ++i) {
    89           sb.Append(i);
    90           sb.Append(i < errorIndices.Count - 1 ? ", " : " ");
    91         }
    92         var error = string.Format("Invalid input values. The following columns are not lists of double, string or DateTime values: {0}", sb);
    93         throw new ArgumentException(error);
    94       }
    9560    }
    9661  }
Note: See TracChangeset for help on using the changeset viewer.