I am developing a chess engine, and wrote four classifiers (logistic regression) for:
- detecting which part of the game it is (opening, middlegame, endgame) based on current board / position
- predicting that white will win (no draw games) if in opening position
- predicting that white will win (no draw games) if in middlegame position
- predicting that white will win (no draw games) if in endgame position
Now for the engine, I would like to compute the probability that white will win (for the minimax algorithm, white tries to increase this probability, black tries to decrease this probability by making moves). My first guess was to compute:
P(W) = P(W|Opening)*P(Opening) + P(W|Middlegame)*P(Middlegame) + P(W|Endgame)*P(Endgame)
Where each probability on the right is from logistic regression above. But now I am unsure, if this is the right "ansatz".
Edit: The idea here is to have a bitboard representation of a position and to interpret the coefficients of the logistic regression as piece value tables as is custom in other engines, with the difference that the values in this table are from logistic regression and not from experience of the programmer / player. As you can imagine predicting is stronger at the end of the game (opening 64% accuracy, middlegame 75 %, end game 83% ) so my idea was to write a classifier which detects on which part of the game it is and then to "combine" these different classifiers to have an evalutation function for each board.
I will illustrate this with some concrete probabilities:
r n b q k b n r p p p p p . . . . . . . . . . p . . . . . p p . . . . P P . . P . . . . . . . N P P P . . P P . R N B Q K B . R # whichPart = [0.91647043 0.07489996 0.00862961] # prOpen = [0.20907355 0.79092645] # prMiddle = [0.00829384 0.99170616] # prEnd = [0.00323957 0.99676043] # pWhiteWins = 0.8077411092561112
So for the position above, the logistic regression whichPart detects correctly that the position belongs to the opening part ( 0.91 probability). But then prOpen thinks that white will win with probability 0.79, which is unclear at this point and which results in 0.8 probability that white will win.
My question is: How do I incorporate the uncertainity of the logistic regression
prOpen when calculating the probability that white will win?
Below are the confusion matrices for the logistic regressions:
Logistic regression for detecting which part of the game it is:
[[1536 205 20] [ 226 1202 376] [ 6 299 1381]]
Logistic regression for detecting if white won the game based on observing one position from the opening:
[[334 421] [240 756]]
Logistic regression for detecting if white won the game based on observing one position from the middlegame:
[[517 238] [208 788]]
Logistic regression for detecting who won the game based on observing one position from the endgame:
[[611 144] [157 839]]