- Timestamp:
- 11/05/08 21:34:12 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification.Classification
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified 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; -
TabularUnified 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)); -
TabularUnified 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; -
TabularUnified 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));
Note: See TracChangeset
for help on using the changeset viewer.