Free cookie consent management tool by TermsFeed Policy Generator

Changeset 692


Ignore:
Timestamp:
10/19/08 00:51:39 (16 years ago)
Author:
gkronber
Message:

fixed #321 (Improve implementation of operator for Theil's Inequality). There was actually a bug in the existing implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/TheilInequalityCoefficientEvaluator.cs

    r686 r692  
    3030namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
    3131  public class TheilInequalityCoefficientEvaluator : GPEvaluatorBase {
    32     private bool differential;
    3332    private DoubleData theilInequaliy;
    3433    public override string Description {
     
    4140    public TheilInequalityCoefficientEvaluator()
    4241      : base() {
    43       AddVariableInfo(new VariableInfo("Differential", "Wether to calculate the coefficient for the predicted change vs. original change or for the absolute prediction vs. original value", typeof(BoolData), VariableKind.In));
    4442      AddVariableInfo(new VariableInfo("TheilInequalityCoefficient", "Theil's inequality coefficient of the model", typeof(DoubleData), VariableKind.New));
    45 
    4643    }
    4744
    4845    public override IOperation Apply(IScope scope) {
    49       differential = GetVariableValue<BoolData>("Differential", scope, true).Data;
    5046      theilInequaliy = GetVariableValue<DoubleData>("TheilInequalityCoefficient", scope, false, false);
    5147      if(theilInequaliy == null) {
     
    5349        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficient"), theilInequaliy));
    5450      }
    55 
    5651      return base.Apply(scope);
    5752    }
     
    5954    public override void Evaluate(int start, int end) {
    6055      double errorsSquaredSum = 0.0;
    61       double estimatedSquaredSum = 0.0;
    6256      double originalSquaredSum = 0.0;
    6357      for(int sample = start; sample < end; sample++) {
    64         double prevValue = 0.0;
    65         if(differential) prevValue = GetOriginalValue(sample - 1);
     58        double prevValue = GetOriginalValue(sample - 1);
    6659        double estimatedChange = GetEstimatedValue(sample) - prevValue;
    6760        double originalChange = GetOriginalValue(sample) - prevValue;
     
    7063          double error = estimatedChange - originalChange;
    7164          errorsSquaredSum += error * error;
    72           estimatedSquaredSum += estimatedChange * estimatedChange;
    7365          originalSquaredSum += originalChange * originalChange;
    7466        }
    7567      }
    7668      int nSamples = end - start;
    77       double quality = Math.Sqrt(errorsSquaredSum / nSamples) / (Math.Sqrt(estimatedSquaredSum / nSamples) + Math.Sqrt(originalSquaredSum / nSamples));
     69      double quality = Math.Sqrt(errorsSquaredSum / nSamples) / Math.Sqrt(originalSquaredSum / nSamples);
    7870      if(double.IsNaN(quality) || double.IsInfinity(quality))
    7971        quality = double.MaxValue;
Note: See TracChangeset for help on using the changeset viewer.