- Timestamp:
- 07/14/10 10:45:41 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs
r4022 r4034 260 260 lowerEstimationLimit, upperEstimationLimit, 261 261 ProblemData.Dataset, targetVariable, 262 validationStart, validationEnd);262 Enumerable.Range(validationStart, validationEnd - validationStart)); 263 263 264 264 if (validationMse < bestValidationMse) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionTournamentPruning.cs
r4028 r4034 216 216 int originalSize = tree.Size; 217 217 double originalMse = SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(interpreter, tree, 218 lowerEstimationLimit, upperEstimationLimit, problemData.Dataset, problemData.TargetVariable.Value, samplesStart, samplesEnd);218 lowerEstimationLimit, upperEstimationLimit, problemData.Dataset, problemData.TargetVariable.Value, Enumerable.Range(samplesStart, samplesEnd - samplesStart)); 219 219 220 220 int minPrunedSize = (int)(originalSize * (1 - maxPruningRatio)); … … 252 252 253 253 double prunedMse = SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(interpreter, clonedTree, 254 lowerEstimationLimit, upperEstimationLimit, problemData.Dataset, problemData.TargetVariable.Value, samplesStart, samplesEnd);254 lowerEstimationLimit, upperEstimationLimit, problemData.Dataset, problemData.TargetVariable.Value, Enumerable.Range(samplesStart, samplesEnd - samplesStart)); 255 255 double prunedSize = clonedTree.Size; 256 256 // MSE of the pruned tree is larger than the original tree in most cases -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs
r3982 r4034 40 40 [StorableClass] 41 41 public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator { 42 private const string RandomParameterName = "Random"; 42 43 private const string QualityParameterName = "Quality"; 43 44 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; … … 46 47 private const string SamplesStartParameterName = "SamplesStart"; 47 48 private const string SamplesEndParameterName = "SamplesEnd"; 49 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 48 50 #region ISymbolicRegressionEvaluator Members 49 51 … … 72 74 } 73 75 76 public IValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { 77 get { return (IValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } 78 } 79 80 public ILookupParameter<IRandom> RandomParameter { 81 get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; } 82 } 83 74 84 #endregion 75 85 #region properties 86 public IRandom Random { 87 get { return RandomParameter.ActualValue; } 88 } 76 89 public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { 77 90 get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; } … … 89 102 get { return SamplesEndParameter.ActualValue; } 90 103 } 104 105 public PercentValue RelativeNumberOfEvaluatedSamples { 106 get { return RelativeNumberOfEvaluatedSamplesParameter.Value; } 107 } 91 108 #endregion 92 109 93 110 public SymbolicRegressionEvaluator() 94 111 : base() { 112 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator to use.")); 95 113 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic regression solution.")); 96 114 Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree.")); … … 99 117 Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic regression solution should be evaluated.")); 100 118 Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic regression solution should be evaluated.")); 119 Parameters.Add(new ValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.", new PercentValue(1))); 120 } 121 122 [StorableConstructor] 123 protected SymbolicRegressionEvaluator(bool deserializing) : base(deserializing) { } 124 [StorableHook(Persistence.Default.CompositeSerializers.Storable.HookType.AfterDeserialization)] 125 private void AfterDeserialization() { 126 if (!Parameters.ContainsKey(RelativeNumberOfEvaluatedSamplesParameterName)) 127 Parameters.Add(new ValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.", new PercentValue(1))); 128 if (!Parameters.ContainsKey(RandomParameterName)) 129 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator to use.")); 101 130 } 102 131 103 132 public override IOperation Apply() { 104 QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset, 105 RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd)); 133 IEnumerable<int> rows = GenerateRowsToEvaluate(RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value); 134 double quality = Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset, 135 RegressionProblemData.TargetVariable, rows); 136 QualityParameter.ActualValue = new DoubleValue(quality); 106 137 return base.Apply(); 138 } 139 140 141 //algorithm taken from progamming pearls page 127 142 private IEnumerable<int> GenerateRowsToEvaluate(double relativeAmount, int start, int end) { 143 int count = (int)((end - start) * relativeAmount); 144 if (count == 0) count = 1; 145 146 int remaining = end - start; 147 for (int i = start; i < end && count > 0; i++) { 148 double probabilty = Random.NextDouble(); 149 if (probabilty < ((double)count) / remaining) { 150 count--; 151 yield return i; 152 } 153 remaining--; 154 } 107 155 } 108 156 … … 111 159 Dataset dataset, 112 160 StringValue targetVariable, 113 I ntValue samplesStart, IntValue samplesEnd);161 IEnumerable<int> rows); 114 162 } 115 163 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs
r3996 r4034 66 66 } 67 67 68 protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, I ntValue samplesStart, IntValue samplesEnd) {69 double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);68 protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IEnumerable<int> rows) { 69 double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows); 70 70 return mse; 71 71 } 72 72 73 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, int start, int end) {74 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start));75 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, start, end);73 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows) { 74 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 75 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 76 76 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 77 77 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs
r4027 r4034 66 66 } 67 67 68 protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, I ntValue samplesStart, IntValue samplesEnd) {68 protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IEnumerable<int> rows) { 69 69 double alpha, beta; 70 double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value, out beta, out alpha);70 double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha); 71 71 AlphaParameter.ActualValue = new DoubleValue(alpha); 72 72 BetaParameter.ActualValue = new DoubleValue(beta); … … 74 74 } 75 75 76 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, int start, int end, out double beta, out double alpha) {77 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, start, end);78 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start));76 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha) { 77 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable,rows); 78 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 79 79 CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha); 80 80 81 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, start, end, beta, alpha);81 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha); 82 82 } 83 83 84 public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, int start, int end, double beta, double alpha) {85 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start));86 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, start, end);84 public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha) { 85 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 86 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 87 87 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 88 88 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
Note: See TracChangeset
for help on using the changeset viewer.