Changeset 8742 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs
- Timestamp:
- 10/05/12 11:58:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs
r7989 r8742 44 44 private const string EvaluationPartitionParameterName = "EvaluationPartition"; 45 45 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 46 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 46 47 private const string ValidRowIndicatorParameterName = "ValidRowIndicator"; 47 48 … … 71 72 get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } 72 73 } 74 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 75 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 76 } 73 77 public IValueLookupParameter<StringValue> ValidRowIndicatorParameter { 74 78 get { return (IValueLookupParameter<StringValue>)Parameters[ValidRowIndicatorParameterName]; } … … 91 95 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.")); 92 96 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.")); 93 98 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).")); 94 99 } … … 96 101 [StorableHook(HookType.AfterDeserialization)] 97 102 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.")); 98 107 if (!Parameters.ContainsKey(ValidRowIndicatorParameterName)) 99 108 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).")); … … 105 114 106 115 protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) { 107 108 116 IEnumerable<int> rows; 109 117 int samplesStart = EvaluationPartitionParameter.ActualValue.Start; … … 131 139 return rows; 132 140 } 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 } 133 185 } 134 186 }
Note: See TracChangeset
for help on using the changeset viewer.