Changeset 2578 for trunk/sources/HeuristicLab.GP.StructureIdentification
- Timestamp:
- 01/02/10 18:10:15 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification/3.3
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/BaseClasses/TreeEvaluatorBase.cs
r2364 r2578 60 60 } 61 61 62 public void PrepareForEvaluation(Dataset dataset, IFunctionTree functionTree) { 62 [Obsolete] 63 public virtual void PrepareForEvaluation(Dataset dataset, IFunctionTree functionTree) { 63 64 this.dataset = dataset; 64 65 codeArr = new Instr[functionTree.GetSize()]; … … 94 95 } 95 96 96 public double Evaluate(int sampleIndex) { 97 [Obsolete] 98 public virtual double Evaluate(int sampleIndex) { 97 99 PC = 0; 98 100 this.sampleIndex = sampleIndex; … … 101 103 if (double.IsNaN(estimated)) estimated = UpperEvaluationLimit; 102 104 return estimated; 105 } 106 107 public virtual IEnumerable<double> Evaluate(Dataset dataset, IFunctionTree tree, IEnumerable<int> rows) { 108 PrepareForEvaluation(dataset, tree); 109 foreach (int row in rows) 110 yield return Evaluate(row); 103 111 } 104 112 -
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 -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HL2TreeEvaluator.cs
r2328 r2578 31 31 public HL2TreeEvaluator(double minValue, double maxValue) : base(minValue, maxValue) { } 32 32 33 [Obsolete] 33 34 protected override double EvaluateBakedCode() { 34 35 Instr currInstr = codeArr[PC++]; -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HL3TreeEvaluator.cs
r2449 r2578 33 33 public HL3TreeEvaluator(double minValue, double maxValue) : base(minValue, maxValue) { } 34 34 35 [Obsolete] 35 36 protected override double EvaluateBakedCode() { 36 37 Instr currInstr = codeArr[PC++]; -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ITreeEvaluator.cs
r2328 r2578 23 23 using HeuristicLab.DataAnalysis; 24 24 using HeuristicLab.GP.Interfaces; 25 using System; 26 using System.Collections.Generic; 25 27 26 28 namespace HeuristicLab.GP.StructureIdentification { … … 28 30 double LowerEvaluationLimit { get; set; } 29 31 double UpperEvaluationLimit { get; set; } 32 [Obsolete] 30 33 void PrepareForEvaluation(Dataset dataset, IFunctionTree functionTree); 34 [Obsolete] 31 35 double Evaluate(int sampleIndex); 36 IEnumerable<double> Evaluate(Dataset dataset, IFunctionTree functionTree, IEnumerable<int> rows); 32 37 } 33 38 }
Note: See TracChangeset
for help on using the changeset viewer.