Math time: binomial distributions in splitter pyramids, and the effects of splitter biases

Post all other topics which do not belong to any other category.
Post Reply
jeff.s
Burner Inserter
Burner Inserter
Posts: 16
Joined: Thu Jan 10, 2019 10:49 pm
Contact:

Math time: binomial distributions in splitter pyramids, and the effects of splitter biases

Post by jeff.s »

Introduction
I got to wondering about splitter pyramids. You know, these contraptions you might build the first time you're trying to split a belt into 6 to load into a train wagon:
example.png
example.png (437.53 KiB) Viewed 3784 times

Splitters alternate sending items right and then left. The first item arriving at a newly placed splitter always goes right. So let's try to draw a diagram the proportion of each belt passing through balancers:
diagram.png
diagram.png (35.75 KiB) Viewed 3784 times

Each balancer receives half of the materials going into each of the two balancers above this. Maybe you've already seen the Pascal's Triangle here. Ignoring the denominators of the fractions, which simply go up as the powers of 2, the numerators are just the binomial coefficients.

The Experiment
The problem is, does the slight bias of splitters affect this distribution? To figure this out, I decided to do some Factorio Science! I made a 64x64 tile map and built a splitter pyramid with 32 splitters on the output (it uses Editor Extensions to create/destroy belts of items). It uses some simple circuits to dispense a single half-belt until exactly 2^28 fish go into the top, and it tracks how many fish come out of each output splitter.

Here's blueprint I used:
blueprint.txt
(8.17 KiB) Downloaded 95 times
setup.jpg
setup.jpg (1.16 MiB) Viewed 3784 times

I let this run overnight at ~16000 UPS and it finished. Each output counter also has a constant combinator wired to its input with an "N" signal ranging from 1 to 32, which makes it easy to extract the data when the run is finished with a small lua snippet:

Code: Select all

local function red_input(e, type, name)
    return e.get_circuit_network(defines.wire_type.red, defines.circuit_connector_id.combinator_input).get_signal({type=type, name=name})
end
local csv = "splitter,fish\n"
for _, e in ipairs(game.surfaces.nauvis.find_entities_filtered({name="decider-combinator"})) do
    local index = red_input(e, "virtual", "signal-N")
    local count = red_input(e, "item", "raw-fish")
    csv = csv .. index .. "," .. count .. "\n"
end
game.write_file("data.csv", csv)
Results
Surprisingly, the output counts were either -1, 0, or +1 from the binomial distribution, despite the small bias of the splitters. I was definitely expecting the splitter bias to pile up and cause at least one splitter to end up with a surplus or deficit of 2 or more, but that's not the case:
data.csv
(1.6 KiB) Downloaded 100 times
data.png
data.png (79.27 KiB) Viewed 3784 times

Analysis of more complicated splitter network topologies (such as belt balancers) is left as an exercise for the reader :)

If you want to run 2^32 items through, please do and report back your findings!

s.vorotilo
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sat Sep 19, 2020 7:59 am
Contact:

Re: Math time: binomial distributions in splitter pyramids, and the effects of splitter biases

Post by s.vorotilo »

Hey, that's pretty cool, would you be interested in doing more Factorio Science?
https://www.reddit.com/r/factorio/comme ... oriobased/

Post Reply

Return to “General discussion”