Skip to content

Unexpected Pickup statistics with small float weights #11

Description

@skyuchukov-bp

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions