5 questions about the command "eval" in Stockfish

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
mohzus
Posts: 106
Joined: Tue Sep 24, 2013 2:54 am

5 questions about the command "eval" in Stockfish

Post by mohzus »

Hello guys,
When using SF with the command-line and entering a FEN like: [d]1q3k2/3p3p/8/8/8/4PB2/3PNKP1/8, typing

Code: Select all

eval
will return something like

Code: Select all

           Eval term |    White    |    Black    |     Total     
                     |   MG    EG  |   MG    EG  |   MG     EG   
---------------------+-------------+-------------+---------------
Material, PST, Tempo |   ---   --- |   ---   --- |  -3.23  -2.53 
  Material imbalance |   ---   --- |   ---   --- |  -0.17  -0.17 
               Pawns |   ---   --- |   ---   --- |   0.19   0.17 
             Knights | -0.04 -0.06 |  0.00  0.00 |  -0.04  -0.06 
             Bishops |  0.02  0.00 |  0.00  0.00 |  +0.02  +0.00 
               Rooks |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
              Queens |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
            Mobility |  0.60  0.62 |  0.14  0.28 |  +0.45  +0.34 
         King safety |  0.42 -0.08 | -0.19 -0.16 |  +0.61  +0.08 
             Threats |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
        Passed pawns |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
               Space |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
---------------------+-------------+-------------+---------------
               Total |   ---   --- |   ---   --- |  -2.31  -2.26 

Scaling:   0.78% MG,  99.22% * 100.00% EG.
Total evaluation: -2.26
What I understand from this output is that the white knight has a slightly bad position both for middle and end game phases according to SF. I think I understand what most of these values are.
However I do not understand the last 2 lines. I do not understand anything from the penultimate line; it looks like it wants to calculate whether the position is a middle game or end game or somewhere in between using, I am guessing from what I've read so far, a linear interpolation based on non-pawn material. But still with this in mind I do not understand it. I'd appreciate if someone could shred some light here. (1)
About the last line, it seems that from it I can determine that SF thinks it's 100% end game, because the eval is -2.26 which corresponds exactly to the EG eval showed at line

Code: Select all

  Total |   ---   --- |   ---   --- |  -2.31  -2.26 
, is this correct? (2)

But what does eval mean? It is not the evaluation returned when you type

Code: Select all

go movetime 10000
for instance. What does this number represent? (3)

Lastly, I would like to know whether the raw numbers in the table are used in stockfish's code and where (what file) just for fun. (4) Also, how are they calculated? For example is the value of the white knight calculated via the NPSQT? (5)

Thank you guys.
P.S.:I posted this question here as suggested there: http://support.stockfishchess.org/.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: 5 questions about the command "eval" in Stockf

Post by bob »

mohzus wrote:Hello guys,
When using SF with the command-line and entering a FEN like: [d]1q3k2/3p3p/8/8/8/4PB2/3PNKP1/8, typing

Code: Select all

eval
will return something like

Code: Select all

           Eval term |    White    |    Black    |     Total     
                     |   MG    EG  |   MG    EG  |   MG     EG   
---------------------+-------------+-------------+---------------
Material, PST, Tempo |   ---   --- |   ---   --- |  -3.23  -2.53 
  Material imbalance |   ---   --- |   ---   --- |  -0.17  -0.17 
               Pawns |   ---   --- |   ---   --- |   0.19   0.17 
             Knights | -0.04 -0.06 |  0.00  0.00 |  -0.04  -0.06 
             Bishops |  0.02  0.00 |  0.00  0.00 |  +0.02  +0.00 
               Rooks |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
              Queens |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
            Mobility |  0.60  0.62 |  0.14  0.28 |  +0.45  +0.34 
         King safety |  0.42 -0.08 | -0.19 -0.16 |  +0.61  +0.08 
             Threats |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
        Passed pawns |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
               Space |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
---------------------+-------------+-------------+---------------
               Total |   ---   --- |   ---   --- |  -2.31  -2.26 

Scaling:   0.78% MG,  99.22% * 100.00% EG.
Total evaluation: -2.26
What I understand from this output is that the white knight has a slightly bad position both for middle and end game phases according to SF. I think I understand what most of these values are.
However I do not understand the last 2 lines. I do not understand anything from the penultimate line; it looks like it wants to calculate whether the position is a middle game or end game or somewhere in between using, I am guessing from what I've read so far, a linear interpolation based on non-pawn material. But still with this in mind I do not understand it. I'd appreciate if someone could shred some light here. (1)
About the last line, it seems that from it I can determine that SF thinks it's 100% end game, because the eval is -2.26 which corresponds exactly to the EG eval showed at line

Code: Select all

  Total |   ---   --- |   ---   --- |  -2.31  -2.26 
, is this correct? (2)

But what does eval mean? It is not the evaluation returned when you type

Code: Select all

go movetime 10000
for instance. What does this number represent? (3)

Lastly, I would like to know whether the raw numbers in the table are used in stockfish's code and where (what file) just for fun. (4) Also, how are they calculated? For example is the value of the white knight calculated via the NPSQT? (5)

Thank you guys.
P.S.:I posted this question here as suggested there: http://support.stockfishchess.org/.
That gives the static evaluation of the position. No search or anything. Which is why it doesn't match the output from the "go" command.

What that next-to-last line says is that the score is based on 0.78% of the MG score, and 99.22% of the endgame score, if you look you can see it is a perfect match to that total EG column since so little of the MG score is factored in.

The last line is simply an interpolation between MG and EG scores based on material remaining. In this case, it is a simple endgame and is basically using just the EG score.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: 5 questions about the command "eval" in Stockf

Post by tpetzke »

Scaling: 0.78% MG, 99.22% * 100.00% EG.
The last number (here 100%) is a extra scaling factor to address things like opposite bishop endgames. Here it is 100% means no additional scaling.

Thomas...
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine
User avatar
mohzus
Posts: 106
Joined: Tue Sep 24, 2013 2:54 am

Re: 5 questions about the command "eval" in Stockf

Post by mohzus »

I see, thank you very much guys, that clears a lot of things for me.
I still wonder however how the values in the table are calculated.
For example the line

Code: Select all

             Knights | -0.04 -0.06 |  0.00  0.00 |  -0.04  -0.06 
, where do these values come from? I have just looked into the knight psqt and there are no such values. If that was taken out from the psqt, the values should have been -0.07 and 0.14 instead of -0.04 and -0.06, respectively.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: 5 questions about the command "eval" in Stockf

Post by tpetzke »

You have to look into the evaluation what terms are factored into that line. It is probably everything related to knights (outpost bonus and stuff) but PST, since PST are in a different line

Material, PST, Tempo | --- --- | --- --- | -3.23 -2.53

Thomas...
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine
AlvaroBegue
Posts: 932
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: 5 questions about the command "eval" in Stockf

Post by AlvaroBegue »

mohzus wrote:I see, thank you very much guys, that clears a lot of things for me.
I still wonder however how the values in the table are calculated.
For example the line

Code: Select all

             Knights | -0.04 -0.06 |  0.00  0.00 |  -0.04  -0.06 
, where do these values come from? I have just looked into the knight psqt and there are no such values. If that was taken out from the psqt, the values should have been -0.07 and 0.14 instead of -0.04 and -0.06, respectively.
This is my first time looking at the code in Stockfish, and it's pretty easy to follow. Towards the end of evaluate.cpp you can see the code that builds the table, and pulling the thread a bit you see it's getting the number from an array called `scores', which is filled with data in `evaluate_pieces'. The code there has much more than psqt (mobility, penalty for being behind a pawn...).

You can start up a debugger and see exactly where the number is coming from. That's probably a good exercise.