Guest User

Untitled

a guest
Sep 9th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. def calculated_confidence score
  2. return 0 if score == 0
  3. n = score.to_f
  4.  
  5. upvotes = score
  6. z = 1.281551565545 # 80% confidence
  7. p = upvotes.to_f / n
  8.  
  9. left = p + (1 / (2.0 * n) * z * z)
  10. right = z * Math.sqrt((p * ((1.0 - p) / n)) + (z * (z / (4.0 * n * n))))
  11. under = 1.0 + ((1.0 / n) * z * z)
  12.  
  13. (left - right) / under
  14. end
  15.  
  16. lastb = -1
  17. (0..1000).each do |n|
  18. c = calculated_confidence(n)
  19. b = (c*256).floor
  20. if b != lastb then
  21. printf "%3d %.4f %d\n", n, c, (c*256).floor
  22. lastb = b
  23. end
  24. end
  25.  
  26. __END__
  27. 0 0.0000 0
  28. 1 0.3784 96
  29. 2 0.5491 140
  30. 3 0.6462 165
  31. 4 0.7089 181
  32. 5 0.7527 192
  33. 6 0.7851 200
  34. 7 0.8100 207
  35. 8 0.8297 212
  36. 9 0.8457 216
  37. 10 0.8589 219
  38. 11 0.8701 222
  39. 12 0.8796 225
  40. 13 0.8878 227
  41. 14 0.8950 229
  42. 15 0.9013 230
  43. 16 0.9069 232
  44. 17 0.9119 233
  45. 18 0.9164 234
  46. 19 0.9204 235
  47. 20 0.9241 236
  48. 21 0.9275 237
  49. 22 0.9305 238
  50. 24 0.9360 239
  51. 25 0.9384 240
  52. 27 0.9427 241
  53. 29 0.9464 242
  54. 31 0.9497 243
  55. 34 0.9539 244
  56. 37 0.9575 245
  57. 41 0.9615 246
  58. 46 0.9655 247
  59. 51 0.9688 248
  60. 59 0.9729 249
  61. 69 0.9768 250
  62. 83 0.9806 251
  63. 104 0.9845 252
  64. 139 0.9883 253
  65. 209 0.9922 254
  66. 419 0.9961 255
  67.  
Advertisement
Add Comment
Please, Sign In to add comment