- Timestamp:
- 01/07/15 09:21:46 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Common/Extensions.cs
r11730 r11732 29 29 } 30 30 } 31 32 public static double RSq(IEnumerable<double> xs, IEnumerable<double> ys) { 33 // two pass implementation, but we don't care 34 var meanX = xs.Average(); 35 var meanY = ys.Average(); 36 37 var s = 0.0; 38 var ssX = 0.0; 39 var ssY = 0.0; 40 foreach (var p in xs.Zip(ys, (x, y) => new { x, y })) { 41 s += (p.x - meanX) * (p.y - meanY); 42 ssX += Math.Pow(p.x - meanX, 2); 43 ssY += Math.Pow(p.y - meanY, 2); 44 } 45 46 if (s.IsAlmost(0)) return 0; 47 if (ssX.IsAlmost(0) || ssY.IsAlmost(0)) return 0; 48 return s * s / (ssX * ssY); 49 } 50 51 31 52 } 32 53 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Common/Rand.cs
r11727 r11732 32 32 * For Gamma(a,b), scale the result by b. 33 33 */ 34 p rivatestatic double GammaRand(Random random, double a) {34 public static double GammaRand(Random random, double a) { 35 35 /* Algorithm: 36 36 * G. Marsaglia and W.W. Tsang, A simple method for generating gamma
Note: See TracChangeset
for help on using the changeset viewer.