Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/21 10:35:19 (3 years ago)
Author:
mkommend
Message:

#3129: Work on variable range calculation of datasets.

Renamed method to calculate variable ranges to a more appropriate method name.
Added possibility to ignore NaNs for range calculation.

Location:
trunk/HeuristicLab.Problems.DataAnalysis/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs

    r17911 r17999  
    9696    }
    9797
    98     public static IntervalCollection GetIntervals(this IDataset dataset) {
    99       IntervalCollection intervalCollection = new IntervalCollection();
    100       foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables
    101         var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
    102         intervalCollection.AddInterval(variable, variableInterval);
     98    public static IntervalCollection GetVariableRanges(this IDataset dataset, bool ignoreNaNs = true) {
     99      IntervalCollection variableRanges = new IntervalCollection();
     100      foreach (var variable in dataset.DoubleVariables) { // ranges can only be calculated for double variables
     101        var values = dataset.GetDoubleValues(variable);
     102
     103        if (ignoreNaNs) {
     104          values = values.Where(v => !double.IsNaN(v));
     105
     106          if (!values.Any()) { //handle values with only NaNs explicitly
     107            var emptyInterval = new Interval(double.NaN, double.NaN);
     108            variableRanges.AddInterval(variable, emptyInterval);
     109            continue;
     110          }
     111        }
     112
     113        var interval = Interval.GetInterval(values);
     114        variableRanges.AddInterval(variable, interval);
    103115      }
    104116
    105       return intervalCollection;
     117      return variableRanges;
    106118    }
    107119
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17958 r17999  
    130130    private void AfterDeserialization() {
    131131      if (!Parameters.ContainsKey(VariableRangesParameterName)) {
    132         var intervalCollection = Dataset.GetIntervals();
     132        var variableRanges = Dataset.GetVariableRanges();
    133133        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    134134      }
     
    164164      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
    165165      if (variableRanges == null) {
    166         variableRanges = Dataset.GetIntervals();
     166        variableRanges = Dataset.GetVariableRanges();
    167167      }
    168168      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ShapeConstrainedRegressionProblemData.cs

    r17982 r17999  
    100100        new ShapeConstraint("x", 1, new Interval(0, double.PositiveInfinity), 1.0)
    101101      };
    102       defaultVariableRanges = defaultDataset.GetIntervals();
     102      defaultVariableRanges = defaultDataset.GetVariableRanges();
    103103      defaultVariableRanges.SetInterval("x", new Interval(0, 6));
    104104
Note: See TracChangeset for help on using the changeset viewer.