# Changeset 11732 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/SymbolicRegressionPoly10Problem.cs

Ignore:
Timestamp:
01/07/15 09:21:46 (7 years ago)
Message:

#2283: refactoring and bug fixes

File:
1 edited

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

 r11730 } public double GetBestKnownQuality(int maxLen) { public double BestKnownQuality(int maxLen) { // for now only an upper bound is returned, ideally we have an R² of 1.0 // the optimal R² can only be reached for sentences of at least 23 symbols public double Evaluate(string sentence) { return RSq(y, Enumerable.Range(0, N).Select(i => interpreter.Interpret(sentence, x[i])).ToArray()); return HeuristicLab.Common.Extensions.RSq(y, Enumerable.Range(0, N).Select(i => interpreter.Interpret(sentence, x[i])).ToArray()); } private double RSq(IEnumerable xs, IEnumerable ys) { // two pass implementation, but we don't care var meanX = xs.Average(); var meanY = ys.Average(); var s = 0.0; var ssX = 0.0; var ssY = 0.0; foreach (var p in xs.Zip(ys, (x, y) => new { x, y })) { s += (p.x - meanX) * (p.y - meanY); ssX += Math.Pow(p.x - meanX, 2); ssY += Math.Pow(p.y - meanY, 2); } if (s.IsAlmost(0)) return 0; if (ssX.IsAlmost(0) || ssY.IsAlmost(0)) return 0; return s * s / (ssX * ssY); }
Note: See TracChangeset for help on using the changeset viewer.