Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/09 18:43:26 (15 years ago)
Author:
gkronber
Message:

Fixed #643 (Simple evaluation operators in HL.Modeling and GP specific evaluation operators in HL.GP.StructureIdentification should be unified).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VarianceAccountedForEvaluator.cs

    r1891 r1894  
    2828using HeuristicLab.Operators;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.Modeling;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
    32   public class VarianceAccountedForEvaluator : GPEvaluatorBase {
     33  /// <summary>
     34  /// The Variance Accounted For (VAF) function calculates is computed as
     35  /// VAF(y,y') = ( 1 - var(y-y')/var(y) )
     36  /// where y' denotes the predicted / modelled values for y and var(x) the variance of a signal x.
     37  /// </summary>
     38  public class VarianceAccountedForEvaluator : SimpleGPEvaluatorBase {
     39    public override string OutputVariableName {
     40      get {
     41        return "VAF";
     42      }
     43    }
    3344    public override string Description {
    3445      get {
     
    4253    }
    4354
    44     /// <summary>
    45     /// The Variance Accounted For (VAF) function calculates is computed as
    46     /// VAF(y,y') = ( 1 - var(y-y')/var(y) )
    47     /// where y' denotes the predicted / modelled values for y and var(x) the variance of a signal x.
    48     /// </summary>
    49     public VarianceAccountedForEvaluator()
    50       : base() {
    51       AddVariableInfo(new VariableInfo("VAF", "The variance-accounted-for quality of the model", typeof(DoubleData), VariableKind.New));
    52 
    53     }
    54 
    55     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    56       int nSamples = end - start;
    57       double[] errors = new double[nSamples];
    58       double[] originalTargetVariableValues = new double[nSamples];
    59       for (int sample = start; sample < end; sample++) {
    60         double estimated = evaluator.Evaluate(sample);
    61         double original = dataset.GetValue(sample, targetVariable);
    62         if (updateTargetValues) {
    63           dataset.SetValue(sample, targetVariable, estimated);
    64         }
    65         if (!double.IsNaN(original) && !double.IsInfinity(original)) {
    66           errors[sample - start] = original - estimated;
    67           originalTargetVariableValues[sample - start] = original;
    68         } else {
    69           errors[sample - start] = double.NaN;
    70           originalTargetVariableValues[sample - start] = double.NaN;
    71         }
    72       }
    73       double errorsVariance = Statistics.Variance(errors);
    74       double originalsVariance = Statistics.Variance(originalTargetVariableValues);
    75       double quality = 1 - errorsVariance / originalsVariance;
     55    public override double Evaluate(double[,] values) {
     56      double quality = SimpleVarianceAccountedForEvaluator.Calculate(values);
    7657
    7758      if (double.IsNaN(quality) || double.IsInfinity(quality)) {
    7859        quality = double.MaxValue;
    7960      }
    80       DoubleData vaf = GetVariableValue<DoubleData>("VAF", scope, false, false);
    81       if (vaf == null) {
    82         vaf = new DoubleData();
    83         scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("VAF"), vaf));
    84       }
    85 
    86       vaf.Data = quality;
     61      return quality;
    8762    }
    8863  }
Note: See TracChangeset for help on using the changeset viewer.