endolith / elsim

Election Simulator 3000: Simulates a variety of elections and voting methods

Home Page:https://endolith.github.io/elsim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vectorize methods

endolith opened this issue · comments

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)

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

Need to

  • generate the utilities in chunks,
  • feed those chunks to the method functions,
    • some of which can be vectorized and some of which can't,
  • re-use the same utilities for different methods, but
  • don't re-use for the same method,
  • parallelize everything.