Changeset 1894 for trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VarianceAccountedForEvaluator.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/VarianceAccountedForEvaluator.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 VarianceAccountedForEvaluator : GPEvaluatorBase { 33 /// <summary> 34 /// The Variance Accounted For (VAF) function calculates is computed as 35 /// VAF(y,y') = ( 1 - var(y-y')/var(y) ) 36 /// where y' denotes the predicted / modelled values for y and var(x) the variance of a signal x. 37 /// </summary> 38 public class VarianceAccountedForEvaluator : SimpleGPEvaluatorBase { 39 public override string OutputVariableName { 40 get { 41 return "VAF"; 42 } 43 } 33 44 public override string Description { 34 45 get { … … 42 53 } 43 54 44 /// <summary> 45 /// The Variance Accounted For (VAF) function calculates is computed as 46 /// VAF(y,y') = ( 1 - var(y-y')/var(y) ) 47 /// where y' denotes the predicted / modelled values for y and var(x) the variance of a signal x. 48 /// </summary> 49 public VarianceAccountedForEvaluator() 50 : base() { 51 AddVariableInfo(new VariableInfo("VAF", "The variance-accounted-for quality of the model", typeof(DoubleData), VariableKind.New)); 52 53 } 54 55 public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 56 int nSamples = end - start; 57 double[] errors = new double[nSamples]; 58 double[] originalTargetVariableValues = new double[nSamples]; 59 for (int sample = start; sample < end; sample++) { 60 double estimated = evaluator.Evaluate(sample); 61 double original = dataset.GetValue(sample, targetVariable); 62 if (updateTargetValues) { 63 dataset.SetValue(sample, targetVariable, estimated); 64 } 65 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 66 errors[sample - start] = original - estimated; 67 originalTargetVariableValues[sample - start] = original; 68 } else { 69 errors[sample - start] = double.NaN; 70 originalTargetVariableValues[sample - start] = double.NaN; 71 } 72 } 73 double errorsVariance = Statistics.Variance(errors); 74 double originalsVariance = Statistics.Variance(originalTargetVariableValues); 75 double quality = 1 - errorsVariance / originalsVariance; 55 public override double Evaluate(double[,] values) { 56 double quality = SimpleVarianceAccountedForEvaluator.Calculate(values); 76 57 77 58 if (double.IsNaN(quality) || double.IsInfinity(quality)) { 78 59 quality = double.MaxValue; 79 60 } 80 DoubleData vaf = GetVariableValue<DoubleData>("VAF", scope, false, false); 81 if (vaf == null) { 82 vaf = new DoubleData(); 83 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("VAF"), vaf)); 84 } 85 86 vaf.Data = quality; 61 return quality; 87 62 } 88 63 }
Note: See TracChangeset
for help on using the changeset viewer.