Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/10/08 11:08:07 (16 years ago)
Author:
gkronber
Message:

implemented #242 (All GP evaluators should support the 'UseEstimatedTargetValues' switch for autoregressive modelling).
Also used the chance to remove a lot of the code duplication and thus improve the readability of all GP evaluators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MCCEvaluator.cs

    r453 r479  
    3232namespace HeuristicLab.StructureIdentification {
    3333  public class MCCEvaluator : GPEvaluatorBase {
     34    private double limit;
     35    private double[] original = new double[1];
     36    private double[] estimated = new double[1];
    3437    public override string Description {
    3538      get {
     
    3740      }
    3841    }
    39 
    4042    public MCCEvaluator()
    4143      : base() {
     
    4345    }
    4446
    45     private double[] original = new double[1];
    46     private double[] estimated = new double[1];
    47     public override double Evaluate(IScope scope, IFunctionTree functionTree, int targetVariable, Dataset dataset) {
    48       int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
    49       int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    50       int nSamples = trainingEnd-trainingStart;
    51       double limit = GetVariableValue<DoubleData>("ClassSeparation", scope, true).Data;
     47    public override IOperation Apply(IScope scope) {
     48      limit = GetVariableValue<DoubleData>("ClassSeparation", scope, true).Data;
     49      return base.Apply(scope);
     50    }
     51
     52    public override double Evaluate(int start, int end) {
     53      int nSamples = end - start;
    5254      if(estimated.Length != nSamples) {
    5355        estimated = new double[nSamples];
     
    5759      double positive = 0;
    5860      double negative = 0;
    59       double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd);
    60       for(int sample = trainingStart; sample < trainingEnd; sample++) {
    61         double est = evaluator.Evaluate(sample);
    62         double orig = dataset.GetValue(sample, targetVariable);
    63         if(double.IsNaN(est) || double.IsInfinity(est)) {
    64           est = targetMean + maximumPunishment;
    65         } else if(est > targetMean + maximumPunishment) {
    66           est = targetMean + maximumPunishment;
    67         } else if(est < targetMean - maximumPunishment) {
    68           est = targetMean - maximumPunishment;
    69         }
    70         estimated[sample-trainingStart] = est;
    71         original[sample-trainingStart] = orig;
     61      for(int sample = start; sample < end; sample++) {
     62        double est = GetEstimatedValue(sample);
     63        double orig = GetOriginalValue(sample);
     64        estimated[sample - start] = est;
     65        original[sample - start] = orig;
    7266        if(orig >= limit) positive++;
    7367        else negative++;
     
    7973      double tn = negative;
    8074      double fp = 0;
    81       for(int i = original.Length-1; i >= 0 ; i--) {
     75      for(int i = original.Length - 1; i >= 0; i--) {
    8276        if(original[i] >= limit) {
    8377          tp++; fn--;
     
    9084        }
    9185      }
    92       scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (trainingEnd - trainingStart);
    9386      return best_mcc;
    9487    }
Note: See TracChangeset for help on using the changeset viewer.