Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/05/12 11:58:17 (12 years ago)
Author:
mkommend
Message:

#1081: Merged trunk changes and fixed compilation errors due to the merge.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs

    r7989 r8742  
    4444    private const string EvaluationPartitionParameterName = "EvaluationPartition";
    4545    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
     46    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4647    private const string ValidRowIndicatorParameterName = "ValidRowIndicator";
    4748
     
    7172      get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
    7273    }
     74    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     75      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     76    }
    7377    public IValueLookupParameter<StringValue> ValidRowIndicatorParameter {
    7478      get { return (IValueLookupParameter<StringValue>)Parameters[ValidRowIndicatorParameterName]; }
     
    9195      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees."));
    9296      Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index."));
     97      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
    9398      Parameters.Add(new ValueLookupParameter<StringValue>(ValidRowIndicatorParameterName, "An indicator variable in the data set that specifies which rows should be evaluated (those for which the indicator <> 0) (optional)."));
    9499    }
     
    96101    [StorableHook(HookType.AfterDeserialization)]
    97102    private void AfterDeserialization() {
     103      if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>))
     104        Parameters.Remove(ApplyLinearScalingParameterName);
     105      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))
     106        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
    98107      if (!Parameters.ContainsKey(ValidRowIndicatorParameterName))
    99108        Parameters.Add(new ValueLookupParameter<StringValue>(ValidRowIndicatorParameterName, "An indicator variable in the data set that specifies which rows should be evaluated (those for which the indicator <> 0) (optional)."));
     
    105114
    106115    protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) {
    107 
    108116      IEnumerable<int> rows;
    109117      int samplesStart = EvaluationPartitionParameter.ActualValue.Start;
     
    131139      return rows;
    132140    }
     141
     142    [ThreadStatic]
     143    private static double[] cache;
     144    protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,
     145      double lowerEstimationLimit, double upperEstimationLimit,
     146      IOnlineCalculator calculator, int maxRows) {
     147      if (cache == null || cache.GetLength(0) < maxRows) {
     148        cache = new double[maxRows];
     149      }
     150
     151      //calculate linear scaling
     152      //the static methods of the calculator could not be used as it performs a check if the enumerators have an equal amount of elements
     153      //this is not true if the cache is used
     154      int i = 0;
     155      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
     156      var targetValuesEnumerator = targetValues.GetEnumerator();
     157      var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
     158      while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
     159        double target = targetValuesEnumerator.Current;
     160        double estimated = estimatedValuesEnumerator.Current;
     161        cache[i] = estimated;
     162        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
     163          linearScalingCalculator.Add(estimated, target);
     164        i++;
     165      }
     166      if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))
     167        throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
     168
     169      double alpha = linearScalingCalculator.Alpha;
     170      double beta = linearScalingCalculator.Beta;
     171      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {
     172        alpha = 0.0;
     173        beta = 1.0;
     174      }
     175
     176      //calculate the quality by using the passed online calculator
     177      targetValuesEnumerator = targetValues.GetEnumerator();
     178      var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha)
     179        .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator();
     180
     181      while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {
     182        calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);
     183      }
     184    }
    133185  }
    134186}
Note: See TracChangeset for help on using the changeset viewer.