Changeset 4122 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3
- Timestamp:
- 07/31/10 16:29:42 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlineMeanAndVarianceCalculator.cs
r4068 r4122 31 31 get { 32 32 return (n > 1) ? m_newS / (n - 1) : 0.0; 33 } 34 } 35 36 public double PopulationVariance { 37 get { 38 return (n > 0) ? m_newS / n : 0.0; 33 39 } 34 40 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlinePearsonsRSquaredEvaluator.cs
r4068 r4122 25 25 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { 26 26 public class OnlinePearsonsRSquaredEvaluator : IOnlineEvaluator { 27 28 private double sum_sq_x; 29 private double sum_sq_y; 30 private double sum_coproduct; 31 private double mean_x; 32 private double mean_y; 33 private int n; 27 private OnlineCovarianceEvaluator covEvaluator = new OnlineCovarianceEvaluator(); 28 private OnlineMeanAndVarianceCalculator sxEvaluator = new OnlineMeanAndVarianceCalculator(); 29 private OnlineMeanAndVarianceCalculator syEvaluator = new OnlineMeanAndVarianceCalculator(); 34 30 35 31 public double RSquared { 36 32 get { 37 if (n < 1) 38 throw new InvalidOperationException("No elements"); 39 else { 40 double pop_sd_x = Math.Sqrt(sum_sq_x / n); 41 double pop_sd_y = Math.Sqrt(sum_sq_y / n); 42 double cov_x_y = sum_coproduct / n; 43 44 if (pop_sd_x.IsAlmost(0.0) || pop_sd_y.IsAlmost(0.0)) 45 return 0.0; 46 else { 47 double r = cov_x_y / (pop_sd_x * pop_sd_y); 48 return r * r; 49 } 50 } 33 double r = covEvaluator.Covariance / (Math.Sqrt(sxEvaluator.PopulationVariance) * Math.Sqrt(syEvaluator.PopulationVariance)); 34 return r * r; 51 35 } 52 36 } … … 59 43 } 60 44 public void Reset() { 61 sum_sq_x = 0.0; 62 sum_sq_y = 0.0; 63 sum_coproduct = 0.0; 64 mean_x = 0.0; 65 mean_y = 0.0; 66 n = 0; 45 covEvaluator.Reset(); 46 sxEvaluator.Reset(); 47 syEvaluator.Reset(); 67 48 } 68 49 69 public void Add(double original, double estimated) { 70 // stable and iterative calculation of R² 71 if (IsInvalidValue(original) || IsInvalidValue(estimated)) { 50 public void Add(double x, double y) { 51 if (IsInvalidValue(x) || IsInvalidValue(y)) { 72 52 throw new ArgumentException("R² is not defined for variables with NaN or infinity values."); 73 53 } 74 if (n == 0) { 75 mean_x = original; 76 mean_y = estimated; 77 n = 1; 78 } else { 79 double sweep = (n - 1.0) / n; 80 double delta_x = original - mean_x; 81 double delta_y = estimated - mean_y; 82 sum_sq_x += delta_x * delta_x * sweep; 83 sum_sq_y += delta_y * delta_y * sweep; 84 sum_coproduct += delta_x * delta_y * sweep; 85 mean_x += delta_x / n; 86 mean_y += delta_y / n; 87 n++; 88 } 54 covEvaluator.Add(x, y); 55 sxEvaluator.Add(x); 56 syEvaluator.Add(y); 89 57 } 90 58 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/HeuristicLab.Problems.DataAnalysis.Tests-3.3.csproj
r4082 r4122 77 77 </ItemGroup> 78 78 <ItemGroup> 79 <Compile Include="StatisticCalculatorsTest.cs" /> 79 80 <Compile Include="LinearScalingTest.cs" /> 80 81 <Compile Include="Properties\AssemblyInfo.cs" /> … … 104 105 <Project>{125D3006-67F5-48CB-913E-73C0548F17FA}</Project> 105 106 <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3</Name> 107 </ProjectReference> 108 <ProjectReference Include="..\..\..\HeuristicLab.ExtLibs\HeuristicLab.ALGLIB\2.5.0\ALGLIB-2.5.0\ALGLIB-2.5.0.csproj"> 109 <Project>{29E4B033-1FEF-4FE1-AE17-0A9319D7C54E}</Project> 110 <Name>ALGLIB-2.5.0</Name> 106 111 </ProjectReference> 107 112 <ProjectReference Include="..\..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
Note: See TracChangeset
for help on using the changeset viewer.