Changeset 712 for trunk/sources/HeuristicLab.GP.StructureIdentification
- Timestamp:
- 11/05/08 21:34:12 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/CoefficientOfDeterminationEvaluator.cs
r702 r712 46 46 double originalDeviationTotalSumOfSquares = 0.0; 47 47 double targetMean = dataset.GetMean(targetVariable, start, end); 48 for (int sample = start; sample < end; sample++) {48 for (int sample = start; sample < end; sample++) { 49 49 double estimated = evaluator.Evaluate(sample); 50 double original = dataset.GetValue( targetVariable, sample);51 if (updateTargetValues) {52 dataset.SetValue( targetVariable, sample, estimated);50 double original = dataset.GetValue(sample, targetVariable); 51 if (updateTargetValues) { 52 dataset.SetValue(sample, targetVariable, estimated); 53 53 } 54 if (!double.IsNaN(original) && !double.IsInfinity(original)) {54 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 55 55 double error = estimated - original; 56 56 errorsSquaredSum += error * error; … … 62 62 63 63 double quality = 1 - errorsSquaredSum / originalDeviationTotalSumOfSquares; 64 if (quality > 1)64 if (quality > 1) 65 65 throw new InvalidProgramException(); 66 if (double.IsNaN(quality) || double.IsInfinity(quality))66 if (double.IsNaN(quality) || double.IsInfinity(quality)) 67 67 quality = double.MaxValue; 68 68 69 69 DoubleData r2 = GetVariableValue<DoubleData>("R2", scope, false, false); 70 if (r2 == null) {70 if (r2 == null) { 71 71 r2 = new DoubleData(); 72 72 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("R2"), r2)); -
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/EarlyStoppingMeanSquaredErrorEvaluator.cs
r702 r712 47 47 double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data; 48 48 DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false); 49 if (mse == null) {49 if (mse == null) { 50 50 mse = new DoubleData(); 51 51 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse)); … … 54 54 double errorsSquaredSum = 0; 55 55 int rows = end - start; 56 for (int sample = start; sample < end; sample++) {56 for (int sample = start; sample < end; sample++) { 57 57 double estimated = evaluator.Evaluate(sample); 58 double original = dataset.GetValue( targetVariable, sample);59 if (updateTargetValues) {60 dataset.SetValue( targetVariable, sample, estimated);58 double original = dataset.GetValue(sample, targetVariable); 59 if (updateTargetValues) { 60 dataset.SetValue(sample, targetVariable, estimated); 61 61 } 62 if (!double.IsNaN(original) && !double.IsInfinity(original)) {62 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 63 63 double error = estimated - original; 64 64 errorsSquaredSum += error * error; 65 65 } 66 66 // check the limit and stop as soon as we hit the limit 67 if (errorsSquaredSum / rows >= qualityLimit) {67 if (errorsSquaredSum / rows >= qualityLimit) { 68 68 mse.Data = errorsSquaredSum / (sample - start + 1); // return estimated MSE (when the remaining errors are on average the same) 69 69 return; … … 71 71 } 72 72 errorsSquaredSum /= rows; 73 if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {73 if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { 74 74 errorsSquaredSum = double.MaxValue; 75 75 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/GPEvaluatorBase.cs
r702 r712 57 57 double[] backupValues = null; 58 58 // prepare for autoregressive modelling by saving the original values of the target-variable to a backup array 59 if (useEstimatedValues &&60 (backupValues == null || backupValues.Length !=end-start)) {59 if (useEstimatedValues && 60 (backupValues == null || backupValues.Length != end - start)) { 61 61 backupValues = new double[end - start]; 62 for (int i = start; i < end; i++) {62 for (int i = start; i < end; i++) { 63 63 backupValues[i - start] = dataset.GetValue(i, targetVariable); 64 64 } … … 72 72 73 73 // restore the values of the target variable from the backup array if necessary 74 if (useEstimatedValues) {75 for (int i = start; i < end; i++) {74 if (useEstimatedValues) { 75 for (int i = start; i < end; i++) { 76 76 dataset.SetValue(i, targetVariable, backupValues[i - start]); 77 77 } … … 79 79 80 80 // update the value of total evaluated nodes 81 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (end -start);81 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (end - start); 82 82 return null; 83 83 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/MeanAbsolutePercentageErrorEvaluator.cs
r702 r712 46 46 double errorsSum = 0.0; 47 47 int n = 0; 48 for (int sample = start; sample < end; sample++) {48 for (int sample = start; sample < end; sample++) { 49 49 double estimated = evaluator.Evaluate(sample); 50 double original = dataset.GetValue( targetVariable, sample);50 double original = dataset.GetValue(sample, targetVariable); 51 51 52 if (updateTargetValues) {53 dataset.SetValue( targetVariable, sample, estimated);52 if (updateTargetValues) { 53 dataset.SetValue(sample, targetVariable, estimated); 54 54 } 55 56 if (!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) {55 56 if (!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) { 57 57 double percent_error = Math.Abs((estimated - original) / original); 58 58 errorsSum += percent_error; … … 61 61 } 62 62 double quality = errorsSum / n; 63 if (double.IsNaN(quality) || double.IsInfinity(quality))63 if (double.IsNaN(quality) || double.IsInfinity(quality)) 64 64 quality = double.MaxValue; 65 65 66 66 // create a variable for the MAPE 67 67 DoubleData mape = GetVariableValue<DoubleData>("MAPE", scope, false, false); 68 if (mape == null) {68 if (mape == null) { 69 69 mape = new DoubleData(); 70 70 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MAPE"), mape)); -
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/MeanSquaredErrorEvaluator.cs
r702 r712 45 45 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 46 46 double errorsSquaredSum = 0; 47 for (int sample = start; sample < end; sample++) {48 double original = dataset.GetValue( targetVariable, sample);47 for (int sample = start; sample < end; sample++) { 48 double original = dataset.GetValue(sample, targetVariable); 49 49 double estimated = evaluator.Evaluate(sample); 50 if (updateTargetValues) {51 dataset.SetValue( targetVariable, sample, estimated);50 if (updateTargetValues) { 51 dataset.SetValue(sample, targetVariable, estimated); 52 52 } 53 if (!double.IsNaN(original) && !double.IsInfinity(original)) {53 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 54 54 double error = estimated - original; 55 55 errorsSquaredSum += error * error; … … 58 58 59 59 errorsSquaredSum /= (end - start); 60 if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {60 if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { 61 61 errorsSquaredSum = double.MaxValue; 62 62 } 63 63 64 64 DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false); 65 if (mse == null) {65 if (mse == null) { 66 66 mse = new DoubleData(); 67 67 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse)); -
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/SimpleEvaluator.cs
r702 r712 38 38 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 39 39 ItemList values = GetVariableValue<ItemList>("Values", scope, false, false); 40 if (values == null) {40 if (values == null) { 41 41 values = new ItemList(); 42 42 IVariableInfo info = GetVariableInfo("Values"); 43 if (info.Local)43 if (info.Local) 44 44 AddVariable(new HeuristicLab.Core.Variable(info.ActualName, values)); 45 45 else … … 48 48 values.Clear(); 49 49 50 for (int sample = start; sample < end; sample++) {50 for (int sample = start; sample < end; sample++) { 51 51 ItemList row = new ItemList(); 52 52 double estimated = evaluator.Evaluate(sample); 53 double original = dataset.GetValue( targetVariable, sample);54 if (updateTargetValues) {55 dataset.SetValue( targetVariable, sample, estimated);53 double original = dataset.GetValue(sample, targetVariable); 54 if (updateTargetValues) { 55 dataset.SetValue(sample, targetVariable, estimated); 56 56 } 57 57 row.Add(new DoubleData(estimated)); -
trunk/sources/HeuristicLab.GP.StructureIdentification/Evaluators/VarianceAccountedForEvaluator.cs
r702 r712 57 57 double[] errors = new double[nSamples]; 58 58 double[] originalTargetVariableValues = new double[nSamples]; 59 for (int sample = start; sample < end; sample++) {59 for (int sample = start; sample < end; sample++) { 60 60 double estimated = evaluator.Evaluate(sample); 61 double original = dataset.GetValue( targetVariable, sample);62 if (updateTargetValues) {63 dataset.SetValue( targetVariable, sample, estimated);61 double original = dataset.GetValue(sample, targetVariable); 62 if (updateTargetValues) { 63 dataset.SetValue(sample, targetVariable, estimated); 64 64 } 65 if (!double.IsNaN(original) && !double.IsInfinity(original)) {65 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 66 66 errors[sample - start] = original - estimated; 67 67 originalTargetVariableValues[sample - start] = original; … … 72 72 double quality = 1 - errorsVariance / originalsVariance; 73 73 74 if (double.IsNaN(quality) || double.IsInfinity(quality)) {74 if (double.IsNaN(quality) || double.IsInfinity(quality)) { 75 75 quality = double.MaxValue; 76 76 } 77 77 DoubleData vaf = GetVariableValue<DoubleData>("VAF", scope, false, false); 78 if (vaf == null) {78 if (vaf == null) { 79 79 vaf = new DoubleData(); 80 80 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("VAF"), vaf));
Note: See TracChangeset
for help on using the changeset viewer.