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/SimpleEvaluator.cs

    r396 r479  
    3131
    3232namespace HeuristicLab.StructureIdentification {
    33   public class SimpleEvaluator : OperatorBase {
    34     protected int treeSize;
    35     protected double totalEvaluatedNodes;
    36     private IEvaluator evaluator;
    37 
     33  public class SimpleEvaluator : GPEvaluatorBase {
     34    private ItemList values;
    3835    public SimpleEvaluator()
    3936      : base() {
    40       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree that should be evaluated", typeof(IFunctionTree), VariableKind.In));
    41       AddVariableInfo(new VariableInfo("TreeSize", "Size (number of nodes) of the tree to evaluate", typeof(IntData), VariableKind.In));
    42       AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    43       AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
    44       AddVariableInfo(new VariableInfo("TotalEvaluatedNodes", "Number of evaluated nodes", typeof(DoubleData), VariableKind.In | VariableKind.Out));
    45       AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training samples in dataset", typeof(IntData), VariableKind.In));
    46       AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training samples in dataset", typeof(IntData), VariableKind.In));
    4737      AddVariableInfo(new VariableInfo("Values", "The values of the target variable as predicted by the model and the original value of the target variable", typeof(ItemList), VariableKind.New | VariableKind.Out));
    4838    }
    4939
    5040    public override IOperation Apply(IScope scope) {
    51       int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    52       Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    53       IFunctionTree functionTree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
    54       this.treeSize = scope.GetVariableValue<IntData>("TreeSize", false).Data;
    55       this.totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data;
    56       int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
    57       int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    58 
    59       ItemList values = GetVariableValue<ItemList>("Values", scope, false, false);
     41      values = GetVariableValue<ItemList>("Values", scope, false, false);
    6042      if(values == null) {
    6143        values = new ItemList();
     
    6749      }
    6850      values.Clear();
    69       if(evaluator == null) evaluator = functionTree.CreateEvaluator(dataset);
    70       evaluator.ResetEvaluator(functionTree);
    71       for(int sample = trainingStart; sample < trainingEnd; sample++) {
     51      return base.Apply(scope);
     52    }
     53
     54    public override double Evaluate(int start, int end) {
     55      for(int sample = start; sample < end; sample++) {
    7256        ItemList row = new ItemList();
    73         row.Add(new DoubleData(evaluator.Evaluate(sample)));
    74         row.Add(new DoubleData(dataset.GetValue(sample, targetVariable)));
     57        row.Add(new DoubleData(GetEstimatedValue(sample)));
     58        row.Add(new DoubleData(GetOriginalValue(sample)));
    7559        values.Add(row);
    7660      }
    77       scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (trainingEnd - trainingStart);
    78       return null;
     61      return double.NaN;
    7962    }
    8063  }
Note: See TracChangeset for help on using the changeset viewer.