Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/14/09 13:46:57 (15 years ago)
Author:
gkronber
Message:

Refactored GP evaluation to make it possible to use different evaluators to interpret function trees. #615 (Evaluation of HL3 function trees should be equivalent to evaluation in HL2)

Location:
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/AccuracyEvaluator.cs

    r1529 r1796  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4646      DoubleData accuracy = GetVariableValue<DoubleData>("Accuracy", scope, false, false);
    4747      if (accuracy == null) {
     
    5353      int nCorrect = 0;
    5454      for (int sample = start; sample < end; sample++) {
    55         double est = evaluator.Evaluate(sample);
     55        double est = evaluator.Evaluate(tree, sample);
    5656        double origClass = dataset.GetValue(sample, targetVariable);
    5757        double estClass = double.NaN;
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/ClassificationMeanSquaredErrorEvaluator.cs

    r1529 r1796  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4646      double errorsSquaredSum = 0;
    4747      for (int sample = start; sample < end; sample++) {
    48         double estimated = evaluator.Evaluate(sample);
     48        double estimated = evaluator.Evaluate(tree, sample);
    4949        double original = dataset.GetValue(sample, targetVariable);
    5050        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/ConfusionMatrixEvaluator.cs

    r1529 r1796  
    4141    }
    4242
    43     public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
     43    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4444      IntMatrixData matrix = GetVariableValue<IntMatrixData>("ConfusionMatrix", scope, false, false);
    4545      if (matrix == null) {
     
    5050      int nSamples = end - start;
    5151      for (int sample = start; sample < end; sample++) {
    52         double est = evaluator.Evaluate(sample);
     52        double est = evaluator.Evaluate(tree, sample);
    5353        double origClass = dataset.GetValue(sample, targetVariable);
    5454        int estClassIndex = -1;
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/GPClassificationEvaluatorBase.cs

    r1529 r1796  
    3737    }
    3838
    39     public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     39    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4040
    4141      ItemList<DoubleData> classes = GetVariableValue<ItemList<DoubleData>>("TargetClassValues", scope, true);
     
    4848      }
    4949
    50       Evaluate(scope, evaluator, dataset, targetVariable, classesArr, thresholds, start, end);
     50      Evaluate(scope, evaluator, tree, dataset, targetVariable, classesArr, thresholds, start, end);
    5151    }
    5252
    53     public abstract void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end);
     53    public abstract void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end);
    5454  }
    5555}
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassOneVsOneAnalyzer.cs

    r1529 r1796  
    3535    private const string TARGETVARIABLE = "TargetVariable";
    3636    private const string TARGETCLASSVALUES = "TargetClassValues";
     37    private const string TRAININGSAMPLESSTART = "TrainingSamplesStart";
     38    private const string TRAININGSAMPLESEND = "TrainingSamplesEnd";
    3739    private const string SAMPLESSTART = "SamplesStart";
    3840    private const string SAMPLESEND = "SamplesEnd";
     
    5658      AddVariableInfo(new VariableInfo(CLASSAVALUE, "The original class value of the class A in the subscope", typeof(DoubleData), VariableKind.In));
    5759      AddVariableInfo(new VariableInfo(CLASSBVALUE, "The original class value of the class B in the subscope", typeof(DoubleData), VariableKind.In));
     60      AddVariableInfo(new VariableInfo(TRAININGSAMPLESSTART, "The start of training samples in the original dataset", typeof(IntData), VariableKind.In));
     61      AddVariableInfo(new VariableInfo(TRAININGSAMPLESEND, "The end of training samples in the original dataset", typeof(IntData), VariableKind.In));
    5862      AddVariableInfo(new VariableInfo(SAMPLESSTART, "The start of samples in the original dataset", typeof(IntData), VariableKind.In));
    5963      AddVariableInfo(new VariableInfo(SAMPLESEND, "The end of samples in the original dataset", typeof(IntData), VariableKind.In));
     
    6771      Dataset dataset = GetVariableValue<Dataset>(DATASET, scope, true);
    6872      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
     73      int trainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data;
     74      int trainingSamplesEnd = GetVariableValue<IntData>(TRAININGSAMPLESEND, scope, true).Data;
    6975      int samplesStart = GetVariableValue<IntData>(SAMPLESSTART, scope, true).Data;
    7076      int samplesEnd = GetVariableValue<IntData>(SAMPLESEND, scope, true).Data;
     
    7985
    8086        BakedTreeEvaluator evaluator = new BakedTreeEvaluator();
    81         evaluator.ResetEvaluator(functionTree, dataset, targetVariable, samplesStart, samplesEnd, 1.0);
     87        evaluator.ResetEvaluator(dataset, targetVariable, trainingSamplesStart, trainingSamplesEnd, 1.0);
    8288
    8389        for(int i = 0; i < (samplesEnd - samplesStart); i++) {
    84           double est = evaluator.Evaluate(i + samplesStart);
     90          double est = evaluator.Evaluate(functionTree, i + samplesStart);
    8591          if(est < 0.5) {
    8692            CastVote(votes, i, classAValue, classValues);
Note: See TracChangeset for help on using the changeset viewer.