Académique Documents
Professionnel Documents
Culture Documents
Jiřı́ Vomlel
http://www.utia.cas.cz/vomlel/
where 0 · log 0 is defined to be zero. Note that the When the number of guesses is restricted to be at
Shannon entropy is zero if and only if the code is maximum m then we may be interested in a par-
known. The Shannon entropy is maximal when noth- tial strategy3 that brings most information about the
ing is known (i.e. when the probability distribution code within the limited number of guesses. If we use
Q(H1 , . . . , H4 | e) is uniform. the Shannon entropy (formula 7) as the information
Mastermind strategy is defined as a tree with nodes criteria then we can define expected entropy EH of
corresponding to evidence collected by performing a strategy as
guesses t = (t1 , . . . , t4 ) and getting answers c, p X
(in case of standard Mastermind game) or c0 , p0 (in EH = Q(en ) · H(Q(H1 , . . . , H4 | en )) ,
the probabilistic Mastermind). The evidence cor- n∈L
responding to the root of the tree is ∅. For ev- where L denotes the set of terminal nodes of the
ery node n in the tree with corresponding evidence strategy and Q(en ) is the probability of getting to
en : H(Q(H1 , . . . , H4 | en )) 6= 0 it holds: node n. We say that a Mastermind strategy T is a
most informative Mastermind strategy of depth ` if
• it has specified a next guess t(en ) and there is no other Mastermind strategy T 0 of depth `
with its EH 0 < EH.
• it has one child for each possible evidence ob-
tained after an answer c, p to the guess t(en )1 . In 1993, Kenji Koyama and Tony W. Lai [7] found
a strategy (of deterministic Mastermind) optimal in
A node n with corresponding evidence en such that average. It has EL = 5625/1296 = 4.340 moves.
H(Q(H1 , . . . , H4 | en )) = 0 is called a terminal node However, for larger problems it is hard to find an
since it has no children (it is a leaf of the tree) and the optimal strategy since we have to search a huge space
strategy terminates there. Depth of a Mastermind of all possible strategies.
strategy is the depth of the corresponding tree, i.e.,
the number of nodes of a longest path from the root Myopic strategy
to a leaf of the tree.
Already in 1976 D. E. Knuth [6] proposed a non-
We say that a Mastermind strategy T of depth ` is optimal strategy (of deterministic Mastermind) with
an optimal Mastermind strategy if there is no other 2
Mastermind strategy T 0 with depth `0 < `. It is the number of possible combinations (with rep-
etition) of three elements black peg, white peg, and no peg
The previous definition is appropriate when our main on four positions, while the combination of three black
interest is the worst case behavior. When we are pegs and one white peg is impossible.
3
Partial strategy may have terminal nodes with corre-
1
Since there are at maximum 14 possible combinations sponding evidence en such that H(Q(H1 , . . . , H4 | en )) 6=
of answers c, p node n has at most 14 children. 0.
the expected number of guesses equal to 4.478. His C0
maker. M3
M4
The approach suggested by Bestavros and Belal [2]
M5
uses information theory to solve the game: each
M6
guess is made in such a way that the answer max- C1 C2 C3 C4 C5 C6
step.
Let Tk = (T1k , . . . , T4k ) denote the guess in the step P1 T1 G1
k. Further let P 0k be the reported number of pegs
G2
with correctly guessed color and the position in the
P2 T2
step k and C 0k be the reported number of pegs with G3
correctly guessed color but in a wrong position in the
step k. Let ek denote the evidence collected in steps P3 T3
G4
1, . . . , k, i.e. G5
P P4 T4 G6
e(t1 , . . . , tk ) =
T = t1 , P 1 = p1 , C 01 = c01 ,
1
P0
. . . , Tk = tk , P 0k = p0k , C 0k = c0k
Figure 1: Bayesian network for the probabilistic
For each e(t1 , . . . , tk−1 ) the next guess is a tk that Mastermind game
minimizes
H1 H2 H3 H4 C
M1 B
P1
M2
M3
P2 M4
M5
M6
P3 C1 C2 C3 C4 C5 C6
P P4
H1 H2 H3 H4
0
P
P1
P3
Next, a naive approach would be to multiply all
probability distributions and then marginalize out
all variables except of variables of our interest. This P P4
would be computationally very inefficient. It is bet-
ter to marginalize out variables as soon as possi- P0
ble and thus keep the intermediate tables smaller.
It means the we need to find a sequence of multi- Figure 3: Bayesian network after the suggested
plications of probability tables and marginalizations transformation and moralization.
of certain variables - called elimination sequence -
such that it minimizes the number of performed nu-
The total size of its junction tree (given in Figure 4)
merical operations. The elimination sequence must
is 214, 775, i.e. it is more than 90 times smaller
satisfy the condition that all tables containing vari-
than the junction tree of Bayesian network before
able, must be multiplied before this variable can be
the transformation.
marginalized out.
After each guess of a Mastermind game we first up-
A graphical representation of an elimination se-
date the joint probability on H1 , . . . , H4 . Then we
quence of computations is junction tree [5]. It is the
retract all evidence and keep just the joint prob-
result of moralization and triangulation of the orig-
ability on H1 , . . . , H4 . This allows to insert new
inal graph of the Bayesian network (for details see,
evidence to the same junction tree. This process
e.g., [4]). The total size of the optimal junction tree
means that evidence from previous steps is combined
of the Bayesian network from Figure 2 is more than
with the new evidence by multiplication of distribu-
20, 526, 445. The Hugin [3] software, which we have
tions on H1 , . . . , H4 and consequent normalization,
used to find optimal junction trees, run out of mem-
which corresponds to the standard updating using
ory in this case. However, Hugin was able to find
the Bayes rule.
an optimal junction tree (with the total size given
above) for the Bayesian network from Figure 2 with- Remark In the original deterministic version of
out the arc P → C. Mastermind after each guess many combinations
B, P1 , . . . , P4 , P
B, P1 , . . . , P4
B, P1 , . . . , P4 , H4
B, P1 , . . . , P3 , H4
B, P1 , . . . , P3 , H3 , H4
B, P1 , P2 , H3 , H4
B, P1 , P2 , H2 , . . . , H4
B, P1 , H2 , . . . , H4
M1 , C 1 , B M6 , C 6 , B
B, P1 , H1 , . . . , H4
C1 , B B, H1 , . . . , H4 C6 , B
M2 , C 2 , B C1 , B, H1 , . . . , H4 C6 , B, H1 , . . . , H4 M5 , C 5 , B
C2 , B B, H1 , . . . , H4 B B, H1 , . . . , H4 C5 , B
C2 , B, H1 , . . . , H4 B, C C5 , B, H1 , . . . , H4
B, H1 , . . . , H4 B, H1 , . . . , H4
C3 , B, H1 , . . . , H4 B, H1 , . . . , H4 C4 , B, H1 , . . . , H4
C3 , B C4 , B
M3 , C 3 , B M4 , C 4 , B
h1 , . . . , h4 of variables of the hidden code H1 , . . . , H4 are left to an automatic inference engine. However,
get impossible, i.e. their probability is zero. We we have observed that, in case of probabilistic Mas-
could eliminate all combination of hidden code with termind, the inference using the standard methods is
zero probability and just keep information about not computationally feasible. It is necessary to ex-
non-zero combinations. This makes the junction tree ploit deterministic dependencies that are present in
even smaller. Note that several nodes in the junction the model. We have shown that after the transfor-
tree in Figure 4 contains all variables H1 , . . . , H4 . mation using an auxiliary variable we get a tractable
The elimination of zero values means that instead of model.
all 64 lists of probabilities for all combinations of val-
Acknowledgements
ues of other variables in the node we keep only those
lists that corresponds to a non-zero combination of The author was supported by the Grant Agency
H1 , . . . , H4 values. of the Czech Republic through grant number
201/02/1269.
Before we select the next most informative guess
the computation of Q(H1 , . . . , H4 | t, c0 , p0 ) are done
for all combinations of t1 , . . . , t4 , c0 , p0 . An open References
question is whether we can find a combination of
t1 , . . . , t4 minimizing the expected entropy more effi- [1] J. L. Bernier, C. Ilia Herraiz, J. J. Merelo,
ciently than by evaluating all possible combinations S. Olmeda, and A. Prieto. Solving mastermind
of t1 , . . . , t4 . using GA’s and simulated annealing: a case of
dynamic constraint optimization. In Parallel
Problem Solving from Nature IV, number 1141
5 Conclusions in Lecture Notes in Computer Science, pages
554–563. Springer Verlag, 1996.
One advantage of the Bayesian network model is the
natural visualization of the problem. The user cre- [2] A. Bestavros and A. Belal. MasterMind a game
ates the model of the problem and all computations of diagnosis strategies. Bulletin of the Faculty of
Engineering, Alexandria University, December
1986.
[3] Hugin Researcher 6.3. http://www.hugin.com/,
2003.