Changeset 9126 for branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators
- Timestamp:
- 01/08/13 15:36:13 (12 years ago)
- Location:
- branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Property svn:ignore
-
old new 1 *.user 2 Plugin.cs 1 3 bin 2 *.user3 HeuristicLabProblemsDataAnalysisSymbolicPlugin.cs4 4 obj 5 *.vs10x6 Plugin.cs
-
- Property svn:ignore
-
branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs
r7259 r9126 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 29 using HeuristicLab.Operators; 30 using HeuristicLab.Optimization; 30 31 using HeuristicLab.Parameters; 31 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 35 36 [StorableClass] 36 37 public abstract class SymbolicDataAnalysisEvaluator<T> : SingleSuccessorOperator, 37 ISymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator 38 ISymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, IStochasticOperator 38 39 where T : class, IDataAnalysisProblemData { 39 40 private const string RandomParameterName = "Random"; … … 44 45 private const string EvaluationPartitionParameterName = "EvaluationPartition"; 45 46 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 47 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 48 private const string ValidRowIndicatorParameterName = "ValidRowIndicator"; 46 49 47 50 public override bool CanChangeName { get { return false; } } 48 51 49 52 #region parameter properties 53 ILookupParameter<IRandom> IStochasticOperator.RandomParameter { 54 get { return RandomParameter; } 55 } 56 50 57 public IValueLookupParameter<IRandom> RandomParameter { 51 58 get { return (IValueLookupParameter<IRandom>)Parameters[RandomParameterName]; } … … 70 77 get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } 71 78 } 79 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 80 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 81 } 82 public IValueLookupParameter<StringValue> ValidRowIndicatorParameter { 83 get { return (IValueLookupParameter<StringValue>)Parameters[ValidRowIndicatorParameterName]; } 84 } 72 85 #endregion 73 86 … … 87 100 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 101 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.")); 102 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 103 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).")); 104 } 105 106 [StorableHook(HookType.AfterDeserialization)] 107 private void AfterDeserialization() { 108 if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>)) 109 Parameters.Remove(ApplyLinearScalingParameterName); 110 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) 111 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 112 if (!Parameters.ContainsKey(ValidRowIndicatorParameterName)) 113 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).")); 89 114 } 90 115 … … 94 119 95 120 protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) { 96 97 98 121 IEnumerable<int> rows; 99 122 int samplesStart = EvaluationPartitionParameter.ActualValue.Start; … … 101 124 int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start; 102 125 int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End; 103 104 126 if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value."); 105 127 … … 113 135 } 114 136 115 return rows.Where(i => i < testPartitionStart || testPartitionEnd <= i); 137 rows = rows.Where(i => i < testPartitionStart || testPartitionEnd <= i); 138 if (ValidRowIndicatorParameter.ActualValue != null) { 139 string indicatorVar = ValidRowIndicatorParameter.ActualValue.Value; 140 var problemData = ProblemDataParameter.ActualValue; 141 var indicatorRow = problemData.Dataset.GetReadOnlyDoubleValues(indicatorVar); 142 rows = rows.Where(r => !indicatorRow[r].IsAlmost(0.0)); 143 } 144 return rows; 145 } 146 147 [ThreadStatic] 148 private static double[] cache; 149 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, 150 double lowerEstimationLimit, double upperEstimationLimit, 151 IOnlineCalculator calculator, int maxRows) { 152 if (cache == null || cache.Length < maxRows) { 153 cache = new double[maxRows]; 154 } 155 156 // calculate linear scaling 157 int i = 0; 158 var linearScalingCalculator = new OnlineLinearScalingParameterCalculator(); 159 var targetValuesEnumerator = targetValues.GetEnumerator(); 160 var estimatedValuesEnumerator = estimatedValues.GetEnumerator(); 161 while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) { 162 double target = targetValuesEnumerator.Current; 163 double estimated = estimatedValuesEnumerator.Current; 164 cache[i] = estimated; 165 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated)) 166 linearScalingCalculator.Add(estimated, target); 167 i++; 168 } 169 if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext())) 170 throw new ArgumentException("Number of elements in target and estimated values enumeration do not match."); 171 172 double alpha = linearScalingCalculator.Alpha; 173 double beta = linearScalingCalculator.Beta; 174 if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) { 175 alpha = 0.0; 176 beta = 1.0; 177 } 178 179 //calculate the quality by using the passed online calculator 180 targetValuesEnumerator = targetValues.GetEnumerator(); 181 var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha) 182 .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator(); 183 184 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) { 185 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current); 186 } 116 187 } 117 188 }
Note: See TracChangeset
for help on using the changeset viewer.