Changeset 16041


Ignore:
Timestamp:
08/03/18 10:55:23 (3 years ago)
Author:
fholzing
Message:

#2904: Removed ElementAt

Location:
branches/2904_CalculateImpacts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2904_CalculateImpacts/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs

    r16037 r16041  
    131131     ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
    132132     FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best) {
    133       //Calculate original quality-values (via calculator, default is Accuracy)
     133      //Calculate original quality-values (via calculator, default is Accuracy)   
    134134      OnlineCalculatorError error;
    135135      IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     
    144144
    145145      foreach (var inputVariable in allowedInputVariables) {
    146         impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod);
     146        if (model.VariablesUsedForPrediction.Contains(inputVariable)) {
     147          impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod);
     148        } else {
     149          impacts[inputVariable] = 0;
     150        }
    147151      }
    148152
  • branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r16036 r16041  
    110110      FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
    111111      DataPartitionEnum dataPartition = DataPartitionEnum.Training) {
    112       return CalculateImpacts(solution.Model, solution.ProblemData, solution.EstimatedValues, replacementMethod, factorReplacementMethod, dataPartition);
    113     }
    114 
    115     public static IEnumerable<Tuple<string, double>> CalculateImpacts(
    116       IRegressionModel model,
    117       IRegressionProblemData problemData,
    118       IEnumerable<double> estimatedValues,
    119       ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
    120       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
    121       DataPartitionEnum dataPartition = DataPartitionEnum.Training) {
    122       IEnumerable<int> rows = GetPartitionRows(dataPartition, problemData);
    123       return CalculateImpacts(model, problemData, estimatedValues, rows, replacementMethod, factorReplacementMethod);
     112      IEnumerable<int> rows = (GetPartitionRows(dataPartition, solution.ProblemData));
     113      IEnumerable<double> estimatedValues = solution.GetEstimatedValues(rows);
     114      return CalculateImpacts(solution.Model, solution.ProblemData, estimatedValues, rows, replacementMethod, factorReplacementMethod);
    124115    }
    125116
     
    133124      //Calculate original quality-values (via calculator, default is R²)
    134125      OnlineCalculatorError error;
    135       IEnumerable<double> targetValuesPartition = rows.Select(v => problemData.TargetVariableValues.ElementAt(v));
    136       IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v));
    137       var originalCalculatorValue = CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error);
     126      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     127      var originalCalculatorValue = CalculateVariableImpact(targetValues, estimatedValues, out error);
    138128      if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
    139129
     
    143133      var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable();
    144134
     135
    145136      foreach (var inputVariable in allowedInputVariables) {
    146         impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod);
     137        if (model.VariablesUsedForPrediction.Contains(inputVariable)) {
     138          impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValues, originalCalculatorValue, replacementMethod, factorReplacementMethod);
     139        } else {
     140          impacts[inputVariable] = 0;
     141        }
    147142      }
    148143
  • branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs

    r16036 r16041  
    168168      OnlineCalculatorError error;
    169169      IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    170       IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v));
     170      IEnumerable<double> estimatedValuesPartition = Content.GetEstimatedClassValues(rows);
    171171      var originalCalculatorValue = ClassificationSolutionVariableImpactsCalculator.CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error);
    172172      if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
     
    177177        progress.Status = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
    178178
    179         double impact = ClassificationSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod);
     179        double impact = 0;
     180        //If the variable isn't used for prediction, it has zero impact.
     181        if (model.VariablesUsedForPrediction.Contains(variableName)) {
     182          impact = ClassificationSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod);
     183        }
    180184        impacts.Add(new Tuple<string, double>(variableName, impact));
    181185      }
  • branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r16035 r16041  
    165165      //Calculate original quality-values (via calculator, default is R²)
    166166      OnlineCalculatorError error;
    167       IEnumerable<double> targetValuesPartition = rows.Select(v => problemData.TargetVariableValues.ElementAt(v));
    168       IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v));
     167      IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     168      IEnumerable<double> estimatedValuesPartition = Content.GetEstimatedValues(rows);
     169
    169170      var originalCalculatorValue = RegressionSolutionVariableImpactsCalculator.CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error);
    170171      if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
     
    175176        progress.Status = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
    176177
    177         double impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod);
     178        double impact = 0;
     179        //If the variable isn't used for prediction, it has zero impact.
     180        if (model.VariablesUsedForPrediction.Contains(variableName)) {
     181          impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod);
     182        }
    178183        impacts.Add(new Tuple<string, double>(variableName, impact));
    179184      }
Note: See TracChangeset for help on using the changeset viewer.