Changeset 1894 for trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanSquaredErrorEvaluator.cs
- Timestamp:
- 05/25/09 18:43:26 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanSquaredErrorEvaluator.cs
r1891 r1894 28 28 using HeuristicLab.Operators; 29 29 using HeuristicLab.DataAnalysis; 30 using HeuristicLab.Modeling; 30 31 31 32 namespace HeuristicLab.GP.StructureIdentification { 32 public class MeanSquaredErrorEvaluator : GPEvaluatorBase { 33 public class MeanSquaredErrorEvaluator : SimpleGPEvaluatorBase { 34 public override string OutputVariableName { 35 get { 36 return "MSE"; 37 } 38 } 33 39 public override string Description { 34 40 get { … … 38 44 } 39 45 40 public MeanSquaredErrorEvaluator() 41 : base() { 42 AddVariableInfo(new VariableInfo("MSE", "The mean squared error of the model", typeof(DoubleData), VariableKind.New)); 43 } 46 public override double Evaluate(double[,] values) { 47 double quality = SimpleMSEEvaluator.Calculate(values); 44 48 45 public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 46 double errorsSquaredSum = 0; 47 int n = 0; 48 for (int sample = start; sample < end; sample++) { 49 double original = dataset.GetValue(sample, targetVariable); 50 double estimated = evaluator.Evaluate(sample); 51 if (updateTargetValues) { 52 dataset.SetValue(sample, targetVariable, estimated); 53 } 54 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 55 double error = estimated - original; 56 errorsSquaredSum += error * error; 57 n++; 58 } 49 if (double.IsNaN(quality) || double.IsInfinity(quality)) { 50 quality = double.MaxValue; 59 51 } 60 52 61 errorsSquaredSum /= n; 62 if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { 63 errorsSquaredSum = double.MaxValue; 64 } 65 66 DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false); 67 if (mse == null) { 68 mse = new DoubleData(); 69 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse)); 70 } 71 72 mse.Data = errorsSquaredSum; 53 return quality; 73 54 } 74 55 }
Note: See TracChangeset
for help on using the changeset viewer.