Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/02/15 01:08:30 (9 years ago)
Author:
bburlacu
Message:

#1772:

  • added parameters to the SchemaCreator for calculating things in parallel
  • added parallel code to the SchemaEvaluator
  • implemented quality calculation and saving of estimated values in the scope in the UpdateEstimatedValuesOperator
  • small refactoring of QueryMatch (added some useful methods and made NodeInfo internal)
  • updated query match unit test
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs

    r12958 r12979  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    5152    }
    5253
     54
    5355    public UpdateEstimatedValuesOperator() {
    5456      Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName));
     
    7476      var interpreter = InterpreterParameter.ActualValue;
    7577
    76       var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, problemData.TrainingIndices)
    77                                        .LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     78      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, problemData.TrainingIndices).ToArray();
     79      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).ToArray();
     80
     81      if (estimatedValues.Length != targetValues.Length)
     82        throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
     83
     84      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
     85
     86      for (int i = 0; i < estimatedValues.Length; ++i) {
     87        var estimated = estimatedValues[i];
     88        var target = targetValues[i];
     89        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
     90          linearScalingCalculator.Add(estimated, target);
     91      }
     92      double alpha = linearScalingCalculator.Alpha;
     93      double beta = linearScalingCalculator.Beta;
     94      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {
     95        alpha = 0.0;
     96        beta = 1.0;
     97      }
     98
     99      var scaled = estimatedValues.Select(x => x * beta + alpha).LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     100      OnlineCalculatorError error;
     101      var r = OnlinePearsonsRCalculator.Calculate(targetValues, scaled, out error);
     102      if (error != OnlineCalculatorError.None) r = 0;
     103
     104      var r2 = r * r;
     105      if (r2 > 1.0) r2 = 1.0;
    78106
    79107      var variables = ExecutionContext.Scope.Variables;
    80       if (variables.ContainsKey("EstimatedValues"))
    81         variables["EstimatedValues"].Value = new DoubleArray(estimatedValues);
    82       else
    83         variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(estimatedValues)));
     108      ((DoubleValue)variables["Quality"].Value).Value = r2;
     109
     110      if (variables.ContainsKey("EstimatedValues")) {
     111        variables["EstimatedValues"].Value = new DoubleArray(scaled);
     112      } else {
     113        variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(scaled)));
     114      }
    84115      return base.Apply();
    85116    }
Note: See TracChangeset for help on using the changeset viewer.