Guest User

Untitled

a guest
Sep 9th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.41 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*c*256).floor
  20.   if b != lastb then
  21.     printf "%3d %.4f %d\n", n, c, b
  22.     lastb = b
  23.   end
  24. end
  25.  
  26. __END__
  27.   0 0.0000 0
  28.   1 0.3784 36
  29.   2 0.5491 77
  30.   3 0.6462 106
  31.   4 0.7089 128
  32.   5 0.7527 145
  33.   6 0.7851 157
  34.   7 0.8100 167
  35.   8 0.8297 176
  36.   9 0.8457 183
  37.  10 0.8589 188
  38.  11 0.8701 193
  39.  12 0.8796 198
  40.  13 0.8878 201
  41.  14 0.8950 205
  42.  15 0.9013 207
  43.  16 0.9069 210
  44.  17 0.9119 212
  45.  18 0.9164 214
  46.  19 0.9204 216
  47.  20 0.9241 218
  48.  21 0.9275 220
  49.  22 0.9305 221
  50.  23 0.9334 223
  51.  24 0.9360 224
  52.  25 0.9384 225
  53.  26 0.9406 226
  54.  27 0.9427 227
  55.  28 0.9446 228
  56.  29 0.9464 229
  57.  30 0.9481 230
  58.  32 0.9512 231
  59.  33 0.9526 232
  60.  35 0.9552 233
  61.  36 0.9564 234
  62.  38 0.9586 235
  63.  40 0.9606 236
  64.  42 0.9624 237
  65.  45 0.9648 238
  66.  47 0.9662 239
  67.  51 0.9688 240
  68.  54 0.9705 241
  69.  58 0.9725 242
  70.  63 0.9746 243
  71.  68 0.9764 244
  72.  74 0.9783 245
  73.  82 0.9804 246
  74.  91 0.9823 247
  75. 103 0.9843 248
  76. 118 0.9863 249
  77. 138 0.9882 250
  78. 166 0.9902 251
  79. 208 0.9922 252
  80. 278 0.9941 253
  81. 418 0.9961 254
  82. 839 0.9980 255
  83.  
Advertisement
Add Comment
Please, Sign In to add comment