Changeset 5742
- Timestamp:
- 03/17/11 21:40:31 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs
r5695 r5742 21 21 22 22 using HeuristicLab.Common; 23 using System.Linq; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using System.Collections.Generic; 24 26 25 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 104 106 startSymbol = (StartSymbol)cloner.Clone(original.StartSymbol); 105 107 defunSymbol = (Defun)cloner.Clone(original.defunSymbol); 108 symbols = original.symbols 109 .ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value)); 106 110 maximumFunctionArguments = original.maximumFunctionArguments; 107 111 minimumFunctionArguments = original.minimumFunctionArguments; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs
r5733 r5742 66 66 Parameters.Add(new FixedValueParameter<DoubleValue>(UpperEstimationLimitParameterName, UpperEstimationLimitParameterDescription, new DoubleValue())); 67 67 68 Maximization = new BoolArray(new bool[] { false, false });68 Maximization = new BoolArray(new bool[] { true, false }); 69 69 MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth; 70 70 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r5722 r5742 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System.Linq; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 54 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 55 56 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 56 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 57 return OnlinePearsonsRSquaredEvaluator.Calculate(originalValues, boundedEstimatedValues); 57 return OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues); 58 58 } 59 59 -
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 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineCovarianceEvaluator.cs
r5564 r5742 30 30 public double Covariance { 31 31 get { 32 if (n < 1) 33 throw new InvalidOperationException("No elements"); 34 else 35 return Cn / n; 32 return n > 0 ? Cn / n : 0.0; 36 33 } 37 34 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAbsolutePercentageErrorEvaluator.cs
r5564 r5742 31 31 public double MeanAbsolutePercentageError { 32 32 get { 33 if (n < 1) 34 throw new InvalidOperationException("No elements"); 35 else 36 return sre / n; 33 return n > 0 ? sre / n : 0.0; 37 34 } 38 35 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredEvaluator.cs
r5564 r5742 66 66 #endregion 67 67 68 private bool IsInvalidValue(double x) {68 private static bool IsInvalidValue(double x) { 69 69 return double.IsNaN(x) || double.IsInfinity(x); 70 70 } … … 79 79 double estimated = secondEnumerator.Current; 80 80 double original = firstEnumerator.Current; 81 rSquaredEvaluator.Add(original, estimated); 81 if (!IsInvalidValue(estimated) && !IsInvalidValue(original)) 82 rSquaredEvaluator.Add(original, estimated); 82 83 } 83 84
Note: See TracChangeset
for help on using the changeset viewer.