Changeset 712
- Timestamp:
- 11/05/08 21:34:12 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/AccuracyEvaluator.cs
r702 r712 45 45 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) { 46 46 DoubleData accuracy = GetVariableValue<DoubleData>("Accuracy", scope, false, false); 47 if (accuracy == null) {47 if (accuracy == null) { 48 48 accuracy = new DoubleData(); 49 49 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Accuracy"), accuracy)); … … 52 52 int nSamples = end - start; 53 53 int nCorrect = 0; 54 for (int sample = start; sample < end; sample++) {54 for (int sample = start; sample < end; sample++) { 55 55 double est = evaluator.Evaluate(sample); 56 double origClass = dataset.GetValue( targetVariable, sample);56 double origClass = dataset.GetValue(sample, targetVariable); 57 57 double estClass = double.NaN; 58 58 // if estimation is lower than the smallest threshold value -> estimated class is the lower class 59 if (est < thresholds[0]) estClass = classes[0];59 if (est < thresholds[0]) estClass = classes[0]; 60 60 // if estimation is larger (or equal) than the largest threshold value -> estimated class is the upper class 61 else if (est >= thresholds[thresholds.Length - 1]) estClass = classes[classes.Length - 1];61 else if (est >= thresholds[thresholds.Length - 1]) estClass = classes[classes.Length - 1]; 62 62 else { 63 63 // otherwise the estimated class is the class which upper threshold is larger than the estimated value 64 for (int k = 0; k < thresholds.Length; k++) {65 if (thresholds[k] > est) {64 for (int k = 0; k < thresholds.Length; k++) { 65 if (thresholds[k] > est) { 66 66 estClass = classes[k]; 67 67 break; … … 69 69 } 70 70 } 71 if (Math.Abs(estClass - origClass) < EPSILON) nCorrect++;71 if (Math.Abs(estClass - origClass) < EPSILON) nCorrect++; 72 72 } 73 73 accuracy.Data = nCorrect / (double)nSamples; -
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/ClassificationMeanSquaredErrorEvaluator.cs
r702 r712 43 43 } 44 44 45 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) 46 { 45 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) { 47 46 double errorsSquaredSum = 0; 48 for (int sample = start; sample < end; sample++) {47 for (int sample = start; sample < end; sample++) { 49 48 double estimated = evaluator.Evaluate(sample); 50 double original = dataset.GetValue( targetVariable, sample);51 if (!double.IsNaN(original) && !double.IsInfinity(original)) {49 double original = dataset.GetValue(sample, targetVariable); 50 if (!double.IsNaN(original) && !double.IsInfinity(original)) { 52 51 double error = estimated - original; 53 52 // between classes use squared error 54 53 // on the lower end and upper end only add linear error if the absolute error is larger than 1 55 54 // the error>1.0 constraint is needed for balance because in the interval ]-1, 1[ the squared error is smaller than the absolute error 56 if ((IsEqual(original, classes[0]) && error < -1.0) ||55 if ((IsEqual(original, classes[0]) && error < -1.0) || 57 56 (IsEqual(original, classes[classes.Length - 1]) && error > 1.0)) { 58 57 errorsSquaredSum += Math.Abs(error); // only add linear error below the smallest class or above the largest class … … 64 63 65 64 errorsSquaredSum /= (end - start); 66 if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {65 if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { 67 66 errorsSquaredSum = double.MaxValue; 68 67 } 69 68 70 69 DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false); 71 if (mse == null) {70 if (mse == null) { 72 71 mse = new DoubleData(); 73 72 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse)); -
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/ConfusionMatrixEvaluator.cs
r702 r712 43 43 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) { 44 44 IntMatrixData matrix = GetVariableValue<IntMatrixData>("ConfusionMatrix", scope, false, false); 45 if (matrix == null) {45 if (matrix == null) { 46 46 matrix = new IntMatrixData(new int[classes.Length, classes.Length]); 47 47 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("ConfusionMatrix"), matrix)); … … 49 49 50 50 int nSamples = end - start; 51 for (int sample = start; sample < end; sample++) {51 for (int sample = start; sample < end; sample++) { 52 52 double est = evaluator.Evaluate(sample); 53 double origClass = dataset.GetValue( targetVariable,sample);53 double origClass = dataset.GetValue(sample, targetVariable); 54 54 int estClassIndex = -1; 55 55 // if estimation is lower than the smallest threshold value -> estimated class is the lower class 56 if (est < thresholds[0]) estClassIndex = 0;56 if (est < thresholds[0]) estClassIndex = 0; 57 57 // if estimation is larger (or equal) than the largest threshold value -> estimated class is the upper class 58 else if (est >= thresholds[thresholds.Length - 1]) estClassIndex = classes.Length - 1;58 else if (est >= thresholds[thresholds.Length - 1]) estClassIndex = classes.Length - 1; 59 59 else { 60 60 // otherwise the estimated class is the class which upper threshold is larger than the estimated value 61 for (int k = 0; k < thresholds.Length; k++) {62 if (thresholds[k] > est) {61 for (int k = 0; k < thresholds.Length; k++) { 62 if (thresholds[k] > est) { 63 63 estClassIndex = k; 64 64 break; … … 68 68 69 69 // find the first threshold index that is larger to the original value 70 int origClassIndex = classes.Length -1;71 for (int i = 0; i < thresholds.Length; i++) {72 if (origClass < thresholds[i]) {70 int origClassIndex = classes.Length - 1; 71 for (int i = 0; i < thresholds.Length; i++) { 72 if (origClass < thresholds[i]) { 73 73 origClassIndex = i; 74 74 break; -
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/MulticlassModeller.cs
r668 r712 69 69 binaryClassValues.Add(new DoubleData(0.0)); 70 70 binaryClassValues.Add(new DoubleData(1.0)); 71 for (int i = 0; i < classValues.Count-1; i++) {72 for (int j = i+1; j < classValues.Count; j++) {71 for (int i = 0; i < classValues.Count - 1; i++) { 72 for (int j = i + 1; j < classValues.Count; j++) { 73 73 Dataset dataset = new Dataset(); 74 74 dataset.Columns = origDataset.Columns; … … 82 82 trainingSamplesStart = 0; 83 83 List<double[]> rows = new List<double[]>(); 84 for (int k = origTrainingSamplesStart; k < origTrainingSamplesEnd; k++) {84 for (int k = origTrainingSamplesStart; k < origTrainingSamplesEnd; k++) { 85 85 double[] row = new double[dataset.Columns]; 86 86 double targetValue = origDataset.GetValue(k, targetVariable); 87 if (IsEqual(targetValue, classAValue)) {88 for (int l = 0; l < row.Length; l++) {87 if (IsEqual(targetValue, classAValue)) { 88 for (int l = 0; l < row.Length; l++) { 89 89 row[l] = origDataset.GetValue(k, l); 90 90 } 91 91 row[targetVariable] = 0; 92 92 rows.Add(row); 93 } else if (IsEqual(targetValue, classBValue)) {94 for (int l = 0; l < row.Length; l++) {93 } else if (IsEqual(targetValue, classBValue)) { 94 for (int l = 0; l < row.Length; l++) { 95 95 row[l] = origDataset.GetValue(k, l); 96 96 } … … 101 101 trainingSamplesEnd = rows.Count; 102 102 validationSamplesStart = rows.Count; 103 for (int k = origValidationSamplesStart; k < origValidationSamplesEnd; k++) {103 for (int k = origValidationSamplesStart; k < origValidationSamplesEnd; k++) { 104 104 double[] row = new double[dataset.Columns]; 105 105 double targetValue = origDataset.GetValue(k, targetVariable); 106 if (IsEqual(targetValue, classAValue)) {107 for (int l = 0; l < row.Length; l++) {106 if (IsEqual(targetValue, classAValue)) { 107 for (int l = 0; l < row.Length; l++) { 108 108 row[l] = origDataset.GetValue(k, l); 109 109 } 110 110 row[targetVariable] = 0; 111 111 rows.Add(row); 112 } else if (IsEqual(targetValue, classBValue)) {113 for (int l = 0; l < row.Length; l++) {112 } else if (IsEqual(targetValue, classBValue)) { 113 for (int l = 0; l < row.Length; l++) { 114 114 row[l] = origDataset.GetValue(k, l); 115 115 } … … 122 122 dataset.Rows = rows.Count; 123 123 dataset.Samples = new double[dataset.Rows * dataset.Columns]; 124 for (int k = 0; k < dataset.Rows; k++) {125 for (int l = 0; l < dataset.Columns; l++) {124 for (int k = 0; k < dataset.Rows; k++) { 125 for (int l = 0; l < dataset.Columns; l++) { 126 126 dataset.SetValue(k, l, rows[k][l]); 127 127 } 128 128 } 129 129 130 Scope childScope = new Scope(classAValue +" vs. "+classBValue);130 Scope childScope = new Scope(classAValue + " vs. " + classBValue); 131 131 132 132 childScope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(TARGETCLASSVALUES), binaryClassValues)); -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/AveragePercentageChangeEvaluator.cs
r702 r712 45 45 bool differential = GetVariableValue<BoolData>("Differential", scope, true).Data; 46 46 DoubleData apc = GetVariableValue<DoubleData>("APC", scope, false, false); 47 if (apc == null) {47 if (apc == null) { 48 48 apc = new DoubleData(); 49 49 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("APC"), apc)); … … 51 51 52 52 double percentageSum = 0; 53 for (int sample = start; sample < end; sample++) {53 for (int sample = start; sample < end; sample++) { 54 54 double prevOriginal; 55 55 double originalPercentageChange; 56 56 double estimatedPercentageChange; 57 if (differential) {58 prevOriginal = dataset.GetValue( targetVariable,sample - 1);59 originalPercentageChange = (dataset.GetValue( targetVariable,sample) - prevOriginal) / prevOriginal;57 if (differential) { 58 prevOriginal = dataset.GetValue(sample - 1, targetVariable); 59 originalPercentageChange = (dataset.GetValue(sample, targetVariable) - prevOriginal) / prevOriginal; 60 60 estimatedPercentageChange = (evaluator.Evaluate(sample) - prevOriginal) / prevOriginal; 61 if (updateTargetValues) {62 dataset.SetValue( targetVariable, sample, estimatedPercentageChange * prevOriginal + prevOriginal);61 if (updateTargetValues) { 62 dataset.SetValue(sample, targetVariable, estimatedPercentageChange * prevOriginal + prevOriginal); 63 63 } 64 64 } else { 65 originalPercentageChange = dataset.GetValue( targetVariable,sample);65 originalPercentageChange = dataset.GetValue(sample, targetVariable); 66 66 estimatedPercentageChange = evaluator.Evaluate(sample); 67 if (updateTargetValues) {68 dataset.SetValue( targetVariable, sample, estimatedPercentageChange);67 if (updateTargetValues) { 68 dataset.SetValue(sample, targetVariable, estimatedPercentageChange); 69 69 } 70 70 } 71 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) {72 if ((estimatedPercentageChange > 0 && originalPercentageChange > 0) ||71 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) { 72 if ((estimatedPercentageChange > 0 && originalPercentageChange > 0) || 73 73 (estimatedPercentageChange < 0 && originalPercentageChange < 0)) { 74 74 percentageSum += Math.Abs(originalPercentageChange); 75 } else if ((estimatedPercentageChange > 0 && originalPercentageChange < 0) ||75 } else if ((estimatedPercentageChange > 0 && originalPercentageChange < 0) || 76 76 (estimatedPercentageChange < 0 && originalPercentageChange > 0)) { 77 77 percentageSum -= Math.Abs(originalPercentageChange); … … 81 81 82 82 percentageSum /= (end - start); 83 if (double.IsNaN(percentageSum) || double.IsInfinity(percentageSum)) {83 if (double.IsNaN(percentageSum) || double.IsInfinity(percentageSum)) { 84 84 percentageSum = double.MinValue; 85 85 } -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/ProfitEvaluator.cs
r702 r712 47 47 double transactionCost = GetVariableValue<DoubleData>("TransactionCost", scope, true).Data; 48 48 DoubleData profit = GetVariableValue<DoubleData>("Profit", scope, false, false); 49 if (profit == null) {49 if (profit == null) { 50 50 profit = new DoubleData(); 51 51 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Profit"), profit)); … … 55 55 double cB = 0; 56 56 double exchangeRate = double.MaxValue; 57 for (int sample = start; sample < end; sample++) {57 for (int sample = start; sample < end; sample++) { 58 58 exchangeRate = dataset.GetValue(sample, exchangeRateVarIndex); 59 double originalPercentageChange = dataset.GetValue( targetVariable, sample);59 double originalPercentageChange = dataset.GetValue(sample, targetVariable); 60 60 double estimatedPercentageChange = evaluator.Evaluate(sample); 61 if (updateTargetValues) {62 dataset.SetValue( targetVariable, sample, estimatedPercentageChange);61 if (updateTargetValues) { 62 dataset.SetValue(sample, targetVariable, estimatedPercentageChange); 63 63 } 64 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) {65 if (estimatedPercentageChange > 0) {64 if (!double.IsNaN(originalPercentageChange) && !double.IsInfinity(originalPercentageChange)) { 65 if (estimatedPercentageChange > 0) { 66 66 // prediction is the rate of B/A will increase (= get more B for one A) => exchange all B to A 67 67 cA += (cB / exchangeRate) * (1 - transactionCost); 68 68 cB = 0; 69 } else if (estimatedPercentageChange < 0) {69 } else if (estimatedPercentageChange < 0) { 70 70 // prediction is the rate of B/A will drop (= get more A for one B) => exchange all A to B 71 71 cB += (cA * exchangeRate) * (1 - transactionCost); … … 75 75 } 76 76 77 if (double.IsNaN(cA) || double.IsInfinity(cA) || double.IsInfinity(cB) || double.IsNaN(cB)) {77 if (double.IsNaN(cA) || double.IsInfinity(cA) || double.IsInfinity(cB) || double.IsNaN(cB)) { 78 78 cA = 0; 79 79 cB = 0; -
trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/TheilInequalityCoefficientEvaluator.cs
r702 r712 55 55 56 56 public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { 57 #region create result variables57 #region create result variables 58 58 DoubleData theilInequaliy = GetVariableValue<DoubleData>("TheilInequalityCoefficient", scope, false, false); 59 if (theilInequaliy == null) {59 if (theilInequaliy == null) { 60 60 theilInequaliy = new DoubleData(); 61 61 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficient"), theilInequaliy)); 62 62 } 63 63 DoubleData uBias = GetVariableValue<DoubleData>("TheilInequalityCoefficientBias", scope, false, false); 64 if (uBias == null) {64 if (uBias == null) { 65 65 uBias = new DoubleData(); 66 66 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientBias"), uBias)); 67 67 } 68 68 DoubleData uVariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientVariance", scope, false, false); 69 if (uVariance == null) {69 if (uVariance == null) { 70 70 uVariance = new DoubleData(); 71 71 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientVariance"), uVariance)); 72 72 } 73 73 DoubleData uCovariance = GetVariableValue<DoubleData>("TheilInequalityCoefficientCovariance", scope, false, false); 74 if (uCovariance == null) {74 if (uCovariance == null) { 75 75 uCovariance = new DoubleData(); 76 76 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TheilInequalityCoefficientCovariance"), uCovariance)); … … 83 83 double[] originalChanges = new double[end - start]; 84 84 int nSamples = 0; 85 for (int sample = start; sample < end; sample++) {86 double prevValue = dataset.GetValue( targetVariable, sample - 1);85 for (int sample = start; sample < end; sample++) { 86 double prevValue = dataset.GetValue(sample - 1, targetVariable); 87 87 double estimatedChange = evaluator.Evaluate(sample) - prevValue; 88 double originalChange = dataset.GetValue( targetVariable, sample) - prevValue;89 if (updateTargetValues) {90 dataset.SetValue( targetVariable, sample, estimatedChange + prevValue);88 double originalChange = dataset.GetValue(sample, targetVariable) - prevValue; 89 if (updateTargetValues) { 90 dataset.SetValue(sample, targetVariable, estimatedChange + prevValue); 91 91 } 92 if (!double.IsNaN(originalChange) && !double.IsInfinity(originalChange)) {92 if (!double.IsNaN(originalChange) && !double.IsInfinity(originalChange)) { 93 93 double error = estimatedChange - originalChange; 94 94 errorsSquaredSum += error * error; … … 100 100 } 101 101 double quality = Math.Sqrt(errorsSquaredSum / nSamples) / Math.Sqrt(originalSquaredSum / nSamples); 102 if (double.IsNaN(quality) || double.IsInfinity(quality))102 if (double.IsNaN(quality) || double.IsInfinity(quality)) 103 103 quality = double.MaxValue; 104 104 theilInequaliy.Data = quality; // U2 -
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.