Changeset 16016


Ignore:
Timestamp:
07/25/18 18:19:51 (13 months ago)
Author:
fholzing
Message:

#2904: Removed unnecessary where-condition (.Where(...).Count()); Cloned the dataset before the .ToModifiable() call; Adapted the CalculateValue-Method for a single loop through the IEnumerables for the target and estimated values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r16002 r16016  
    161161
    162162      int curIdx = 0;
    163       int count = allowedInputVariables
    164         .Where(v => problemData.Dataset.VariableHasType<double>(v) || problemData.Dataset.VariableHasType<string>(v))
    165         .Count();
     163      int count = allowedInputVariables.Count();
    166164
    167165      foreach (var inputVariable in allowedInputVariables) {
     
    198196
    199197      double impact = 0;
    200       var modifiableDataset = ((Dataset)dataset).ToModifiable();
     198      var modifiableDataset = ((Dataset)(dataset).Clone()).ToModifiable();
    201199
    202200      // calculate impacts for double variables
     
    369367    private static double CalculateValue(IEnumerable<double> targets, IEnumerable<double> estimates, out OnlineCalculatorError error) {
    370368      calculator.Reset();
    371       if (targets.Count() != estimates.Count()) {
     369
     370      var targetsEnumerator = targets.GetEnumerator();
     371      var estimatesEnumerator = estimates.GetEnumerator();
     372
     373      bool targetsHasNextValue = targetsEnumerator.MoveNext();
     374      bool estimatesHasNextValue = estimatesEnumerator.MoveNext();
     375
     376      while (targetsHasNextValue && estimatesHasNextValue) {
     377        calculator.Add(targetsEnumerator.Current, estimatesEnumerator.Current);
     378        targetsHasNextValue = targetsEnumerator.MoveNext();
     379        estimatesHasNextValue = estimatesEnumerator.MoveNext();
     380      }
     381
     382      //Check if there is an equal quantity of targets and estimates
     383      if (targetsHasNextValue != estimatesHasNextValue) {
    372384        throw new ArgumentException(string.Format("Targets and Estimates must be of equal length ({0},{1})", targets.Count(), estimates.Count()));
    373       }
    374       foreach (var entry in targets.Zip(estimates, (target, estimate) => new { target, estimate })) {
    375         calculator.Add(entry.target, entry.estimate);
    376       }
     385
     386      }
     387
    377388      error = calculator.ErrorState;
    378389      return calculator.Value;
Note: See TracChangeset for help on using the changeset viewer.