Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculated_confidence score
- return 0 if score == 0
- n = score.to_f
- upvotes = score
- z = 1.281551565545 # 80% confidence
- p = upvotes.to_f / n
- left = p + (1 / (2.0 * n) * z * z)
- right = z * Math.sqrt((p * ((1.0 - p) / n)) + (z * (z / (4.0 * n * n))))
- under = 1.0 + ((1.0 / n) * z * z)
- (left - right) / under
- end
- lastb = -1
- (0..1000).each do |n|
- c = calculated_confidence(n)
- b = (c*c*256).floor
- if b != lastb then
- printf "%3d %.4f %d\n", n, c, b
- lastb = b
- end
- end
- __END__
- 0 0.0000 0
- 1 0.3784 36
- 2 0.5491 77
- 3 0.6462 106
- 4 0.7089 128
- 5 0.7527 145
- 6 0.7851 157
- 7 0.8100 167
- 8 0.8297 176
- 9 0.8457 183
- 10 0.8589 188
- 11 0.8701 193
- 12 0.8796 198
- 13 0.8878 201
- 14 0.8950 205
- 15 0.9013 207
- 16 0.9069 210
- 17 0.9119 212
- 18 0.9164 214
- 19 0.9204 216
- 20 0.9241 218
- 21 0.9275 220
- 22 0.9305 221
- 23 0.9334 223
- 24 0.9360 224
- 25 0.9384 225
- 26 0.9406 226
- 27 0.9427 227
- 28 0.9446 228
- 29 0.9464 229
- 30 0.9481 230
- 32 0.9512 231
- 33 0.9526 232
- 35 0.9552 233
- 36 0.9564 234
- 38 0.9586 235
- 40 0.9606 236
- 42 0.9624 237
- 45 0.9648 238
- 47 0.9662 239
- 51 0.9688 240
- 54 0.9705 241
- 58 0.9725 242
- 63 0.9746 243
- 68 0.9764 244
- 74 0.9783 245
- 82 0.9804 246
- 91 0.9823 247
- 103 0.9843 248
- 118 0.9863 249
- 138 0.9882 250
- 166 0.9902 251
- 208 0.9922 252
- 278 0.9941 253
- 418 0.9961 254
- 839 0.9980 255
Advertisement
Add Comment
Please, Sign In to add comment