Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/21/18 12:01:54 (7 years ago)
Author:
fholzing
Message:

#2871: Added additional logic for progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r15673 r15796  
    5252      All
    5353    }
    54    
     54
    5555    private const string ReplacementParameterName = "Replacement Method";
    5656    private const string DataPartitionParameterName = "DataPartition";
     
    9696      DataPartitionEnum data = DataPartitionEnum.Training,
    9797      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
    98       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best) {
     98      FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best, Func<double, bool> progressCallback = null) {
    9999
    100100      var problemData = solution.ProblemData;
     
    134134      var allowedInputVariables = dataset.VariableNames.Where(v => inputvariables.Contains(v)).ToList();
    135135
     136      int curIdx = 1;
     137      int count = allowedInputVariables.Where(problemData.Dataset.VariableHasType<double>).Count();
    136138      // calculate impacts for double variables
    137139      foreach (var inputVariable in allowedInputVariables.Where(problemData.Dataset.VariableHasType<double>)) {
     140        //Report the current progress in percent. If the callback returns true, it means the execution shall be stopped
     141        if (progressCallback != null) {
     142          if (progressCallback((double)curIdx++ / count)) { return null; }
     143        }
    138144        var newEstimates = EvaluateModelWithReplacedVariable(solution.Model, inputVariable, modifiableDataset, rows, replacementMethod);
    139145        var newR2 = OnlinePearsonsRCalculator.Calculate(targetValues, newEstimates, out error);
     
    180186    }
    181187
     188
    182189    private static IEnumerable<double> EvaluateModelWithReplacedVariable(IRegressionModel model, string variable, ModifiableDataset dataset, IEnumerable<int> rows, ReplacementMethodEnum replacement = ReplacementMethodEnum.Median) {
    183190      var originalValues = dataset.GetReadOnlyDoubleValues(variable).ToList();
Note: See TracChangeset for help on using the changeset viewer.