How do you handle weighted dice in your algorithm, concretely? #219
-
Hi, I've been reimplementing the paper recently in Java, and I must say that it did wonders. I polished my implementation of the base algorithm and it just works perfectly. My library does exactly what I want it to do. However I've advanced to the point where I want to add loaded dice. I've now been trying to implement weighted dice for a few days, but I couldn't find how. I know your paper mentions
But I just don't understand what you mean with "shifted copy". Considering your Python implementation of the basic algorithm on page 4, I've been basically doing the following: (I don't know if it's valid Python, but the idea is there) @cache
def solve(die, n):
(outcome, w), die = die.pop() # w is the weight of the outcome
if len(die) == 0:
state = next_state(None, outcome, n)
return {state : w} # This line is modified
result = defaultdict(int)
for k in range(n + 1):
tail = solve(die, n - k)
for state, weight in tail.items():
state = next_state(state, outcome, k)
weight *= comb(n, k) * w # This line is modified
result[state] += weight
return result I'm testing with 2 basic loaded dice I now believe that my I've tried to find out the answer by myself by reading the icepool codebase and understanding the difference between Do you have any pointers that could help me implement loaded dice? Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Glad to get your question! The short answer is the first modified line should have The long answer: suppose that, rather than computing If you like, you can think of this in terms of vectors instead of individual elements: One copy (blue) stays at the same Okay, now what if we want to do the weighted version? We can just multiply the rightward-traveling (red) number by We can vectorize this as well, in which case each element of the red vector gets multiplied by |
Beta Was this translation helpful? Give feedback.
-
Thank you for the explanation! I kind of needed it. I feel so dumb. I was so sure that I was only indirectly concerned by the first part of the paragraph, and therefore focused on the second part of it, not understanding that the "triangle" of the general layout (when printing a solution, for instance) wasn't the Pascal triangle you mentioned. Anyways you put back my neurons in marching order and I thank you! I'll consider using the optimization for |
Beta Was this translation helpful? Give feedback.
Glad to get your question! The short answer is the first modified line should have
pow(w, n)
rather thanw
and the other modified linepow(w, k)
instead ofw
.The long answer: suppose that, rather than computing$n$ and $k$ , we want to compute it for all $0 \leq k \leq n \leq N$ for some $N$ . (Indeed, the dice pool algorithm will visit every one of these coefficients at some point.) For the pure binomial case ($w=1$ ) it's well-known that we can do this using Pascal's triangle, where each entry is the sum of the two entries above it:
comb(n, k) * pow(w, k)
for a single choice ofIf you like, you can think of this in terms of vectors instead of individual elements:
One copy (blue) stays …