- Timestamp:
- 09/17/12 11:18:40 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs
r7259 r8664 44 44 private const string EvaluationPartitionParameterName = "EvaluationPartition"; 45 45 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 46 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 46 47 47 48 public override bool CanChangeName { get { return false; } } … … 70 71 get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } 71 72 } 73 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 74 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 75 } 72 76 #endregion 73 77 … … 87 91 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.")); 88 92 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.")); 93 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 94 } 95 96 [StorableHook(HookType.AfterDeserialization)] 97 private void AfterDeserialization() { 98 if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>)) 99 Parameters.Remove(ApplyLinearScalingParameterName); 100 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) 101 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 89 102 } 90 103 … … 94 107 95 108 protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) { 96 97 98 109 IEnumerable<int> rows; 99 110 int samplesStart = EvaluationPartitionParameter.ActualValue.Start; … … 115 126 return rows.Where(i => i < testPartitionStart || testPartitionEnd <= i); 116 127 } 128 129 [ThreadStatic] 130 private static double[] cache; 131 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, 132 double lowerEstimationLimit, double upperEstimationLimit, 133 IOnlineCalculator calculator, int maxRows) { 134 if (cache == null || cache.GetLength(0) < maxRows) { 135 cache = new double[maxRows]; 136 } 137 138 //calculate linear scaling 139 //the static methods of the calculator could not be used as it performs a check if the enumerators have an equal amount of elements 140 //this is not true if the cache is used 141 int i = 0; 142 var linearScalingCalculator = new OnlineLinearScalingParameterCalculator(); 143 var targetValuesEnumerator = targetValues.GetEnumerator(); 144 var estimatedValuesEnumerator = estimatedValues.GetEnumerator(); 145 while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) { 146 double target = targetValuesEnumerator.Current; 147 double estimated = estimatedValuesEnumerator.Current; 148 cache[i] = estimated; 149 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated)) 150 linearScalingCalculator.Add(estimated, target); 151 i++; 152 } 153 if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext())) 154 throw new ArgumentException("Number of elements in target and estimated values enumeration do not match."); 155 156 double alpha = linearScalingCalculator.Alpha; 157 double beta = linearScalingCalculator.Beta; 158 if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) { 159 alpha = 0.0; 160 beta = 1.0; 161 } 162 163 //calculate the quality by using the passed online calculator 164 targetValuesEnumerator = targetValues.GetEnumerator(); 165 var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha) 166 .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator(); 167 168 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) { 169 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current); 170 } 171 } 117 172 } 118 173 }
Note: See TracChangeset
for help on using the changeset viewer.