Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/07/15 09:21:46 (9 years ago)
Author:
gkronber
Message:

#2283: refactoring and bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/SymbolicRegressionPoly10Problem.cs

    r11730 r11732  
    5656    }
    5757
    58     public double GetBestKnownQuality(int maxLen) {
     58    public double BestKnownQuality(int maxLen) {
    5959      // for now only an upper bound is returned, ideally we have an R² of 1.0
    6060      // the optimal R² can only be reached for sentences of at least 23 symbols
     
    6767
    6868    public double Evaluate(string sentence) {
    69       return RSq(y, Enumerable.Range(0, N).Select(i => interpreter.Interpret(sentence, x[i])).ToArray());
     69      return HeuristicLab.Common.Extensions.RSq(y, Enumerable.Range(0, N).Select(i => interpreter.Interpret(sentence, x[i])).ToArray());
    7070    }
    7171
    72     private double RSq(IEnumerable<double> xs, IEnumerable<double> ys) {
    73       // two pass implementation, but we don't care
    74       var meanX = xs.Average();
    75       var meanY = ys.Average();
    76 
    77       var s = 0.0;
    78       var ssX = 0.0;
    79       var ssY = 0.0;
    80       foreach (var p in xs.Zip(ys, (x, y) => new { x, y })) {
    81         s += (p.x - meanX) * (p.y - meanY);
    82         ssX += Math.Pow(p.x - meanX, 2);
    83         ssY += Math.Pow(p.y - meanY, 2);
    84       }
    85 
    86       if (s.IsAlmost(0)) return 0;
    87       if (ssX.IsAlmost(0) || ssY.IsAlmost(0)) return 0;
    88       return s * s / (ssX * ssY);
    89     }
    9072
    9173
Note: See TracChangeset for help on using the changeset viewer.