Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/11 21:40:31 (14 years ago)
Author:
gkronber
Message:

#1418 fixed grammar cloning bug, improved analyzers for multi objective symbolic data analysis problems.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r5607 r5742  
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using System;
    3233
    3334namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    9596        if (IsNonDominated(qualities[i], trainingBestQualities, maximization) &&
    9697          IsNonDominated(qualities[i], qualities, maximization)) {
    97           newNonDominatedQualities.Add(qualities[i]);
    98           nonDominatedIndexes.Add(i);
     98          if (!newNonDominatedQualities.Contains(qualities[i], new DoubleArrayComparer())) {
     99            newNonDominatedQualities.Add(qualities[i]);
     100            nonDominatedIndexes.Add(i);
     101          }
    99102        }
    100103      }
     
    113116        for (int i = 0; i < trainingBestQualities.Count; i++) {
    114117          if (IsNonDominated(trainingBestQualities[i], newNonDominatedQualities, maximization)) {
    115             nonDominatedSolutions.Add(TrainingBestSolutions[i]);
    116             nonDominatedQualities.Add(TrainingBestSolutionQualities[i]);
     118            if (!newNonDominatedQualities.Contains(trainingBestQualities[i], new DoubleArrayComparer())) {
     119              nonDominatedSolutions.Add(TrainingBestSolutions[i]);
     120              nonDominatedQualities.Add(TrainingBestSolutionQualities[i]);
     121            }
    117122          }
    118123        }
     
    125130    }
    126131
     132    private class DoubleArrayComparer : IEqualityComparer<double[]> {
     133      public bool Equals(double[] x, double[] y) {
     134        if (y.Length != x.Length) throw new ArgumentException();
     135        for (int i = 0; i < x.Length;i++ ) {
     136          if (!x[i].IsAlmost(y[i])) return false;
     137        }
     138        return true;
     139      }
     140
     141      public int GetHashCode(double[] obj) {
     142        int c = obj.Length;
     143        for (int i = 0; i < obj.Length; i++)
     144          c ^= obj[i].GetHashCode();
     145        return c;
     146      }
     147    }
     148
    127149    protected abstract T CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality);
    128150
     
    131153        bool refPointDominatesPoint = true;
    132154        for (int i = 0; i < point.Length; i++) {
    133           refPointDominatesPoint &= IsBetter(refPoint[i], point[i], maximization[i]);
     155          refPointDominatesPoint &= IsBetterOrEqual(refPoint[i], point[i], maximization[i]);
    134156        }
    135157        if (refPointDominatesPoint) return false;
     
    137159      return true;
    138160    }
    139     private bool IsBetter(double lhs, double rhs, bool maximization) {
     161    private bool IsBetterOrEqual(double lhs, double rhs, bool maximization) {
    140162      if (maximization) return lhs > rhs;
    141163      else return lhs < rhs;
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs

    r5722 r5742  
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using System;
    3233
    3334namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    120121        if (IsNonDominated(qualities[i], trainingBestQualities, maximization) &&
    121122          IsNonDominated(qualities[i], qualities, maximization)) {
    122           newNonDominatedQualities.Add(qualities[i]);
    123           nonDominatedIndexes.Add(i);
     123          if (!newNonDominatedQualities.Contains(qualities[i], new DoubleArrayComparer())) {
     124            newNonDominatedQualities.Add(qualities[i]);
     125            nonDominatedIndexes.Add(i);
     126          }
    124127        }
    125128      }
     
    138141        for (int i = 0; i < trainingBestQualities.Count; i++) {
    139142          if (IsNonDominated(trainingBestQualities[i], newNonDominatedQualities, maximization)) {
    140             nonDominatedSolutions.Add(ValidationBestSolutions[i]);
    141             nonDominatedQualities.Add(ValidationBestSolutionQualities[i]);
     143            if (!newNonDominatedQualities.Contains(trainingBestQualities[i], new DoubleArrayComparer())) {
     144              nonDominatedSolutions.Add(ValidationBestSolutions[i]);
     145              nonDominatedQualities.Add(ValidationBestSolutionQualities[i]);
     146            }
    142147          }
    143148        }
     
    166171      else return lhs < rhs;
    167172    }
     173
     174    private class DoubleArrayComparer : IEqualityComparer<double[]> {
     175      public bool Equals(double[] x, double[] y) {
     176        if (y.Length != x.Length) throw new ArgumentException();
     177        for (int i = 0; i < x.Length; i++) {
     178          if (!x[i].IsAlmost(y[i])) return false;
     179        }
     180        return true;
     181      }
     182
     183      public int GetHashCode(double[] obj) {
     184        int c = obj.Length;
     185        for (int i = 0; i < obj.Length; i++)
     186          c ^= obj[i].GetHashCode();
     187        return c;
     188      }
     189    }
     190
    168191  }
    169192}
Note: See TracChangeset for help on using the changeset viewer.