Changeset 12669
- Timestamp:
- 07/08/15 09:52:09 (9 years ago)
- Location:
- stable
- Files:
-
- 20 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12492,12641
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis merged: 12492,12641
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 12641
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification merged: 12641
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r12009 r12669 57 57 OnlineCalculatorError errorState; 58 58 59 double r 2;59 double r; 60 60 if (applyLinearScaling) { 61 var r 2Calculator = new OnlinePearsonsRSquaredCalculator();62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r 2Calculator, problemData.Dataset.Rows);63 errorState = r 2Calculator.ErrorState;64 r 2 = r2Calculator.RSquared;61 var rCalculator = new OnlinePearsonsRCalculator(); 62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows); 63 errorState = rCalculator.ErrorState; 64 r = rCalculator.R; 65 65 } else { 66 66 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 67 r 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);67 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 68 68 } 69 69 70 if (errorState != OnlineCalculatorError.None) r 2= double.NaN;71 return new double[2] { r 2, solution.Length };70 if (errorState != OnlineCalculatorError.None) r = double.NaN; 71 return new double[2] { r*r, solution.Length }; 72 72 73 73 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs
r12009 r12669 57 57 OnlineCalculatorError errorState; 58 58 59 double r 2;59 double r; 60 60 if (applyLinearScaling) { 61 var r 2Calculator = new OnlinePearsonsRSquaredCalculator();62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r 2Calculator, problemData.Dataset.Rows);63 errorState = r 2Calculator.ErrorState;64 r 2 = r2Calculator.RSquared;61 var rCalculator = new OnlinePearsonsRCalculator(); 62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows); 63 errorState = rCalculator.ErrorState; 64 r = rCalculator.R; 65 65 } else { 66 66 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 67 r 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);67 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 68 68 } 69 69 if (errorState != OnlineCalculatorError.None) return double.NaN; 70 return r 2;70 return r*r; 71 71 } 72 72 -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged: 12641
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r12009 r12669 57 57 OnlineCalculatorError errorState; 58 58 59 double r 2;59 double r; 60 60 if (applyLinearScaling) { 61 var r 2Calculator = new OnlinePearsonsRSquaredCalculator();62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r 2Calculator, problemData.Dataset.Rows);63 errorState = r 2Calculator.ErrorState;64 r 2 = r2Calculator.RSquared;61 var rCalculator = new OnlinePearsonsRCalculator(); 62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows); 63 errorState = rCalculator.ErrorState; 64 r = rCalculator.R; 65 65 } else { 66 66 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 67 r 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);67 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 68 68 } 69 69 70 if (errorState != OnlineCalculatorError.None) r 2= double.NaN;71 return new double[2] { r 2, solution.Length };70 if (errorState != OnlineCalculatorError.None) r = double.NaN; 71 return new double[2] { r*r, solution.Length }; 72 72 } 73 73 -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r12009 r12669 59 59 OnlineCalculatorError errorState; 60 60 61 double r 2;61 double r; 62 62 if (applyLinearScaling) { 63 var r 2Calculator = new OnlinePearsonsRSquaredCalculator();64 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r 2Calculator, problemData.Dataset.Rows);65 errorState = r 2Calculator.ErrorState;66 r 2 = r2Calculator.RSquared;63 var rCalculator = new OnlinePearsonsRCalculator(); 64 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows); 65 errorState = rCalculator.ErrorState; 66 r = rCalculator.R; 67 67 } else { 68 68 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 69 r 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);69 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 70 70 } 71 71 if (errorState != OnlineCalculatorError.None) return double.NaN; 72 return r 2;72 return r*r; 73 73 } 74 74 -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r12009 r12669 60 60 var targetValues = ProblemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, trainingIndices); 61 61 OnlineCalculatorError errorState; 62 var quality = OnlinePearsonsR SquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);62 var quality = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState); 63 63 if (errorState != OnlineCalculatorError.None) return double.NaN; 64 return quality ;64 return quality*quality; 65 65 } 66 66 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs
r12009 r12669 66 66 if (double.IsNaN(originalQuality)) { 67 67 var originalValues = regressionModel.GetEstimatedValues(dataset, rows); 68 originalQuality = OnlinePearsonsR SquaredCalculator.Calculate(targetValues, originalValues, out errorState);68 originalQuality = OnlinePearsonsRCalculator.Calculate(targetValues, originalValues, out errorState); 69 69 if (errorState != OnlineCalculatorError.None) originalQuality = 0.0; 70 70 } … … 83 83 84 84 var estimatedValues = tempModel.GetEstimatedValues(dataset, rows); 85 double newQuality = OnlinePearsonsR SquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);85 double newQuality = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState); 86 86 if (errorState != OnlineCalculatorError.None) newQuality = 0.0; 87 87 88 impactValue = originalQuality - newQuality;88 impactValue = (originalQuality*originalQuality) - (newQuality*newQuality); 89 89 } 90 90 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r12009 r12669 60 60 List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList(); 61 61 OnlineCalculatorError errorState; 62 double originalR 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput, out errorState);63 if (errorState != OnlineCalculatorError.None) originalR 2= 0.0;62 double originalR = OnlinePearsonsRCalculator.Calculate(targetValues, originalOutput, out errorState); 63 if (errorState != OnlineCalculatorError.None) originalR = 0.0; 64 64 65 65 foreach (ISymbolicExpressionTreeNode node in nodes) { … … 69 69 SwitchNode(parent, node, replacementNode); 70 70 var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows); 71 double newR 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);72 if (errorState != OnlineCalculatorError.None) newR 2= 0.0;71 double newR = OnlinePearsonsRCalculator.Calculate(targetValues, newOutput, out errorState); 72 if (errorState != OnlineCalculatorError.None) newR = 0.0; 73 73 74 74 // impact = 0 if no change 75 75 // impact < 0 if new solution is better 76 76 // impact > 0 if new solution is worse 77 double impact = originalR2 - newR2;77 double impact = (originalR*originalR) - (newR*newR); 78 78 impactAndReplacementValues[node] = new Tuple<double, double>(impact, constantNode.Value); 79 79 SwitchNode(parent, replacementNode, node); -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs
r12281 r12669 65 65 66 66 OnlineCalculatorError error; 67 var r 2 = OnlinePearsonsRSquaredCalculator.Calculate(v1, v2, out error);67 var r = OnlinePearsonsRCalculator.Calculate(v1, v2, out error); 68 68 69 if (r 2> 1.0)70 r 2= 1.0;69 if (r > 1.0) 70 r = 1.0; 71 71 72 return error == OnlineCalculatorError.None ? r 2: 0;72 return error == OnlineCalculatorError.None ? r*r : 0; 73 73 } 74 74 … … 87 87 88 88 OnlineCalculatorError error; 89 var r 2 = OnlinePearsonsRSquaredCalculator.Calculate(leftValues, rightValues, out error);89 var r = OnlinePearsonsRCalculator.Calculate(leftValues, rightValues, out error); 90 90 91 if (r 2> 1.0)92 r 2 = 1.0; // sometimes due to fp errors it can happen that the r2is over 1 (like 1.0000000009)91 if (r > 1.0) 92 r = 1.0; // sometimes due to fp errors it can happen that the correlation is over 1 (like 1.0000000009) 93 93 94 return error == OnlineCalculatorError.None ? r 2: 0;94 return error == OnlineCalculatorError.None ? r*r : 0; 95 95 } 96 96 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r11920 r12669 222 222 <Compile Include="OnlineCalculators\OnlineMeanSquaredErrorCalculator.cs" /> 223 223 <Compile Include="OnlineCalculators\OnlineNormalizedMeanSquaredErrorCalculator.cs" /> 224 <Compile Include="OnlineCalculators\OnlinePearsonsRCalculator.cs" /> 224 225 <Compile Include="OnlineCalculators\OnlinePearsonsRSquaredCalculator.cs" /> 225 226 <Compile Include="Implementation\Regression\RegressionSolution.cs" /> -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r12009 r12669 105 105 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 106 106 107 double trainingR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);108 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR 2: double.NaN;109 double testR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);110 TestRSquared = errorState == OnlineCalculatorError.None ? testR 2: double.NaN;107 double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 108 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN; 109 double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 110 TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN; 111 111 112 112 double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs
r12636 r12669 229 229 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 230 230 231 double trainingR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);232 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR 2: double.NaN;233 double testR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);234 TestRSquared = errorState == OnlineCalculatorError.None ? testR 2: double.NaN;231 double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 232 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN; 233 double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 234 TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN; 235 235 236 236 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisResults.cs
r12009 r12669 394 394 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 395 395 PrognosisTrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN; 396 double trainingR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);397 PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR 2: double.NaN;396 double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 397 PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN; 398 398 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 399 399 PrognosisTrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN; … … 430 430 double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 431 431 PrognosisTestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 432 double testR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);433 PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR 2: double.NaN;432 double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 433 PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN; 434 434 double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 435 435 PrognosisTestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; -
stable/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs
r12009 r12669 33 33 34 34 public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 35 return Math.Sqrt(OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState));35 return OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState); 36 36 } 37 37 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs
r12009 r12669 32 32 33 33 public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 34 return OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState); 34 var r = OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState); 35 return r * r; 35 36 } 36 37 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs
r12009 r12669 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 [Obsolete("Use OnlinePearsonsRCalculator directly")] 27 28 public class OnlinePearsonsRSquaredCalculator : IOnlineCalculator { 28 private OnlineCovarianceCalculator covCalculator = new OnlineCovarianceCalculator(); 29 private OnlineMeanAndVarianceCalculator sxCalculator = new OnlineMeanAndVarianceCalculator(); 30 private OnlineMeanAndVarianceCalculator syCalculator = new OnlineMeanAndVarianceCalculator(); 29 private readonly OnlinePearsonsRCalculator rCalculator = new OnlinePearsonsRCalculator(); 31 30 32 31 public double RSquared { 33 32 get { 34 double xVar = sxCalculator.PopulationVariance; 35 double yVar = syCalculator.PopulationVariance; 36 if (xVar.IsAlmost(0.0) || yVar.IsAlmost(0.0)) { 37 return 0.0; 38 } else { 39 double r = covCalculator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar)); 40 return r * r; 41 } 33 if (rCalculator.ErrorState != OnlineCalculatorError.None) return 0.0; 34 else return rCalculator.R * rCalculator.R; 42 35 } 43 36 } … … 47 40 #region IOnlineCalculator Members 48 41 public OnlineCalculatorError ErrorState { 49 get { return covCalculator.ErrorState | sxCalculator.PopulationVarianceErrorState | syCalculator.PopulationVarianceErrorState; }42 get { return rCalculator.ErrorState; } 50 43 } 51 44 public double Value { … … 53 46 } 54 47 public void Reset() { 55 covCalculator.Reset(); 56 sxCalculator.Reset(); 57 syCalculator.Reset(); 48 rCalculator.Reset(); 58 49 } 59 50 60 51 public void Add(double x, double y) { 61 // no need to check validity of values explicitly here as it is checked in all three evaluators 62 covCalculator.Add(x, y); 63 sxCalculator.Add(x); 64 syCalculator.Add(y); 52 rCalculator.Add(x, y); 65 53 } 66 54 … … 68 56 69 57 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 70 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 71 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 72 OnlinePearsonsRSquaredCalculator rSquaredCalculator = new OnlinePearsonsRSquaredCalculator(); 73 74 // always move forward both enumerators (do not use short-circuit evaluation!) 75 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 76 double original = firstEnumerator.Current; 77 double estimated = secondEnumerator.Current; 78 rSquaredCalculator.Add(original, estimated); 79 if (rSquaredCalculator.ErrorState != OnlineCalculatorError.None) break; 80 } 81 82 // check if both enumerators are at the end to make sure both enumerations have the same length 83 if (rSquaredCalculator.ErrorState == OnlineCalculatorError.None && 84 (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) { 85 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 86 } else { 87 errorState = rSquaredCalculator.ErrorState; 88 return rSquaredCalculator.RSquared; 89 } 58 var r = OnlinePearsonsRCalculator.Calculate(first, second, out errorState); 59 return r * r; 90 60 } 91 61 }
Note: See TracChangeset
for help on using the changeset viewer.