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*256).floor
- if b != lastb then
- printf "%3d %.4f %d\n", n, c, (c*256).floor
- lastb = b
- end
- end
- __END__
- 0 0.0000 0
- 1 0.3784 96
- 2 0.5491 140
- 3 0.6462 165
- 4 0.7089 181
- 5 0.7527 192
- 6 0.7851 200
- 7 0.8100 207
- 8 0.8297 212
- 9 0.8457 216
- 10 0.8589 219
- 11 0.8701 222
- 12 0.8796 225
- 13 0.8878 227
- 14 0.8950 229
- 15 0.9013 230
- 16 0.9069 232
- 17 0.9119 233
- 18 0.9164 234
- 19 0.9204 235
- 20 0.9241 236
- 21 0.9275 237
- 22 0.9305 238
- 24 0.9360 239
- 25 0.9384 240
- 27 0.9427 241
- 29 0.9464 242
- 31 0.9497 243
- 34 0.9539 244
- 37 0.9575 245
- 41 0.9615 246
- 46 0.9655 247
- 51 0.9688 248
- 59 0.9729 249
- 69 0.9768 250
- 83 0.9806 251
- 104 0.9845 252
- 139 0.9883 253
- 209 0.9922 254
- 419 0.9961 255
Advertisement
Add Comment
Please, Sign In to add comment