Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Pickup statistics with small float weights #11

Open
skyuchukov-bp opened this issue Jul 6, 2020 · 0 comments
Open

Unexpected Pickup statistics with small float weights #11

skyuchukov-bp opened this issue Jul 6, 2020 · 0 comments

Comments

@skyuchukov-bp
Copy link

skyuchukov-bp commented Jul 6, 2020

Pickup gem version: 0.0.11
Test cases:

Sum approaching 1:
(1..10000).map { Pickup.new({"X1" => 0.11, "Y" => 0.78, "X2" => 0.11}).pick() }
Result frequency table (actual): [["X1", 10000]]
Comment: One of the elements was chosen always, and it has one of the 2 smallest weights

Sum above 1, but with a small element:
(1..10000).map { Pickup.new({"X" => 0.11, "Y" => 1.01, "Z" => 1.11}).pick() }
Result frequency table (actual): [["Y", 4925], ["X", 5075]]
Comment: No Z in the results, this might already be reported in #7

Sum above 1, each weight at least twice as big/small as the other two:
(1..10000).map { Pickup.new({"X" => 0.11, "Y" => 1.01, "Z" => 2.11}).pick() }
Result frequency table (actual): [["Z", 3323], ["X", 3333], ["Y", 3344]]
Comment: Items in the result have equal distribution, albeit input weights for X and Z having >19 times difference

P.s. Frequency tables calculated via this helper function:

def frequency_table(collection)
  table = collection.inject(Hash.new(0)) { |hash, element| hash[element] += 1; hash }
  table.sort_by { |_key, value| value }
end
@skyuchukov-bp skyuchukov-bp changed the title Unexpected Pickup statistics with float weights Unexpected Pickup statistics with small float weights Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant