Is it possible to delete a move from a Polyglot book?

Discussions about Winboard/Xboard. News about engines or programs to use with these GUIs (e.g. tournament managers or adapters) belong in this sub forum.

Moderator: Andres Valverde

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 08 May 2011, 06:22

K Inuen wrote:If Polyglot Bin books have some active book-learn & book-adjustment functions similar to Ctg books (Fritz GUIs), that directly adjust bin book moves as games progress, this would catapult Bin books further. I think this is the only advantage Ctg books have over Polyglot Bin books.

Would you grant us, Winboard + Polyglot enthusiasts, this dream H.G.Muller/Michel? Thanks.


Well, Polyglot books are prepared for this, as in addition to the weights they do store a 'learn field' with each (position, move) pair, which can hold a 32-bit integer. I haven't included that learn field in the Edit Book dialog yet, because to my knowledge there is no one that uses it. This could be changed, of course.

I don't think it makes much sense to apply learning to a GUI book, as it is intended to be shared by all engines. The natural place to apply learning would be Polyglot.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby Denis P. Mendoza » 09 May 2011, 16:01

The problem of Ed Collins was the same as mine before, but good that he also found the solution. I'm sure polyglot can do a book editing too in the future!

The natural place to apply learning would be Polyglot.


That is correct, as that is an engine option using polyglot, not the GUI.

by Michel:
BookLearn (default: false)
Store learning information in the book (which must be writable).
Currently no engine actually uses this information.


by Fonzy:
- "BookLearn" (default: false)
Record learning information in the opening book. Naturally this
requires the opening book to be writable.
I'm proud to be a Pinoy! Ikaw dre?
Denis P. Mendoza
 
Posts: 84
Joined: 31 Oct 2007, 16:38
Location: Philippines

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 09 May 2011, 23:38

@ H.G.Muller and Denis,

By my interpretation of the quotes produced (from Michel and Fonzy), it would seem the algorithm of Polyglot & it's book-making mechanisms would have to be changed or rewritten such that it allows Bin books made, to be writable. Hence proper 'BookLearn' function if set to 'true'.

In order to use a writable bin book, a new 'race' of Polyglot adapter is necessary which produces a new type of writtable Bin book format. This is crucial for the progress of Bin books.

Is this possible, Michel? Thanks.
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 10 May 2011, 07:55

The way I read the quotes is that Polyglot already writes learning information into a bin book file (provided the user switches BookLearn on). When it is using the book, not when it is making it. The current format of bin books certainly allows it to do that, as it reserves 4 bytes of space with each move in the book, for learning info. Whether the book is writable or not is an OS matter.

What I don't understand is the remark that no known engine uses the info. If Polyglot writes the info, the logical thing would be that Polyglot also uses the info, and apparently the engine lets Polyglot handle the book. So the thing that matters is that Polyglot does not use the learn info it writes. If it were made to do so, we would immediately have switched to a situation where _all_ UCI engines would use the learning info (when running under Polyglot).
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 10 May 2011, 09:16

H.G.Muller wrote:The way I read the quotes is that Polyglot already writes learning information into a bin book file (provided the user switches BookLearn on). When it is using the book, not when it is making it. The current format of bin books certainly allows it to do that, as it reserves 4 bytes of space with each move in the book, for learning info. Whether the book is writable or not is an OS matter.

What I don't understand is the remark that no known engine uses the info. If Polyglot writes the info, the logical thing would be that Polyglot also uses the info, and apparently the engine lets Polyglot handle the book. So the thing that matters is that Polyglot does not use the learn info it writes. If it were made to do so, we would immediately have switched to a situation where _all_ UCI engines would use the learning info (when running under Polyglot).


I understand that Polyglot, at least as intended and when BookLearn=true, is supposed to wite learning information during game play. The problem is, this feature does not work. In fact, when BookLearn=true, either the engine used or the Polyglot adapter (with the BookLearn feature) would crash and send an error message similar to this:

Error writing to file: Polyglot has caused exception error...


So in order to avoid the exception error during gameplay, the BookLearn feature had to be disabled (BookLearn=false). The BookLearn=false was advised by Michel upon my encounter with this problem, as described above, and sent him the Polyglot log file. By the way, my OS is Windows 7.

A picuter of the exception error experienced when BookLearn=true
http://imageshack.us/photo/my-images/19 ... ormsg.png/
Image

Uploaded with ImageShack.us
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 10 May 2011, 10:40

This is clearly a Polyglot bug. When I try it, I get a completely different error message, though. E.g. from the log file:

Code: Select all
1305017481.004 POLYGLOT *LEARN WIN*
1305017481.004 POLYGLOT write_integer(): fputc(): No such file or directory
1305017481.004 POLYGLOT *** QUIT ***


This is not really a crash, but a voluntary exit by Polyglot, after discovering the fputc() call it attempted to use to write a byte into the book file returned a failure code. The error message doesn't seem to make sense, though: this is not an error one could get when writing a stream. So I wonder if the correct error (derived from errno) is returned here. I suspect it is an earlier error (from when it tried to open its default book at startup, which is not there) that was still hanging there.

Shouldn't the routine ferror(FILE *f); be used to get the error on the stream I/O?

From looking at the log, it seems the probem is the options are processed in the wrong order:

Code: Select all
1305017454.316 POLYGLOT *** LOGFILE OPENED ***
1305017454.316 POLYGLOT Setting PolyGlot option "Book=true"
1305017454.316 POLYGLOT *** SETTING BOOK ***
1305017454.316 POLYGLOT BOOK "book.bin"
1305017454.316 POLYGLOT Unable to open book "book.bin"
1305017454.316 POLYGLOT Setting PolyGlot option "BookFile=C:\WinBoard-4.5.0\WinBoard\testbook.bin"
1305017454.316 POLYGLOT *** SETTING BOOK ***
1305017454.316 POLYGLOT BOOK "C:\WinBoard-4.5.0\WinBoard\testbook.bin"
1305017454.316 POLYGLOT Setting PolyGlot option "BookLearn=true"


First the book (in this case testbook.bin) is opened, and only after that the option BookLearn is set. So when the book was openend, BookLearn was still false, and the book file was opened read-only...

Michel!? :wink:

Current work-around is to put BookLearn=true in the polyglot.ini file _before_ the line that sets the Book option. Then it works for me.

Code: Select all
; Created: Tue May 10 10:50:33 2011

[PolyGlot]
EngineCommand=glaurung.exe
EngineDir=C:\cygwin\home\hgm\glaurung22
Log=true
LogFile=learn.log
Book=true
BookLearn=true
BookFile=C:\WinBoard-4.5.0\WinBoard\testbook.bin
[Engine]
Hash=20


When I check the 'properties' of testbook.bin, indeed it now says it was last modified today. I haven't actually checked what the modification was (my WinBoard Edit Book function does not print the learn field yet), but from looking at the Polyglot code I guess this must be OK. It seems the learning stores then number of times the move is played, and the number of half-points scored with it, each as a 16-bit integer.

Edit:
I can confirm now that the book learn info is written by Polyglot exactly as it should. It only updates the stats for all book moves played by the engine that was using the book, not for the moves played by its opponent.

So it would just be a matter of having Polyglot's book-probing code use this statistics (in addition to the weights) to decide which move to pick. It could, for instance, use the info to modify the weights (not in the book,of course, but in its move-picking calculation) as follows:

weight *= (learnPoints+10.)/(learnTotal+1.)

This would bias it to play moves it did not play before (because the weights of such moves are multiplied by 10), but when moves are played many times with an average result (50%), the multiplier would converge (after many more than 10 plays) to 1, and above-average results would converge to a higher value (maximally doubling the weight), while very poor results could reduce it to nearly zero. To tune the aggressiveness of the learning,one could introduce an exponent f:

weight *= power( (learnPonts + power(10., 1./f))/(learnTotal+1.), f);
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 10 May 2011, 13:50

Indeed I rearranged my internal Polyglot options according to the example you provided, with BookLearn=true, and haven't experienced exceptional error/s except on 2 accounts; when a 'certain' draw was reached (in an engine-engine match). The engine used in engine-engine match is the same for white and black, along with one (or the same) bin book for the match.

Besides these 2 incidences, the BookLearn appears to work fine though the write-log (in Windows OS) shows it only wrote once. The 'writing' to the bin book used happened only once despite playing numerous games after that. In other words, the future games played, despite wins, lose or draws were no longer 'written' to the bin book after the initial book-writing.

Here's the specific exceptional error produced from a 'certain' draw game. This happened 2x but with different draw games:

Image

Uploaded with ImageShack.us

And here's the actual draw games (as experienced twice) on Winboard GUI that cause exceptional error:

Image

Uploaded with ImageShack.us

If it helps, here's the game:
Code: Select all
[Event "Computer Chess Game"]
[Site "PC-PC"]
[Date "2011.05.10"]
[Round "-"]
[White "PolyGlot"]
[Black "PolyGlot"]
[Result "1/2-1/2"]
[TimeControl "240"]
[Annotator "30... -0.14"]

1. e4 d5 2. exd5 Qxd5 3. Nc3 Qa5 4. d4 Nf6 5. Nf3 c6 6. Bc4 Bf5 7. Bd2 e6
8. Qe2 Bb4 9. O-O-O Nbd7 10. a3 Bxc3 11. Bxc3 Qc7 12. Ne5 O-O 13. g4 Nxe5
14. dxe5 Nxg4 15. Rhg1 b5 16. Bb3 Nh6 17. Rd6 Rfd8 18. Bd2 Bg6 19. Bxh6
gxh6 20. h4 Rxd6 21. exd6 Qxd6 22. h5 Qh2 23. Qd1 Qxf2 24. hxg6 hxg6 25.
Kb1 Kg7 26. c3 c5 27. Rf1 Qg2 28. Bc2 h5 29. Rg1 Qf2 30. Rf1 Qg2
{-0.14/27 7} 31. Rg1 Qf2 32. Rf1 Qg2 {-0.14/28 5}
{XBoard adjudication: repetition draw} 1/2-1/2
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby Michel » 10 May 2011, 14:23

I am just noticing this thread but I am busy today. I thought I fixed the invalid file descriptor bug a while ago but apparently not.
I am not sure if I ever found the cause of the unknown side bug. I will look into it.
Michel
 
Posts: 513
Joined: 01 Oct 2008, 12:15

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 10 May 2011, 22:03

The "Unkown side" bug should be 'impossible', as there was an ASSERT just before it that says it cannot happen:

Code: Select all
static void learn(int result) {

   int pos;
   board_t board[1];
   int move;

   ASSERT(result>=-1&&result<=+1);

   ASSERT(XB->result);
   ASSERT(State->computer[White]||State->computer[Black]);

   // init

   pos = 0;

   if (FALSE) {
   } else if (State->computer[White]) {
      pos = 0;
   } else if (State->computer[Black]) {
      pos = 1;
      result = -result;
   } else {
      my_fatal("learn(): unknown side\n");
   }


It can only be explained by asynchronous execution, if the thread running the quoted code could be interrupted between the ASSERT and the if-statements, by something that resets the State->computer[i] flags. (In particular a 'force' command that would reset both to FALSE.)

Come to think of it, the way Polyglot does this seems unsound, and cannot bear the behavior of the newer WinBoard versions that adjudicate:
When WinBoard receives a move from the opponent that causes a draw adjudication, it first puts the opponent engine in force mode, and only then relays the opponent move causing the draw. This to prevent that engines that do not claim the draw by themselves will start thinking on a reply drawing move, and would only look at the message telling the game has ended when they are done with that.

So the engine will have been put in force mode before receiving the 'result' command on which it starts 'learning'. As 'force' sets both State->computer flags to FALSE, it cannot use them anymore to decide which color should do the learning. There really should be introduced some memory as to the last side for which it has been playing. In fact it would be good to verify that it has been playing all the moves for that side, as it seems to make little sense to learn from a game where you only played part of the moves and then changed side to play the last move in a position that was already decided.

So it would be good to have two Booleans playedAllOutOfBookMoves[color], which are initialized to TRUE on 'new' and any book move that is played by that color, and reset to FALSE on any move received in force mode for that color. Learning should only take place for the side that has the flag set to TRUE after the game. (So it could actually be applied to both sides when the engine was made to play both sided after getting out of book, by sending it 'go' on every move.) If both flags are FALSE, it should not be considered an error (and certainly not a fatalone!); it just means that the user has only let the engine play part of the game, so that learning from the game is not appropriate.

What I don't see is how the current code could ever get through the ASSERT after WinBoard puts it in force mode...
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 12 May 2011, 02:28

An observation with BookLearn=true:

I played online games yesterday with Winboard and Polyglot and noticed that, despite games my program lost, it kept repeating the moves that led to it losing in previous games.

Also, I noticed a 'fixed number of repetition' of won/lose games. For example, if I won 2 games in a row and then lose 2 game in a row, this 2-win and 2-lose game pattern keeps repeating itself. The BookLearn feature was working by the apparent updating (or writing) of the Bin book used during game play - (apparent by the time of update too). Is the BookLearn=true feature working as intended?

Does Polyglot actually make use of the learned-positions or moves it stored (or write) to the bin book? Does Polyglot even probe for the preferred positions it supposedly learned earlier?

Thanks.
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby F. Bluemers » 12 May 2011, 04:11

H.G.Muller wrote:The "Unkown side" bug should be 'impossible', as there was an ASSERT just before it that says it cannot happen:

<snip>
ASSERT(State->computer[White]||State->computer[Black]);
<snap>

Normally one sees assert()... instead of ASSERT().
Anyway, an assert() call will be removed by the preprocessor if -DEBUG is not defined
See f.i. assert.h
F. Bluemers
 
Posts: 175
Joined: 04 Sep 2008, 16:56
Location: Netherlands

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 12 May 2011, 07:22

K Inuen wrote:Does Polyglot actually make use of the learned-positions or moves it stored (or write) to the bin book? Does Polyglot even probe for the preferred positions it supposedly learned earlier?


No, Polyglot does not use the learn info on probing. This is why I proposed above to put in the formula to alter the weights during probing; then it would. Not sure if the formula is optimal, though. I started a discussion on TalkChess about that.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 12 May 2011, 07:42

H.G.Muller wrote:
K Inuen wrote:Does Polyglot actually make use of the learned-positions or moves it stored (or write) to the bin book? Does Polyglot even probe for the preferred positions it supposedly learned earlier?


No, Polyglot does not use the learn info on probing. This is why I proposed above to put in the formula to alter the weights during probing; then it would. Not sure if the formula is optimal, though. I started a discussion on TalkChess about that.


Thanks for the clarification and the proposed method. Provided Michel can spare some of his time to implement the proposed formula, I'm willing to test this out and report to you both.

Michel ?! :wink:
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 12 May 2011, 08:51

In any case I have implemented the handling of learn info in the Edit-Book function of WinBoard now. When the learn fields are non-zero, the edit window wil print {halfPoints/nrOfPlays} behind the move, and this info is then written back when you save. You can also edit this info, if you want.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 12 May 2011, 09:19

H.G.Muller wrote:In any case I have implemented the handling of learn info in the Edit-Book function of WinBoard now. When the learn fields are non-zero, the edit window wil print {halfPoints/nrOfPlays} behind the move, and this info is then written back when you save. You can also edit this info, if you want.


Where can I download this Winboard with the implemented learn info within the GUI?
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 12 May 2011, 09:36

http://hgm.nubati.net/WinBoard-TM.zip

It contains a bare winboard.exe. Note that it does not use the learn info on probing either; for a GUI book that does not seem appropriate. It just allows you to edit it.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 12 May 2011, 09:47

Thanks H.G.Muller. I'll test it sometime today and relay results.
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby K Inuen » 13 May 2011, 06:19

Update for H.G.Muller (and maybe for Michel?):

I played few games with an opponent. This is what the Edit Book feature yielded upon inquiry:
Image

Uploaded with ImageShack.us


My win / draw statistic summary:

Game1: Draw........e4 (opponent responded with 1.e6)
Game2: Win.........c5 (in response responded with 1.e4)
Game3: Win.........d4 (opponent responded with 1.d5)
Game4: Draw........c5 (in response to opponent's 1.e4)
Game5: Win.........d4 (opponent responded with 1.d5)

Question: if I wanted to edit a book, using the Edit Book feature, how would I go about it? Or how does the statistics (4/2, 1/1,...) in the Edit Book panel help me in this regard? Thanks.
K Inuen
 
Posts: 50
Joined: 27 Apr 2010, 02:25

Re: Is it possible to delete a move from a Polyglot book?

Postby H.G.Muller » 13 May 2011, 08:34

To edit the book, you would simply replace the weights (7800 or 65520 in this case) by what you want it to be, by typing into the Edit Book window, and press OK. The info in the window is then written back into the book. (You'd better not write something invalid there, like illegal moves or nonsense messages, as in this primitive implementaton there is no validity checking before writing the info back to the book, and it will only write back the stuff upto the point where it encounters something invalid. So you could lose moves from the book by this!) The learning info tells you that you played two games with 1.d4, and won them both (4 half-points), and 1 game with 1.e4, which was a draw (1 half-point). Results when the opponent played white are not incorporated. You could also edit that before you OK the dialog (but there seems little point in doing that).
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Is it possible to delete a move from a Polyglot book?

Postby matematiko » 13 May 2011, 09:37

The percentages (42.4+42.4 +5.1+5.1+5.1) add to 100.1 which is acceptable/OK I guess...but the other numbers (65520+65520+7800+7800+7800) add to 154,440...what gives? Isn't this sum supposed to be 10,000? Or some sort of 1-EE XX where XX is an integer number?

Just curious to what this 65520 and 7800 are supposed to mean in relation to the percentage.

Thanks,
One that does not live to serve, does not deserve to live.
matematiko
 
Posts: 219
Joined: 07 Dec 2008, 17:11
Location: Texas

PreviousNext

Return to Winboard and related Topics

Who is online

Users browsing this forum: No registered users and 37 guests