Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/05/08 21:34:12 (16 years ago)
Author:
gkronber
Message:

fixed a stupid mistake introduced with r702 #328 (GP evaluation doesn't work in a thread parallel engine).

Location:
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators
Files:
7 edited

Legend:

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

    r702 r712  
    4646      double originalDeviationTotalSumOfSquares = 0.0;
    4747      double targetMean = dataset.GetMean(targetVariable, start, end);
    48       for(int sample = start; sample < end; sample++) {
     48      for (int sample = start; sample < end; sample++) {
    4949        double estimated = evaluator.Evaluate(sample);
    50         double original = dataset.GetValue(targetVariable, sample);
    51         if(updateTargetValues) {
    52           dataset.SetValue(targetVariable, sample, estimated);
     50        double original = dataset.GetValue(sample, targetVariable);
     51        if (updateTargetValues) {
     52          dataset.SetValue(sample, targetVariable, estimated);
    5353        }
    54         if(!double.IsNaN(original) && !double.IsInfinity(original)) {
     54        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
    5555          double error = estimated - original;
    5656          errorsSquaredSum += error * error;
     
    6262
    6363      double quality = 1 - errorsSquaredSum / originalDeviationTotalSumOfSquares;
    64       if(quality > 1)
     64      if (quality > 1)
    6565        throw new InvalidProgramException();
    66       if(double.IsNaN(quality) || double.IsInfinity(quality))
     66      if (double.IsNaN(quality) || double.IsInfinity(quality))
    6767        quality = double.MaxValue;
    6868
    6969      DoubleData r2 = GetVariableValue<DoubleData>("R2", scope, false, false);
    70       if(r2 == null) {
     70      if (r2 == null) {
    7171        r2 = new DoubleData();
    7272        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("R2"), r2));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/EarlyStoppingMeanSquaredErrorEvaluator.cs

    r702 r712  
    4747      double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
    4848      DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
    49       if(mse == null) {
     49      if (mse == null) {
    5050        mse = new DoubleData();
    5151        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse));
     
    5454      double errorsSquaredSum = 0;
    5555      int rows = end - start;
    56       for(int sample = start; sample < end; sample++) {
     56      for (int sample = start; sample < end; sample++) {
    5757        double estimated = evaluator.Evaluate(sample);
    58         double original = dataset.GetValue(targetVariable, sample);
    59         if(updateTargetValues) {
    60           dataset.SetValue(targetVariable, sample, estimated);
     58        double original = dataset.GetValue(sample, targetVariable);
     59        if (updateTargetValues) {
     60          dataset.SetValue(sample, targetVariable, estimated);
    6161        }
    62         if(!double.IsNaN(original) && !double.IsInfinity(original)) {
     62        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
    6363          double error = estimated - original;
    6464          errorsSquaredSum += error * error;
    6565        }
    6666        // check the limit and stop as soon as we hit the limit
    67         if(errorsSquaredSum / rows >= qualityLimit) {
     67        if (errorsSquaredSum / rows >= qualityLimit) {
    6868          mse.Data = errorsSquaredSum / (sample - start + 1); // return estimated MSE (when the remaining errors are on average the same)
    6969          return;
     
    7171      }
    7272      errorsSquaredSum /= rows;
    73       if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
     73      if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
    7474        errorsSquaredSum = double.MaxValue;
    7575      }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/GPEvaluatorBase.cs

    r702 r712  
    5757      double[] backupValues = null;
    5858      // prepare for autoregressive modelling by saving the original values of the target-variable to a backup array
    59       if(useEstimatedValues &&
    60         (backupValues == null || backupValues.Length!=end-start)) {
     59      if (useEstimatedValues &&
     60        (backupValues == null || backupValues.Length != end - start)) {
    6161        backupValues = new double[end - start];
    62         for(int i = start; i < end; i++) {
     62        for (int i = start; i < end; i++) {
    6363          backupValues[i - start] = dataset.GetValue(i, targetVariable);
    6464        }
     
    7272
    7373      // restore the values of the target variable from the backup array if necessary
    74       if(useEstimatedValues) {
    75         for(int i = start; i < end; i++) {
     74      if (useEstimatedValues) {
     75        for (int i = start; i < end; i++) {
    7676          dataset.SetValue(i, targetVariable, backupValues[i - start]);
    7777        }
     
    7979
    8080      // update the value of total evaluated nodes
    81       scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (end-start);
     81      scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (end - start);
    8282      return null;
    8383    }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/MeanAbsolutePercentageErrorEvaluator.cs

    r702 r712  
    4646      double errorsSum = 0.0;
    4747      int n = 0;
    48       for(int sample = start; sample < end; sample++) {
     48      for (int sample = start; sample < end; sample++) {
    4949        double estimated = evaluator.Evaluate(sample);
    50         double original = dataset.GetValue(targetVariable, sample);
     50        double original = dataset.GetValue(sample, targetVariable);
    5151
    52         if(updateTargetValues) {
    53           dataset.SetValue(targetVariable, sample, estimated);
     52        if (updateTargetValues) {
     53          dataset.SetValue(sample, targetVariable, estimated);
    5454        }
    55        
    56         if(!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) {
     55
     56        if (!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) {
    5757          double percent_error = Math.Abs((estimated - original) / original);
    5858          errorsSum += percent_error;
     
    6161      }
    6262      double quality = errorsSum / n;
    63       if(double.IsNaN(quality) || double.IsInfinity(quality))
     63      if (double.IsNaN(quality) || double.IsInfinity(quality))
    6464        quality = double.MaxValue;
    6565
    6666      // create a variable for the MAPE
    6767      DoubleData mape = GetVariableValue<DoubleData>("MAPE", scope, false, false);
    68       if(mape == null) {
     68      if (mape == null) {
    6969        mape = new DoubleData();
    7070        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MAPE"), mape));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/MeanSquaredErrorEvaluator.cs

    r702 r712  
    4545    public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4646      double errorsSquaredSum = 0;
    47       for(int sample = start; sample < end; sample++) {
    48         double original = dataset.GetValue(targetVariable, sample);
     47      for (int sample = start; sample < end; sample++) {
     48        double original = dataset.GetValue(sample, targetVariable);
    4949        double estimated = evaluator.Evaluate(sample);
    50         if(updateTargetValues) {
    51           dataset.SetValue(targetVariable, sample, estimated);
     50        if (updateTargetValues) {
     51          dataset.SetValue(sample, targetVariable, estimated);
    5252        }
    53         if(!double.IsNaN(original) && !double.IsInfinity(original)) {
     53        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
    5454          double error = estimated - original;
    5555          errorsSquaredSum += error * error;
     
    5858
    5959      errorsSquaredSum /= (end - start);
    60       if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
     60      if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
    6161        errorsSquaredSum = double.MaxValue;
    6262      }
    6363
    6464      DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
    65       if(mse == null) {
     65      if (mse == null) {
    6666        mse = new DoubleData();
    6767        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/SimpleEvaluator.cs

    r702 r712  
    3838    public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    3939      ItemList values = GetVariableValue<ItemList>("Values", scope, false, false);
    40       if(values == null) {
     40      if (values == null) {
    4141        values = new ItemList();
    4242        IVariableInfo info = GetVariableInfo("Values");
    43         if(info.Local)
     43        if (info.Local)
    4444          AddVariable(new HeuristicLab.Core.Variable(info.ActualName, values));
    4545        else
     
    4848      values.Clear();
    4949
    50       for(int sample = start; sample < end; sample++) {
     50      for (int sample = start; sample < end; sample++) {
    5151        ItemList row = new ItemList();
    5252        double estimated = evaluator.Evaluate(sample);
    53         double original = dataset.GetValue(targetVariable, sample);
    54         if(updateTargetValues) {
    55           dataset.SetValue(targetVariable, sample, estimated);
     53        double original = dataset.GetValue(sample, targetVariable);
     54        if (updateTargetValues) {
     55          dataset.SetValue(sample, targetVariable, estimated);
    5656        }
    5757        row.Add(new DoubleData(estimated));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/VarianceAccountedForEvaluator.cs

    r702 r712  
    5757      double[] errors = new double[nSamples];
    5858      double[] originalTargetVariableValues = new double[nSamples];
    59       for(int sample = start; sample < end; sample++) {
     59      for (int sample = start; sample < end; sample++) {
    6060        double estimated = evaluator.Evaluate(sample);
    61         double original = dataset.GetValue(targetVariable, sample);
    62         if(updateTargetValues) {
    63           dataset.SetValue(targetVariable, sample, estimated);
     61        double original = dataset.GetValue(sample, targetVariable);
     62        if (updateTargetValues) {
     63          dataset.SetValue(sample, targetVariable, estimated);
    6464        }
    65         if(!double.IsNaN(original) && !double.IsInfinity(original)) {
     65        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
    6666          errors[sample - start] = original - estimated;
    6767          originalTargetVariableValues[sample - start] = original;
     
    7272      double quality = 1 - errorsVariance / originalsVariance;
    7373
    74       if(double.IsNaN(quality) || double.IsInfinity(quality)) {
     74      if (double.IsNaN(quality) || double.IsInfinity(quality)) {
    7575        quality = double.MaxValue;
    7676      }
    7777      DoubleData vaf = GetVariableValue<DoubleData>("VAF", scope, false, false);
    78       if(vaf == null) {
     78      if (vaf == null) {
    7979        vaf = new DoubleData();
    8080        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("VAF"), vaf));
Note: See TracChangeset for help on using the changeset viewer.