SF6 eval command output

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

SF6 eval command output

Post by Ferdy »

I am trying to understand the output of SF6 eval command for my game analyzer tool.
In mobility under Total, mg = -0.13, eg = +0.31, how can I get the interpolated value for this term alone?

[d]3r1rk1/1bq1bp2/p2ppn1p/1p3P2/4P1P1/6NP/PPPQ2B1/3R1R1K w - - 0 20

Code: Select all

position fen 3r1rk1/1bq1bp2/p2ppn1p/1p3P2/4P1P1/6NP/PPPQ2B1/3R1R1K w - - 0 20
eval
      Eval term |    White    |    Black    |    Total
                |   MG    EG  |   MG    EG  |   MG    EG
----------------+-------------+-------------+-------------
       Material |   ---   --- |   ---   --- | -2.63 -2.59
      Imbalance |   ---   --- |   ---   --- | -0.63 -0.63
          Pawns |   ---   --- |   ---   --- |  0.01  0.13
        Knights |  0.06  0.00 |  0.06  0.00 |  0.00  0.00
        Bishops | -0.19 -0.28 | -0.12 -0.28 | -0.06  0.00
          Rooks |  0.07  0.04 |  0.00  0.00 |  0.07  0.04
         Queens |  0.00  0.00 |  0.00  0.00 |  0.00  0.00
       Mobility |  0.40  1.38 |  0.53  1.08 | -0.13  0.31
    King safety |  0.18 -0.12 |  0.24 -0.06 | -0.06 -0.06
        Threats |  0.12  0.31 |  0.00  0.23 |  0.12  0.08
   Passed pawns |  0.00  0.00 |  0.00  0.00 |  0.00  0.00
          Space |  0.24  0.00 |  0.16  0.00 |  0.09  0.00
----------------+-------------+-------------+-------------
          Total |   ---   --- |   ---   --- | -3.21 -2.76

Total Evaluation: -3.09 (white side)
User avatar
Eelco de Groot
Posts: 4561
Joined: Sun Mar 12, 2006 2:40 am
Full name:   

Re: SF6 eval command output

Post by Eelco de Groot »

Hello Ferdinand,

I think you will need to modify Stockfish to give that information, because eval does not give you either the game phase

Code: Select all

ei.mi->game_phase()
or the scale factor, called

Code: Select all

sf
internally.

The interpolation is only done at the end of evaluate, for the sum of the eval values, starting in line 766 of evaluate.cpp

Code: Select all

    // Interpolate between a middlegame and a (scaled by 'sf') endgame score
    Value v =  mg_value(score) * int(ei.mi->game_phase())
             + eg_value(score) * int(PHASE_MIDGAME - ei.mi->game_phase()) * sf / SCALE_FACTOR_NORMAL;

    v /= int(PHASE_MIDGAME);
so you would have to change tracing, to either give those two terms sf and ei.mi->game_phase() or let it interpolate the traced terms as well as giving the not interpolated MG and EG values.

tracing is done right after the above lines 766-770 in evaluate()
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan
Haikouichthys
Posts: 38
Joined: Sun Oct 06, 2013 6:16 am

Re: SF6 eval command output

Post by Haikouichthys »

You could modify SF's source as Eelco recommends, or you could calculate it mathematically (easy to do, but will be quite time consuming if you intend to look at more than a couple of positions).
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: SF6 eval command output

Post by Ferdy »

Eelco de Groot wrote:Hello Ferdinand,

I think you will need to modify Stockfish to give that information, because eval does not give you either the game phase

Code: Select all

ei.mi->game_phase()
or the scale factor, called

Code: Select all

sf
internally.

The interpolation is only done at the end of evaluate, for the sum of the eval values, starting in line 766 of evaluate.cpp

Code: Select all

    // Interpolate between a middlegame and a (scaled by 'sf') endgame score
    Value v =  mg_value(score) * int(ei.mi->game_phase())
             + eg_value(score) * int(PHASE_MIDGAME - ei.mi->game_phase()) * sf / SCALE_FACTOR_NORMAL;

    v /= int(PHASE_MIDGAME);
so you would have to change tracing, to either give those two terms sf and ei.mi->game_phase() or let it interpolate the traced terms as well as giving the not interpolated MG and EG values.

tracing is done right after the above lines 766-770 in evaluate()
if this one

Code: Select all

ei.mi->game_phase()
is a function of material on the board, then I can calculate.
PHASE_MIDGAME and SCALE_FACTOR_NORMAL are probably constants.
So I am left with sf, how sf is calculated? If this is complicated perhaps just an estimate 25%, 50%, 75% or something?

What I plan is to add comment to a game in a move say 15. Nf5!
{White has superior piece mobility}
that is if white's neat mobility >= +0.50 pawn unit.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: SF6 eval command output

Post by Ferdy »

Haikouichthys wrote:You could modify SF's source as Eelco recommends, or you could calculate it mathematically (easy to do, but will be quite time consuming if you intend to look at more than a couple of positions).
I am not interested yet on modifying the source. No problem with calculation the script will do it, and I am actually looking at the fen most of the time, so I can get material details if needed.
Haikouichthys
Posts: 38
Joined: Sun Oct 06, 2013 6:16 am

Re: SF6 eval command output

Post by Haikouichthys »

Ferdy wrote:
Haikouichthys wrote:You could modify SF's source as Eelco recommends, or you could calculate it mathematically (easy to do, but will be quite time consuming if you intend to look at more than a couple of positions).
I am not interested yet on modifying the source. No problem with calculation the script will do it, and I am actually looking at the fen most of the time, so I can get material details if needed.
What I mean is that the game phase is deducible to a very high degree of accuracy from the MG total, the EG total and the interpolated total, and the interpolated mobility is deducible to a very high degree of accuracy from the MG mobility, the EG mobility and the game phase.
That is, letting the game phase be a decimal in the interval [0.0, 1.0] (SF actually uses an integer, but this is a good approximation),
total = totalMG * game_phase + totalEG * (1 - game_phase)
so
game_phase = (total - totalEG) / (totalMG - totalEG)

Then,
mobility = mobilityMG * game_phase + mobilityEG * (1 - game_phase)

EDIT: As pointed out by Eelco, I forgot the scaling factor. He mentions how to deduce that, though.
Last edited by Haikouichthys on Sun Jun 28, 2015 4:44 am, edited 1 time in total.
User avatar
Eelco de Groot
Posts: 4561
Joined: Sun Mar 12, 2006 2:40 am
Full name:   

Re: SF6 eval command output

Post by Eelco de Groot »

Hi Ferdinand,

If you don't want a modified Stockfish, is it not easiest to calculate the interpolation back from Total Evaluation (-3.09 in your example) and the MG and EG values for this value, -3.21 and -2.76. It will be a bit rounded but as far as I can see the final value is the computed value using the game_phase and the scaling factor sf. You can see in evalute() that, for instance, in the case of opposite colour bishops there is higher scale factor to make final eval closer to a draw. -3.21 X + -2.76 (1-X) = 3.09 should be easily solvable for X, or am I missing something here.
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: SF6 eval command output

Post by Ferdy »

Eelco de Groot wrote:Hi Ferdinand,

If you don't want a modified Stockfish, is it not easiest to calculate the interpolation back from Total Evaluation (-3.09 in your example) and the MG and EG values for this value, -3.21 and -2.76. It will be a bit rounded but as far as I can see the final value is the computed value using the game_phase and the scaling factor sf. You can see in evalute() that, for instance, in the case of opposite colour bishops there is higher scale factor to make final eval closer to a draw. -3.21 X + -2.76 (1-X) = 3.09 should be easily solvable for X, or am I missing something here.
I found the game_phase(), in the source, it is a function of non-pawn material piece_values. So we can get the sf based from the total score and just use that sf (in general) to calculate the net mobility. Thanks.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: SF6 eval command output

Post by Ferdy »

Haikouichthys wrote:
Ferdy wrote:
Haikouichthys wrote:You could modify SF's source as Eelco recommends, or you could calculate it mathematically (easy to do, but will be quite time consuming if you intend to look at more than a couple of positions).
I am not interested yet on modifying the source. No problem with calculation the script will do it, and I am actually looking at the fen most of the time, so I can get material details if needed.
What I mean is that the game phase is deducible to a very high degree of accuracy from the MG total, the EG total and the interpolated total, and the interpolated mobility is deducible to a very high degree of accuracy from the MG mobility, the EG mobility and the game phase.
That is, letting the game phase be a decimal in the interval [0.0, 1.0] (SF actually uses an integer, but this is a good approximation),
total = totalMG * game_phase + totalEG * (1 - game_phase)
so
game_phase = (total - totalEG) / (totalMG - totalEG)

Then,
mobility = mobilityMG * game_phase + mobilityEG * (1 - game_phase)

EDIT: As pointed out by Eelco, I forgot the scaling factor. He mentions how to deduce that, though.
That is indeed a good idea to get the game phase, except that we still have sf. I check the source and I find the game_phase(), so I will just calculate the sf and use it in general to get specific net values of terms. I am only after the estimated net value. Thanks.