Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17416


Ignore:
Timestamp:
01/31/20 16:21:00 (5 years ago)
Author:
pfleck
Message:

#3040 enabled variable impacts for vectorial data (if vectors have the same length)

Location:
branches/3040_VectorBasedGP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r17276 r17416  
    141141        var originalVariableOrdering = problemData.Dataset.VariableNames
    142142          .Where(v => inputvariables.Contains(v))
    143           .Where(v => problemData.Dataset.VariableHasType<double>(v) || problemData.Dataset.VariableHasType<string>(v))
     143          //.Where(v => problemData.Dataset.VariableHasType<double>(v) || problemData.Dataset.VariableHasType<string>(v))
    144144          .ToList();
    145145
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r17180 r17416  
    195195        originalValues = modifiableDataset.GetReadOnlyStringValues(variableName).ToList();
    196196        replacementValues = GetReplacementValuesForString(model, modifiableDataset, variableName, rows, (List<string>)originalValues, targetValues, factorReplacementMethod);
     197      } else if (modifiableDataset.VariableHasType<DoubleVector>(variableName)) {
     198        originalValues = modifiableDataset.GetReadOnlyDoubleVectorValues(variableName).ToList();
     199        replacementValues = GetReplacementValuesForDoubleVector(modifiableDataset, rows, (List<DoubleVector>)originalValues, replacementMethod);
    197200      } else {
    198201        throw new NotSupportedException("Variable not supported");
     
    303306    }
    304307
     308    private static IList GetReplacementValuesForDoubleVector(ModifiableDataset modifiableDataset,
     309      IEnumerable<int> rows,
     310      List<DoubleVector> originalValues,
     311      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle) {
     312
     313      IRandom random = new FastRandom(31415);
     314      List<DoubleVector> replacementValues;
     315      DoubleVector replacementValue;
     316
     317      switch (replacementMethod) {
     318        case ReplacementMethodEnum.Shuffle:
     319          // new var has same empirical distribution but the relation to y is broken
     320          // prepare a complete column for the dataset
     321          replacementValues = Enumerable.Repeat(new DoubleVector(new[] { double.NaN }), modifiableDataset.Rows).ToList();
     322          // shuffle only the selected rows
     323          var shuffledValues = rows.Select(r => originalValues[r]).Shuffle(random).ToList();
     324          int i = 0;
     325          // update column values
     326          foreach (var r in rows) {
     327            replacementValues[r] = shuffledValues[i++];
     328          }
     329          break;
     330
     331        default:
     332          throw new ArgumentException(string.Format("ReplacementMethod {0} cannot be handled.", replacementMethod));
     333      }
     334
     335      return replacementValues;
     336    }
     337
    305338    private static double CalculateQualityForReplacement(
    306339      IRegressionModel model,
Note: See TracChangeset for help on using the changeset viewer.