- Timestamp:
- 01/02/10 18:10:15 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/EarlyStoppingMeanSquaredErrorEvaluator.cs
r2577 r2578 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using System; 25 using HeuristicLab.GP.Interfaces; 26 using HeuristicLab.DataAnalysis; 27 using System.Collections; 28 using System.Collections.Generic; 29 using System.Linq; 24 30 25 31 namespace HeuristicLab.GP.StructureIdentification { … … 39 45 40 46 // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE 41 public override void Evaluate(IScope scope, I TreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end) {47 public override void Evaluate(IScope scope, IFunctionTree tree, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) { 42 48 double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, true).Data; 43 49 DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false); … … 46 52 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse)); 47 53 } 48 49 54 double errorsSquaredSum = 0; 50 55 int rows = end - start; 51 56 int n = 0; 52 for (int sample = start; sample < end; sample++) {53 double estimated = evaluator.Evaluate(sample);57 int sample = start; 58 foreach (var estimatedValue in evaluator.Evaluate(dataset, tree, Enumerable.Range(start, end - start))) { 54 59 double original = dataset.GetValue(sample, targetVariable); 55 60 56 61 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 57 double error = estimated - original;62 double error = estimatedValue - original; 58 63 errorsSquaredSum += error * error; 59 64 n++; 60 65 } 61 // check the limit and stop as soon as we hit the limit62 if ( errorsSquaredSum / rows >= qualityLimit) {66 // check the limit every 30 samples and stop as soon as we hit the limit 67 if (n % 30 == 29 && errorsSquaredSum / rows >= qualityLimit) { 63 68 mse.Data = errorsSquaredSum / (n + 1); // return estimated MSE (when the remaining errors are on average the same) 64 69 return; 65 70 } 71 sample++; 66 72 } 67 73 errorsSquaredSum /= n; -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs
r2577 r2578 46 46 int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data; 47 47 int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data; 48 48 49 ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true); 49 50 evaluator.PrepareForEvaluation(dataset, gpModel.FunctionTree); 51 Evaluate(scope, evaluator, dataset, targetVariable, start, end); 50 Evaluate(scope, gpModel.FunctionTree, evaluator, dataset, targetVariable, start, end); 52 51 53 52 // update the value of total evaluated nodes … … 56 55 } 57 56 58 public abstract void Evaluate(IScope scope, I TreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end);57 public abstract void Evaluate(IScope scope, IFunctionTree tree, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end); 59 58 } 60 59 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/NodeBasedVariableImpactCalculator.cs
r2454 r2578 138 138 139 139 private static double CalculateMSE(Dataset dataset, ITreeEvaluator evaluator, IFunctionTree tree, int targetVariable, int start, int end) { 140 double[,] values = new double[end - start, 2]; 141 evaluator.PrepareForEvaluation(dataset, tree); 142 for (int i = start; i < end; i++) { 143 values[i - start, 0] = dataset.GetValue(i, targetVariable); 144 values[i - start, 1] = evaluator.Evaluate(i); 145 } 140 141 double[,] values = Matrix<double>.Create( 142 dataset.GetVariableValues(targetVariable, start, end), 143 evaluator.Evaluate(dataset, tree, Enumerable.Range(start, end - start)).ToArray()); 146 144 return SimpleMSEEvaluator.Calculate(values); 147 145 } … … 155 153 156 154 private static double CalculateReplacementValue(Dataset dataset, ITreeEvaluator evaluator, IFunctionTree tree, int targetVariable, int start, int end) { 157 double[] values = new double[end - start]; 158 evaluator.PrepareForEvaluation(dataset, tree); 159 for (int i = start; i < end; i++) { 160 values[i - start] = evaluator.Evaluate(i); 161 } 162 return Statistics.Median(values); 155 return Statistics.Median(evaluator.Evaluate(dataset, tree, Enumerable.Range(start, end - start)).ToArray()); 163 156 } 164 157 -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/SimpleEvaluator.cs
r2577 r2578 23 23 using HeuristicLab.Data; 24 24 using HeuristicLab.DataAnalysis; 25 using HeuristicLab.GP.Interfaces; 26 using HeuristicLab.Modeling; 27 using System.Linq; 25 28 26 29 namespace HeuristicLab.GP.StructureIdentification { … … 31 34 } 32 35 33 public override void Evaluate(IScope scope, I TreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) {36 public override void Evaluate(IScope scope, IFunctionTree tree, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) { 34 37 DoubleMatrixData values = GetVariableValue<DoubleMatrixData>("Values", scope, false, false); 35 38 if (values == null) { … … 42 45 } 43 46 44 double[,] v = new double[end - start, 2]; 45 46 for (int sample = start; sample < end; sample++) { 47 double estimated = evaluator.Evaluate(sample); 48 double original = dataset.GetValue(sample, targetVariable); 49 50 v[sample - start, 0] = original; 51 v[sample - start, 1] = estimated; 52 } 47 double[,] v = Matrix<double>.Create( 48 dataset.GetVariableValues(targetVariable, start, end), 49 evaluator.Evaluate(dataset, tree, Enumerable.Range(start, end - start)).ToArray()); 53 50 values.Data = v; 54 51 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/SimpleGPEvaluatorBase.cs
r2577 r2578 23 23 using HeuristicLab.Data; 24 24 using HeuristicLab.DataAnalysis; 25 using HeuristicLab.Modeling; 26 using HeuristicLab.GP.Interfaces; 27 using System.Linq; 25 28 26 29 namespace HeuristicLab.GP.StructureIdentification { … … 33 36 } 34 37 35 public override void Evaluate(IScope scope, I TreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) {38 public override void Evaluate(IScope scope, IFunctionTree tree, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end) { 36 39 // store original and estimated values in a double array 37 double[,] values = new double[end - start, 2]; 38 for (int sample = start; sample < end; sample++) { 39 double original = dataset.GetValue(sample, targetVariable); 40 double estimated = evaluator.Evaluate(sample); 41 42 values[sample - start, 0] = estimated; 43 values[sample - start, 1] = original; 44 } 40 double[,] values = Matrix<double>.Create( 41 dataset.GetVariableValues(targetVariable, start, end), 42 evaluator.Evaluate(dataset, tree, Enumerable.Range(start, end - start)).ToArray()); 45 43 46 44 double quality = Evaluate(values); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/UncertainMeanSquaredErrorEvaluator.cs
r2577 r2578 24 24 using HeuristicLab.Data; 25 25 using HeuristicLab.Random; 26 using HeuristicLab.GP.Interfaces; 27 using System.Collections.Generic; 28 using System.Linq; 26 29 27 30 namespace HeuristicLab.GP.StructureIdentification { … … 45 48 46 49 // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE 47 public override void Evaluate(IScope scope, I TreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end) {50 public override void Evaluate(IScope scope, IFunctionTree tree, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end) { 48 51 double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, true).Data; 49 52 int minSamples = GetVariableValue<IntData>("MinEvaluatedSamples", scope, true).Data; … … 72 75 int[] indexes = InitIndexes(mt, start, end); 73 76 int n = 0; 74 for (int sample = 0; sample < rows; sample++) {75 double estimated = evaluator.Evaluate(indexes[sample]);77 int sample = 0; 78 foreach (double estimated in evaluator.Evaluate(dataset, tree, indexes)) { 76 79 double original = dataset.GetValue(indexes[sample], targetVariable); 77 80 if (!double.IsNaN(original) && !double.IsInfinity(original)) { … … 91 94 } 92 95 } 96 sample++; 93 97 } 94 98
Note: See TracChangeset
for help on using the changeset viewer.