Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/05/08 21:34:12 (16 years ago)
Author:
gkronber
Message:

fixed a stupid mistake introduced with r702 #328 (GP evaluation doesn't work in a thread parallel engine).

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  
    4545    public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4646      DoubleData accuracy = GetVariableValue<DoubleData>("Accuracy", scope, false, false);
    47       if(accuracy == null) {
     47      if (accuracy == null) {
    4848        accuracy = new DoubleData();
    4949        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Accuracy"), accuracy));
     
    5252      int nSamples = end - start;
    5353      int nCorrect = 0;
    54       for(int sample = start; sample < end; sample++) {
     54      for (int sample = start; sample < end; sample++) {
    5555        double est = evaluator.Evaluate(sample);
    56         double origClass = dataset.GetValue(targetVariable, sample);
     56        double origClass = dataset.GetValue(sample, targetVariable);
    5757        double estClass = double.NaN;
    5858        // 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];
    6060        // 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];
    6262        else {
    6363          // 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) {
    6666              estClass = classes[k];
    6767              break;
     
    6969          }
    7070        }
    71         if(Math.Abs(estClass - origClass) < EPSILON) nCorrect++;
     71        if (Math.Abs(estClass - origClass) < EPSILON) nCorrect++;
    7272      }
    7373      accuracy.Data = nCorrect / (double)nSamples;
  • TabularUnified trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/ClassificationMeanSquaredErrorEvaluator.cs

    r702 r712  
    4343    }
    4444
    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) {
    4746      double errorsSquaredSum = 0;
    48       for(int sample = start; sample < end; sample++) {
     47      for (int sample = start; sample < end; sample++) {
    4948        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)) {
    5251          double error = estimated - original;
    5352          // between classes use squared error
    5453          // on the lower end and upper end only add linear error if the absolute error is larger than 1
    5554          // 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) ||
    5756            (IsEqual(original, classes[classes.Length - 1]) && error > 1.0)) {
    5857            errorsSquaredSum += Math.Abs(error); // only add linear error below the smallest class or above the largest class
     
    6463
    6564      errorsSquaredSum /= (end - start);
    66       if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
     65      if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
    6766        errorsSquaredSum = double.MaxValue;
    6867      }
    6968
    7069      DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
    71       if(mse == null) {
     70      if (mse == null) {
    7271        mse = new DoubleData();
    7372        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse));
  • TabularUnified trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/ConfusionMatrixEvaluator.cs

    r702 r712  
    4343    public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4444      IntMatrixData matrix = GetVariableValue<IntMatrixData>("ConfusionMatrix", scope, false, false);
    45       if(matrix == null) {
     45      if (matrix == null) {
    4646        matrix = new IntMatrixData(new int[classes.Length, classes.Length]);
    4747        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("ConfusionMatrix"), matrix));
     
    4949
    5050      int nSamples = end - start;
    51       for(int sample = start; sample < end; sample++) {
     51      for (int sample = start; sample < end; sample++) {
    5252        double est = evaluator.Evaluate(sample);
    53         double origClass = dataset.GetValue(targetVariable,sample);
     53        double origClass = dataset.GetValue(sample, targetVariable);
    5454        int estClassIndex = -1;
    5555        // 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;
    5757        // 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;
    5959        else {
    6060          // 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) {
    6363              estClassIndex = k;
    6464              break;
     
    6868
    6969        // 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]) {
    7373            origClassIndex = i;
    7474            break;
  • TabularUnified trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/MulticlassModeller.cs

    r668 r712  
    6969      binaryClassValues.Add(new DoubleData(0.0));
    7070      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++) {
    7373          Dataset dataset = new Dataset();
    7474          dataset.Columns = origDataset.Columns;
     
    8282          trainingSamplesStart = 0;
    8383          List<double[]> rows = new List<double[]>();
    84           for(int k = origTrainingSamplesStart; k < origTrainingSamplesEnd; k++) {
     84          for (int k = origTrainingSamplesStart; k < origTrainingSamplesEnd; k++) {
    8585            double[] row = new double[dataset.Columns];
    8686            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++) {
    8989                row[l] = origDataset.GetValue(k, l);
    9090              }
    9191              row[targetVariable] = 0;
    9292              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++) {
    9595                row[l] = origDataset.GetValue(k, l);
    9696              }
     
    101101          trainingSamplesEnd = rows.Count;
    102102          validationSamplesStart = rows.Count;
    103           for(int k = origValidationSamplesStart; k < origValidationSamplesEnd; k++) {
     103          for (int k = origValidationSamplesStart; k < origValidationSamplesEnd; k++) {
    104104            double[] row = new double[dataset.Columns];
    105105            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++) {
    108108                row[l] = origDataset.GetValue(k, l);
    109109              }
    110110              row[targetVariable] = 0;
    111111              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++) {
    114114                row[l] = origDataset.GetValue(k, l);
    115115              }
     
    122122          dataset.Rows = rows.Count;
    123123          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++) {
    126126              dataset.SetValue(k, l, rows[k][l]);
    127127            }
    128128          }
    129129
    130           Scope childScope = new Scope(classAValue+" vs. "+classBValue);
     130          Scope childScope = new Scope(classAValue + " vs. " + classBValue);
    131131
    132132          childScope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(TARGETCLASSVALUES), binaryClassValues));
Note: See TracChangeset for help on using the changeset viewer.