Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/15/12 16:47:25 (11 years ago)
Author:
mkommend
Message:

#1763: merged changes from trunk into the tree simplifier branch.

File:
1 edited

Legend:

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

    r8127 r8915  
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3131  [StorableClass]
    32   public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator {
    33     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    34     public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {
    35       get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    36     }
    37     public bool ApplyLinearScaling {
    38       get { return ApplyLinearScalingParameter.Value.Value; }
    39       set { ApplyLinearScalingParameter.Value.Value = value; }
    40     }
    41 
     32  public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 
    4233    [StorableConstructor]
    4334    protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
    4435    protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
    45     protected SymbolicRegressionSingleObjectiveEvaluator()
    46       : base() {
    47       Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(true)));
    48       ApplyLinearScalingParameter.Hidden = true;
    49     }
    50 
    51     [StorableHook(HookType.AfterDeserialization)]
    52     private void AfterDeserialization() {
    53       if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
    54         Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(false)));
    55         ApplyLinearScalingParameter.Hidden = true;
    56       }
    57     }
    58 
    59     [ThreadStatic]
    60     private static double[] cache;
    61 
    62     protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,
    63       double lowerEstimationLimit, double upperEstimationLimit,
    64       IOnlineCalculator calculator, int maxRows) {
    65       if (cache == null || cache.GetLength(0) < maxRows) {
    66         cache = new double[maxRows];
    67       }
    68 
    69       //calculate linear scaling
    70       //the static methods of the calculator could not be used as it performs a check if the enumerators have an equal amount of elements
    71       //this is not true if the cache is used
    72       int i = 0;
    73       var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
    74       var targetValuesEnumerator = targetValues.GetEnumerator();
    75       var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
    76       while (targetValuesEnumerator.MoveNext() && estimatedValuesEnumerator.MoveNext()) {
    77         double target = targetValuesEnumerator.Current;
    78         double estimated = estimatedValuesEnumerator.Current;
    79         cache[i] = estimated;
    80         linearScalingCalculator.Add(estimated, target);
    81         i++;
    82       }
    83       double alpha = linearScalingCalculator.Alpha;
    84       double beta = linearScalingCalculator.Beta;
    85 
    86       //calculate the quality by using the passed online calculator
    87       targetValuesEnumerator = targetValues.GetEnumerator();
    88       var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha)
    89         .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator();
    90 
    91       while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {
    92         calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);
    93       }
    94     }
     36    protected SymbolicRegressionSingleObjectiveEvaluator(): base() {}   
    9537  }
    9638}
Note: See TracChangeset for help on using the changeset viewer.