Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/05/10 16:30:57 (14 years ago)
Author:
gkronber
Message:

Improved time series evaluators. #1142

Location:
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs

    r4460 r4555  
    126126      IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows);
    127127      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows);
    128       CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha);
     128      SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha);
    129129
    130130      return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance);
     
    174174      }
    175175    }
    176 
    177     /// <summary>
    178     /// Calculates linear scaling parameters in one pass.
    179     /// The formulas to calculate the scaling parameters were taken from Scaled Symblic Regression by Maarten Keijzer.
    180     /// http://www.springerlink.com/content/x035121165125175/
    181     /// </summary>
    182     public static void CalculateScalingParameters(IEnumerable<double> original, IEnumerable<double> estimated, out double beta, out double alpha) {
    183       IEnumerator<double> originalEnumerator = original.GetEnumerator();
    184       IEnumerator<double> estimatedEnumerator = estimated.GetEnumerator();
    185       OnlineMeanAndVarianceCalculator yVarianceCalculator = new OnlineMeanAndVarianceCalculator();
    186       OnlineMeanAndVarianceCalculator tMeanCalculator = new OnlineMeanAndVarianceCalculator();
    187       OnlineCovarianceEvaluator ytCovarianceEvaluator = new OnlineCovarianceEvaluator();
    188       int cnt = 0;
    189 
    190       while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
    191         double y = estimatedEnumerator.Current;
    192         double t = originalEnumerator.Current;
    193         if (IsValidValue(t) && IsValidValue(y)) {
    194           tMeanCalculator.Add(t);
    195           yVarianceCalculator.Add(y);
    196           ytCovarianceEvaluator.Add(y, t);
    197 
    198           cnt++;
    199         }
    200       }
    201 
    202       if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())
    203         throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match.");
    204       if (cnt < 2) {
    205         alpha = 0;
    206         beta = 1;
    207       } else {
    208         if (yVarianceCalculator.PopulationVariance.IsAlmost(0.0))
    209           beta = 1;
    210         else
    211           beta = ytCovarianceEvaluator.Covariance / yVarianceCalculator.PopulationVariance;
    212 
    213         alpha = tMeanCalculator.Mean - beta * yVarianceCalculator.Mean;
    214       }
    215     }
    216 
    217     private static bool IsValidValue(double d) {
    218       return !double.IsInfinity(d) && !double.IsNaN(d) && d > -1.0E07 && d < 1.0E07;  // don't consider very large or very small values for scaling
    219     }
    220176  }
    221177}
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs

    r4458 r4555  
    100100    }
    101101
    102     /// <summary>
    103     /// Calculates linear scaling parameters in one pass.
    104     /// The formulas to calculate the scaling parameters were taken from Scaled Symblic Regression by Maarten Keijzer.
    105     /// http://www.springerlink.com/content/x035121165125175/
    106     /// </summary>
    107102    public static void CalculateScalingParameters(IEnumerable<double> original, IEnumerable<double> estimated, out double beta, out double alpha) {
    108103      IEnumerator<double> originalEnumerator = original.GetEnumerator();
    109104      IEnumerator<double> estimatedEnumerator = estimated.GetEnumerator();
    110       OnlineMeanAndVarianceCalculator yVarianceCalculator = new OnlineMeanAndVarianceCalculator();
    111       OnlineMeanAndVarianceCalculator tMeanCalculator = new OnlineMeanAndVarianceCalculator();
    112       OnlineCovarianceEvaluator ytCovarianceEvaluator = new OnlineCovarianceEvaluator();
    113       int cnt = 0;
     105      OnlineLinearScalingCalculator linearScalingCalculator = new OnlineLinearScalingCalculator();
    114106
    115107      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     
    117109        double t = originalEnumerator.Current;
    118110        if (IsValidValue(t) && IsValidValue(y)) {
    119           tMeanCalculator.Add(t);
    120           yVarianceCalculator.Add(y);
    121           ytCovarianceEvaluator.Add(y, t);
    122 
    123           cnt++;
     111          linearScalingCalculator.Add(t, y);
    124112        }
    125113      }
     
    127115      if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())
    128116        throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match.");
    129       if (cnt < 2) {
    130         alpha = 0;
    131         beta = 1;
    132       } else {
    133         if (yVarianceCalculator.PopulationVariance.IsAlmost(0.0))
    134           beta = 1;
    135         else
    136           beta = ytCovarianceEvaluator.Covariance / yVarianceCalculator.PopulationVariance;
    137 
    138         alpha = tMeanCalculator.Mean - beta * yVarianceCalculator.Mean;
     117      else {
     118        beta = linearScalingCalculator.Beta;
     119        alpha = linearScalingCalculator.Alpha;
    139120      }
    140121    }
Note: See TracChangeset for help on using the changeset viewer.