Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4122


Ignore:
Timestamp:
07/31/10 16:29:42 (14 years ago)
Author:
gkronber
Message:

Fixed #1116

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  
    3131      get {
    3232        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;
    3339      }
    3440    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlinePearsonsRSquaredEvaluator.cs

    r4068 r4122  
    2525namespace HeuristicLab.Problems.DataAnalysis.Evaluators {
    2626  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();
    3430
    3531    public double RSquared {
    3632      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;
    5135      }
    5236    }
     
    5943    }
    6044    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();
    6748    }
    6849
    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)) {
    7252        throw new ArgumentException("R² is not defined for variables with NaN or infinity values.");
    7353      }
    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);
    8957    }
    9058
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/HeuristicLab.Problems.DataAnalysis.Tests-3.3.csproj

    r4082 r4122  
    7777  </ItemGroup>
    7878  <ItemGroup>
     79    <Compile Include="StatisticCalculatorsTest.cs" />
    7980    <Compile Include="LinearScalingTest.cs" />
    8081    <Compile Include="Properties\AssemblyInfo.cs" />
     
    104105      <Project>{125D3006-67F5-48CB-913E-73C0548F17FA}</Project>
    105106      <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>
    106111    </ProjectReference>
    107112    <ProjectReference Include="..\..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
Note: See TracChangeset for help on using the changeset viewer.