endolith / elsim

Election Simulator 3000: Simulates a variety of elections and voting methods
https://endolith.github.io/elsim
MIT License
7 stars 4 forks source link

Vectorize methods #1

Open endolith opened 5 years ago

endolith commented 5 years ago

I think all of these functions could accept 3D arrays of shape (n_voters, n_cands, n_elections) or (n_elections, n_voters, n_cands), whichever makes more sense, and return a list of winners for each election.

np.array((impartial_culture(5, 4), impartial_culture(5, 4)))
Out[16]:
array([[[1, 2, 0, 3],
        [2, 1, 3, 0],
        [3, 0, 1, 2],
        [3, 1, 2, 0],
        [2, 3, 0, 1]],

       [[0, 2, 3, 1],
        [2, 3, 1, 0],
        [1, 3, 2, 0],
        [2, 1, 0, 3],
        [0, 2, 3, 1]]], dtype=uint8)

_.shape
Out[17]: (2, 5, 4)
endolith commented 5 years ago

Huge elections would run out of memory, but still would be faster than processing them in a loop.

    a = np.empty((100000, 10000, 10), dtype=np.uint8)

        MemoryError
endolith commented 3 years ago

Need to