- Timestamp:
- 03/17/11 21:40:31 (14 years ago)
- 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 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using System; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 95 96 if (IsNonDominated(qualities[i], trainingBestQualities, maximization) && 96 97 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 } 99 102 } 100 103 } … … 113 116 for (int i = 0; i < trainingBestQualities.Count; i++) { 114 117 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 } 117 122 } 118 123 } … … 125 130 } 126 131 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 127 149 protected abstract T CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality); 128 150 … … 131 153 bool refPointDominatesPoint = true; 132 154 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]); 134 156 } 135 157 if (refPointDominatesPoint) return false; … … 137 159 return true; 138 160 } 139 private bool IsBetter (double lhs, double rhs, bool maximization) {161 private bool IsBetterOrEqual(double lhs, double rhs, bool maximization) { 140 162 if (maximization) return lhs > rhs; 141 163 else return lhs < rhs; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs
r5722 r5742 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using System; 32 33 33 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 120 121 if (IsNonDominated(qualities[i], trainingBestQualities, maximization) && 121 122 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 } 124 127 } 125 128 } … … 138 141 for (int i = 0; i < trainingBestQualities.Count; i++) { 139 142 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 } 142 147 } 143 148 } … … 166 171 else return lhs < rhs; 167 172 } 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 168 191 } 169 192 }
Note: See TracChangeset
for help on using the changeset viewer.