OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #include "src/shared/assert.h" | 5 #include "src/shared/assert.h" |
6 #include "src/shared/test_case.h" | 6 #include "src/shared/test_case.h" |
7 #include "src/shared/random.h" | 7 #include "src/shared/random.h" |
8 | 8 |
9 namespace fletch { | 9 namespace dartino { |
10 | 10 |
11 // Chi squared for getting m 0s out of n bits. | 11 // Chi squared for getting m 0s out of n bits. |
12 double ChiSquared(int m, int n) { | 12 double ChiSquared(int m, int n) { |
13 double ys_minus_np1 = (m - n / 2.0); | 13 double ys_minus_np1 = (m - n / 2.0); |
14 double chi_squared_1 = ys_minus_np1 * ys_minus_np1 * 2.0 / n; | 14 double chi_squared_1 = ys_minus_np1 * ys_minus_np1 * 2.0 / n; |
15 double ys_minus_np2 = ((n - m) - n / 2.0); | 15 double ys_minus_np2 = ((n - m) - n / 2.0); |
16 double chi_squared_2 = ys_minus_np2 * ys_minus_np2 * 2.0 / n; | 16 double chi_squared_2 = ys_minus_np2 * ys_minus_np2 * 2.0 / n; |
17 return chi_squared_1 + chi_squared_2; | 17 return chi_squared_1 + chi_squared_2; |
18 } | 18 } |
19 | 19 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 EXPECT(chi_squared <= 24); | 80 EXPECT(chi_squared <= 24); |
81 | 81 |
82 // If the predictor bit is a fixed 0 or 1 then it makes no sense to | 82 // If the predictor bit is a fixed 0 or 1 then it makes no sense to |
83 // repeat the test with a different age. | 83 // repeat the test with a different age. |
84 if (predictor_bit < 0) break; | 84 if (predictor_bit < 0) break; |
85 } | 85 } |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 } // namespace fletch | 90 } // namespace dartino |
OLD | NEW |