Nashpy icon indicating copy to clipboard operation
Nashpy copied to clipboard

massive complexity improvement for fictitious play

Open louisabraham opened this issue 1 year ago • 2 comments

Currently, fictitious play stores count vectors and recomputes each time the payoff of each move by matrix multiplication before selecting the best move.

  • move = payoff.argmax() costs $\mathcal{O}(n)$
  • count[move] += 1 costs $\mathcal{O}(1)$
  • payoff = matrix @ count costs $\mathcal{O}(n * m)$

Instead, one could just update the payoff vector with payoff += matrix[:, move] in $\mathcal{O}(n)$.

Even better, the matrix can be stored transposed to be able to write matrix[move] which is more cache efficient.

louisabraham avatar Feb 28 '23 10:02 louisabraham

This sounds like a great improvement. Would you like to work on a PR for this?

drvinceknight avatar Mar 03 '23 10:03 drvinceknight

sure, it's like 10 sloc will do after lunch

louisabraham avatar Mar 03 '23 10:03 louisabraham