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