Skip to content

Commit

Permalink
HalfKAv2_hm-1024x2-8-32-1. nn-exp135-run7-epoch519.nnue
Browse files Browse the repository at this point in the history
bench: 5189338
  • Loading branch information
Sopel97 committed Aug 9, 2021
1 parent dabaf22 commit 7dc7a9a
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ endif
SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp \
material.cpp misc.cpp movegen.cpp movepick.cpp pawns.cpp position.cpp psqt.cpp \
search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp \
nnue/evaluate_nnue.cpp nnue/features/half_ka_v2.cpp
nnue/evaluate_nnue.cpp nnue/features/half_ka_v2_hm.cpp

OBJS = $(notdir $(SRCS:.cpp=.o))

Expand Down
2 changes: 1 addition & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Eval {
// The default net name MUST follow the format nn-[SHA256 first 12 digits].nnue
// for the build process (profile-build and fishtest) to work. Do not change the
// name of the macro, as it is used in the Makefile.
#define EvalFileDefaultName "nn-46832cfbead3.nnue"
#define EvalFileDefaultName "nn-e8321e467bf6.nnue"

namespace NNUE {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,32 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//Definition of input features HalfKAv2 of NNUE evaluation function
//Definition of input features HalfKAv2_hm of NNUE evaluation function

#include "half_ka_v2.h"
#include "half_ka_v2_hm.h"

#include "../../position.h"

namespace Stockfish::Eval::NNUE::Features {

// Orient a square according to perspective (rotates by 180 for black)
inline Square HalfKAv2::orient(Color perspective, Square s) {
return Square(int(s) ^ (bool(perspective) * 56));
inline Square HalfKAv2_hm::orient(Color perspective, Square s, Square ksq) {
return Square(int(s) ^ (bool(perspective) * SQ_A8) ^ ((file_of(ksq) < FILE_E) * SQ_H1));
}

// Index of a feature for a given king position and another piece on some square
inline IndexType HalfKAv2::make_index(Color perspective, Square s, Piece pc, Square ksq) {
return IndexType(orient(perspective, s) + PieceSquareIndex[perspective][pc] + PS_NB * ksq);
inline IndexType HalfKAv2_hm::make_index(Color perspective, Square s, Piece pc, Square ksq) {
Square o_ksq = orient(perspective, ksq, ksq);
return IndexType(orient(perspective, s, ksq) + PieceSquareIndex[perspective][pc] + PS_NB * KingBuckets[o_ksq]);
}

// Get a list of indices for active features
void HalfKAv2::append_active_indices(
void HalfKAv2_hm::append_active_indices(
const Position& pos,
Color perspective,
ValueListInserter<IndexType> active
) {
Square ksq = orient(perspective, pos.square<KING>(perspective));
Square ksq = pos.square<KING>(perspective);
Bitboard bb = pos.pieces();
while (bb)
{
Expand All @@ -52,33 +53,32 @@ namespace Stockfish::Eval::NNUE::Features {

// append_changed_indices() : get a list of indices for recently changed features

void HalfKAv2::append_changed_indices(
void HalfKAv2_hm::append_changed_indices(
Square ksq,
StateInfo* st,
Color perspective,
ValueListInserter<IndexType> removed,
ValueListInserter<IndexType> added
) {
const auto& dp = st->dirtyPiece;
Square oriented_ksq = orient(perspective, ksq);
for (int i = 0; i < dp.dirty_num; ++i) {
Piece pc = dp.piece[i];
if (dp.from[i] != SQ_NONE)
removed.push_back(make_index(perspective, dp.from[i], pc, oriented_ksq));
removed.push_back(make_index(perspective, dp.from[i], pc, ksq));
if (dp.to[i] != SQ_NONE)
added.push_back(make_index(perspective, dp.to[i], pc, oriented_ksq));
added.push_back(make_index(perspective, dp.to[i], pc, ksq));
}
}

int HalfKAv2::update_cost(StateInfo* st) {
int HalfKAv2_hm::update_cost(StateInfo* st) {
return st->dirtyPiece.dirty_num;
}

int HalfKAv2::refresh_cost(const Position& pos) {
int HalfKAv2_hm::refresh_cost(const Position& pos) {
return pos.count<ALL_PIECES>();
}

bool HalfKAv2::requires_refresh(StateInfo* st, Color perspective) {
bool HalfKAv2_hm::requires_refresh(StateInfo* st, Color perspective) {
return st->dirtyPiece.piece[0] == make_piece(perspective, KING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

//Definition of input features HalfKP of NNUE evaluation function

#ifndef NNUE_FEATURES_HALF_KA_V2_H_INCLUDED
#define NNUE_FEATURES_HALF_KA_V2_H_INCLUDED
#ifndef NNUE_FEATURES_HALF_KA_V2_HM_H_INCLUDED
#define NNUE_FEATURES_HALF_KA_V2_HM_H_INCLUDED

#include "../nnue_common.h"

Expand All @@ -32,9 +32,9 @@ namespace Stockfish {

namespace Stockfish::Eval::NNUE::Features {

// Feature HalfKAv2: Combination of the position of own king
// and the position of pieces
class HalfKAv2 {
// Feature HalfKAv2_hm: Combination of the position of own king
// and the position of pieces. Position mirrored such that king always on e..h files.
class HalfKAv2_hm {

// unique number for each piece type on each square
enum {
Expand Down Expand Up @@ -63,21 +63,32 @@ namespace Stockfish::Eval::NNUE::Features {
};

// Orient a square according to perspective (rotates by 180 for black)
static Square orient(Color perspective, Square s);
static Square orient(Color perspective, Square s, Square ksq);

// Index of a feature for a given king position and another piece on some square
static IndexType make_index(Color perspective, Square s, Piece pc, Square ksq);

public:
// Feature name
static constexpr const char* Name = "HalfKAv2(Friend)";
static constexpr const char* Name = "HalfKAv2_hm(Friend)";

// Hash value embedded in the evaluation file
static constexpr std::uint32_t HashValue = 0x5f234cb8u;
static constexpr std::uint32_t HashValue = 0x7f234cb8u;

// Number of feature dimensions
static constexpr IndexType Dimensions =
static_cast<IndexType>(SQUARE_NB) * static_cast<IndexType>(PS_NB);
static_cast<IndexType>(SQUARE_NB) * static_cast<IndexType>(PS_NB) / 2;

static constexpr int KingBuckets[64] = {
-1, -1, -1, -1, 31, 30, 29, 28,
-1, -1, -1, -1, 27, 26, 25, 24,
-1, -1, -1, -1, 23, 22, 21, 20,
-1, -1, -1, -1, 19, 18, 17, 16,
-1, -1, -1, -1, 15, 14, 13, 12,
-1, -1, -1, -1, 11, 10, 9, 8,
-1, -1, -1, -1, 7, 6, 5, 4,
-1, -1, -1, -1, 3, 2, 1, 0
};

// Maximum number of simultaneously active features.
static constexpr IndexType MaxActiveDimensions = 32;
Expand Down Expand Up @@ -108,4 +119,4 @@ namespace Stockfish::Eval::NNUE::Features {

} // namespace Stockfish::Eval::NNUE::Features

#endif // #ifndef NNUE_FEATURES_HALF_KA_V2_H_INCLUDED
#endif // #ifndef NNUE_FEATURES_HALF_KA_V2_HM_H_INCLUDED

0 comments on commit 7dc7a9a

Please sign in to comment.