diff options
author | 2012-09-20 19:05:33 +0000 | |
---|---|---|
committer | 2012-09-20 19:05:33 +0000 | |
commit | c5e1ed875208975c0334b6b5fd3a2e870f65ffef (patch) | |
tree | 50363b317cd868af71c54ced7a34751aa58ebac8 /bench/bench_util.py | |
parent | 2d2b9a0d8c78c62565e8eedeca3c337827d795c1 (diff) |
Prevent LinearRegression from dividing by zero so the GenerateBenchGraphs step doesn't blow up if the data is all zeroes.
http://codereview.appspot.com/6546049/
git-svn-id: http://skia.googlecode.com/svn/trunk@5615 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/bench_util.py')
-rw-r--r-- | bench/bench_util.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/bench/bench_util.py b/bench/bench_util.py index 3abdee8b60..82a16f0522 100644 --- a/bench/bench_util.py +++ b/bench/bench_util.py @@ -151,15 +151,19 @@ class LinearRegression: Sxy += x*y Syy += y*y - B = (n*Sxy - Sx*Sy) / (n*Sxx - Sx*Sx) + denom = n*Sxx - Sx*Sx + if (denom != 0.0): + B = (n*Sxy - Sx*Sy) / denom + else: + B = 0.0 a = (1.0/n)*(Sy - B*Sx) se2 = 0 sB2 = 0 sa2 = 0 - if (n >= 3): - se2 = (1.0/(n*(n-2)) * (n*Syy - Sy*Sy - B*B*(n*Sxx - Sx*Sx))) - sB2 = (n*se2) / (n*Sxx - Sx*Sx) + if (n >= 3 and denom != 0.0): + se2 = (1.0/(n*(n-2)) * (n*Syy - Sy*Sy - B*B*denom)) + sB2 = (n*se2) / denom sa2 = sB2 * (1.0/n) * Sxx @@ -208,3 +212,10 @@ def CreateRevisionLink(revision_number): """ return '<a href="http://code.google.com/p/skia/source/detail?r=%s">%s</a>'%( revision_number, revision_number) + +def main(): + foo = [[0.0, 0.0], [0.0, 1.0], [0.0, 2.0], [0.0, 3.0]] + LinearRegression(foo) + +if __name__ == "__main__": + main() |