Changeset 5942 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredCalculator.cs
- Timestamp:
- 04/04/11 15:38:16 (14 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredCalculator.cs
r5941 r5942 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlinePearsonsRSquared Evaluator : IOnlineEvaluator {28 private OnlineCovariance Evaluator covEvaluator = new OnlineCovarianceEvaluator();29 private OnlineMeanAndVarianceCalculator sx Evaluator = new OnlineMeanAndVarianceCalculator();30 private OnlineMeanAndVarianceCalculator sy Evaluator = new OnlineMeanAndVarianceCalculator();27 public class OnlinePearsonsRSquaredCalculator : IOnlineCalculator { 28 private OnlineCovarianceCalculator covCalculator = new OnlineCovarianceCalculator(); 29 private OnlineMeanAndVarianceCalculator sxCalculator = new OnlineMeanAndVarianceCalculator(); 30 private OnlineMeanAndVarianceCalculator syCalculator = new OnlineMeanAndVarianceCalculator(); 31 31 32 32 public double RSquared { 33 33 get { 34 double xVar = sx Evaluator.PopulationVariance;35 double yVar = sy Evaluator.PopulationVariance;34 double xVar = sxCalculator.PopulationVariance; 35 double yVar = syCalculator.PopulationVariance; 36 36 if (xVar.IsAlmost(0.0) || yVar.IsAlmost(0.0)) { 37 37 return 0.0; 38 38 } else { 39 double r = cov Evaluator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar));39 double r = covCalculator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar)); 40 40 return r * r; 41 41 } … … 43 43 } 44 44 45 public OnlinePearsonsRSquared Evaluator() { }45 public OnlinePearsonsRSquaredCalculator() { } 46 46 47 #region IOnline Evaluator Members48 public Online EvaluatorError ErrorState {49 get { return cov Evaluator.ErrorState | sxEvaluator.PopulationVarianceErrorState | syEvaluator.PopulationVarianceErrorState; }47 #region IOnlineCalculator Members 48 public OnlineCalculatorError ErrorState { 49 get { return covCalculator.ErrorState | sxCalculator.PopulationVarianceErrorState | syCalculator.PopulationVarianceErrorState; } 50 50 } 51 51 public double Value { … … 53 53 } 54 54 public void Reset() { 55 cov Evaluator.Reset();56 sx Evaluator.Reset();57 sy Evaluator.Reset();55 covCalculator.Reset(); 56 sxCalculator.Reset(); 57 syCalculator.Reset(); 58 58 } 59 59 60 60 public void Add(double x, double y) { 61 61 // no need to check validity of values explicitly here as it is checked in all three evaluators 62 cov Evaluator.Add(x, y);63 sx Evaluator.Add(x);64 sy Evaluator.Add(y);62 covCalculator.Add(x, y); 63 sxCalculator.Add(x); 64 syCalculator.Add(y); 65 65 } 66 66 67 67 #endregion 68 68 69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out Online EvaluatorError errorState) {69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 70 70 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 71 71 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 72 OnlinePearsonsRSquared Evaluator rSquaredEvaluator = new OnlinePearsonsRSquaredEvaluator();72 OnlinePearsonsRSquaredCalculator rSquaredCalculator = new OnlinePearsonsRSquaredCalculator(); 73 73 74 74 // always move forward both enumerators (do not use short-circuit evaluation!) … … 76 76 double estimated = secondEnumerator.Current; 77 77 double original = firstEnumerator.Current; 78 rSquared Evaluator.Add(original, estimated);78 rSquaredCalculator.Add(original, estimated); 79 79 } 80 80 … … 83 83 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 84 84 } else { 85 errorState = rSquared Evaluator.ErrorState;86 return rSquared Evaluator.RSquared;85 errorState = rSquaredCalculator.ErrorState; 86 return rSquaredCalculator.RSquared; 87 87 } 88 88 }
Note: See TracChangeset
for help on using the changeset viewer.