Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/30/12 22:48:32 (12 years ago)
Author:
mkommend
Message:

#1788: Implemente new symbolic regression evaluators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r7672 r7677  
    2020#endregion
    2121
    22 
     22using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    5455      }
    5556    }
     57
     58    [ThreadStatic]
     59    private static double[] cache;
     60
     61    protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, IOnlineCalculator calculator, int maxRows) {
     62      if (cache == null || cache.GetLength(0) < maxRows) {
     63        cache = new double[maxRows];
     64      }
     65
     66      //calculate linear scaling
     67      //the static methods of the calculator could not be used as it performs a check if the enumerators have an equal amount of elements
     68      //this is not true if the cache is used
     69      int i = 0;
     70      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
     71      var targetValuesEnumerator = targetValues.GetEnumerator();
     72      var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
     73      while (targetValuesEnumerator.MoveNext() && estimatedValuesEnumerator.MoveNext()) {
     74        double target = targetValuesEnumerator.Current;
     75        double estimated = estimatedValuesEnumerator.Current;
     76        cache[i] = estimated;
     77        linearScalingCalculator.Add(estimated, target);
     78        i++;
     79      }
     80      double alpha = linearScalingCalculator.Alpha;
     81      double beta = linearScalingCalculator.Beta;
     82
     83      //calculate the quality by using the passed online calculator
     84      targetValuesEnumerator = targetValues.GetEnumerator();
     85      i = 0;
     86      while (targetValuesEnumerator.MoveNext()) {
     87        double target = targetValuesEnumerator.Current;
     88        double estimated = cache[i] * beta + alpha;
     89        calculator.Add(target, estimated);
     90        i++;
     91      }
     92    }
    5693  }
    5794}
Note: See TracChangeset for help on using the changeset viewer.