Changeset 11732 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/SymbolicRegressionPoly10Problem.cs
- Timestamp:
- 01/07/15 09:21:46 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/SymbolicRegressionPoly10Problem.cs
r11730 r11732 56 56 } 57 57 58 public double GetBestKnownQuality(int maxLen) {58 public double BestKnownQuality(int maxLen) { 59 59 // for now only an upper bound is returned, ideally we have an R² of 1.0 60 60 // the optimal R² can only be reached for sentences of at least 23 symbols … … 67 67 68 68 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()); 70 70 } 71 71 72 private double RSq(IEnumerable<double> xs, IEnumerable<double> ys) {73 // two pass implementation, but we don't care74 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 }90 72 91 73
Note: See TracChangeset
for help on using the changeset viewer.