mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-24 02:57:11 +08:00
Added the castling right feature. Added k-p-cr_256x2-32-32 architecture.
This commit is contained in:
37
src/eval/nnue/architectures/k-p-cr_256x2-32-32.h
Normal file
37
src/eval/nnue/architectures/k-p-cr_256x2-32-32.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// NNUE<55>]<5D><><EFBFBD><EFBFBD><D690>ŗp<C597><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͓<EFBFBD><CD93><EFBFBD><EFBFBD>ʂƃl<C683>b<EFBFBD>g<EFBFBD><67><EFBFBD>[<5B>N<EFBFBD>\<5C><><EFBFBD>̒<EFBFBD><CC92>`
|
||||
|
||||
#include "../features/feature_set.h"
|
||||
#include "../features/k.h"
|
||||
#include "../features/p.h"
|
||||
#include "../features/castling_right.h"
|
||||
|
||||
#include "../layers/input_slice.h"
|
||||
#include "../layers/affine_transform.h"
|
||||
#include "../layers/clipped_relu.h"
|
||||
|
||||
namespace Eval {
|
||||
|
||||
namespace NNUE {
|
||||
|
||||
// <20>]<5D><><EFBFBD><EFBFBD><D690>ŗp<C597><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͓<EFBFBD><CD93><EFBFBD><EFBFBD><EFBFBD>
|
||||
using RawFeatures = Features::FeatureSet<Features::K, Features::P,
|
||||
Features::CastlingRight>;
|
||||
|
||||
// <20>ϊ<EFBFBD><CF8A><EFBFBD><EFBFBD>̓<EFBFBD><CC93>͓<EFBFBD><CD93><EFBFBD><EFBFBD>ʂ̎<CA82><CC8E><EFBFBD><EFBFBD><EFBFBD>
|
||||
constexpr IndexType kTransformedFeatureDimensions = 256;
|
||||
|
||||
namespace Layers {
|
||||
|
||||
// <20>l<EFBFBD>b<EFBFBD>g<EFBFBD><67><EFBFBD>[<5B>N<EFBFBD>\<5C><><EFBFBD>̒<EFBFBD><CC92>`
|
||||
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
|
||||
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 32>>;
|
||||
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
|
||||
using OutputLayer = AffineTransform<HiddenLayer2, 1>;
|
||||
|
||||
} // namespace Layers
|
||||
|
||||
using Network = Layers::OutputLayer;
|
||||
|
||||
} // namespace NNUE
|
||||
|
||||
} // namespace Eval
|
||||
73
src/eval/nnue/features/castling_right.cpp
Normal file
73
src/eval/nnue/features/castling_right.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// NNUE評価関数の入力特徴量Kの定義
|
||||
|
||||
#if defined(EVAL_NNUE)
|
||||
|
||||
#include "castling_right.h"
|
||||
#include "index_list.h"
|
||||
|
||||
namespace Eval {
|
||||
|
||||
namespace NNUE {
|
||||
|
||||
namespace Features {
|
||||
|
||||
// 特徴量のうち、値が1であるインデックスのリストを取得する
|
||||
void CastlingRight::AppendActiveIndices(
|
||||
const Position& pos, Color perspective, IndexList* active) {
|
||||
// コンパイラの警告を回避するため、配列サイズが小さい場合は何もしない
|
||||
if (RawFeatures::kMaxActiveDimensions < kMaxActiveDimensions) return;
|
||||
|
||||
int castling_rights = pos.state()->castlingRights;
|
||||
int relative_castling_rights;
|
||||
if (perspective == WHITE) {
|
||||
relative_castling_rights = castling_rights;
|
||||
}
|
||||
else {
|
||||
// Invert the perspective.
|
||||
relative_castling_rights = ((castling_rights & 3) << 2)
|
||||
& ((castling_rights >> 2) & 3);
|
||||
}
|
||||
|
||||
for (int i = 0; i < kDimensions; ++i) {
|
||||
if (relative_castling_rights & (i << 1)) {
|
||||
active->push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 特徴量のうち、一手前から値が変化したインデックスのリストを取得する
|
||||
void CastlingRight::AppendChangedIndices(
|
||||
const Position& pos, Color perspective,
|
||||
IndexList* removed, IndexList* added) {
|
||||
|
||||
int previous_castling_rights = pos.state()->previous->castlingRights;
|
||||
int current_castling_rights = pos.state()->castlingRights;
|
||||
int relative_previous_castling_rights;
|
||||
int relative_current_castling_rights;
|
||||
if (perspective == WHITE) {
|
||||
relative_previous_castling_rights = previous_castling_rights;
|
||||
relative_current_castling_rights = current_castling_rights;
|
||||
}
|
||||
else {
|
||||
// Invert the perspective.
|
||||
relative_previous_castling_rights = ((previous_castling_rights & 3) << 2)
|
||||
& ((previous_castling_rights >> 2) & 3);
|
||||
relative_current_castling_rights = ((current_castling_rights & 3) << 2)
|
||||
& ((current_castling_rights >> 2) & 3);
|
||||
}
|
||||
|
||||
for (int i = 0; i < kDimensions; ++i) {
|
||||
if ((relative_previous_castling_rights & (i << 1)) &&
|
||||
(relative_current_castling_rights & (i << 1)) == 0) {
|
||||
removed->push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Features
|
||||
|
||||
} // namespace NNUE
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_NNUE)
|
||||
48
src/eval/nnue/features/castling_right.h
Normal file
48
src/eval/nnue/features/castling_right.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// NNUE<55>]<5D><><EFBFBD><EFBFBD><D690>̓<EFBFBD><CC93>͓<EFBFBD><CD93><EFBFBD><EFBFBD><EFBFBD>K<EFBFBD>̒<EFBFBD><CC92>`
|
||||
|
||||
#ifndef _NNUE_FEATURES_CASTLING_RIGHT_H_
|
||||
#define _NNUE_FEATURES_CASTLING_RIGHT_H_
|
||||
|
||||
#if defined(EVAL_NNUE)
|
||||
|
||||
#include "../../../evaluate.h"
|
||||
#include "features_common.h"
|
||||
|
||||
namespace Eval {
|
||||
|
||||
namespace NNUE {
|
||||
|
||||
namespace Features {
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>K<EFBFBD>F<EFBFBD>ʂ̈ʒu
|
||||
class CastlingRight {
|
||||
public:
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʖ<EFBFBD>
|
||||
static constexpr const char* kName = "CastlingRight";
|
||||
// <20>]<5D><><EFBFBD><EFBFBD><D690>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD>ɖ<EFBFBD><C996>ߍ<EFBFBD><DF8D>ރn<DE83>b<EFBFBD>V<EFBFBD><56><EFBFBD>l
|
||||
static constexpr std::uint32_t kHashValue = 0x913968AAu;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʂ̎<CA82><CC8E><EFBFBD><EFBFBD><EFBFBD>
|
||||
static constexpr IndexType kDimensions = 4;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʂ̂<CA82><CC82><EFBFBD><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>ɒl<C992><6C>1<EFBFBD>ƂȂ<C682><C882>C<EFBFBD><43><EFBFBD>f<EFBFBD>b<EFBFBD>N<EFBFBD>X<EFBFBD>̐<EFBFBD><CC90>̍ő<CC8D><C591>l
|
||||
static constexpr IndexType kMaxActiveDimensions = 4;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>v<EFBFBD>Z<EFBFBD>̑<EFBFBD><CC91><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɑS<C991>v<EFBFBD>Z<EFBFBD><5A><EFBFBD>s<EFBFBD><73><EFBFBD>^<5E>C<EFBFBD>~<7E><><EFBFBD>O
|
||||
static constexpr TriggerEvent kRefreshTrigger = TriggerEvent::kNone;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʂ̂<CA82><CC82><EFBFBD><EFBFBD>A<EFBFBD>l<EFBFBD><6C>1<EFBFBD>ł<EFBFBD><C582><EFBFBD><EFBFBD>C<EFBFBD><43><EFBFBD>f<EFBFBD>b<EFBFBD>N<EFBFBD>X<EFBFBD>̃<EFBFBD><CC83>X<EFBFBD>g<EFBFBD><67><EFBFBD>擾<EFBFBD><E693BE><EFBFBD><EFBFBD>
|
||||
static void AppendActiveIndices(const Position& pos, Color perspective,
|
||||
IndexList* active);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ʂ̂<CA82><CC82><EFBFBD><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD>l<EFBFBD><6C><EFBFBD>ω<EFBFBD><CF89><EFBFBD><EFBFBD><EFBFBD><EFBFBD>C<EFBFBD><43><EFBFBD>f<EFBFBD>b<EFBFBD>N<EFBFBD>X<EFBFBD>̃<EFBFBD><CC83>X<EFBFBD>g<EFBFBD><67><EFBFBD>擾<EFBFBD><E693BE><EFBFBD><EFBFBD>
|
||||
static void AppendChangedIndices(const Position& pos, Color perspective,
|
||||
IndexList* removed, IndexList* added);
|
||||
};
|
||||
|
||||
} // namespace Features
|
||||
|
||||
} // namespace NNUE
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_NNUE)
|
||||
|
||||
#endif
|
||||
@@ -6,16 +6,9 @@
|
||||
#if defined(EVAL_NNUE)
|
||||
|
||||
// 入力特徴量とネットワーク構造が定義されたヘッダをincludeする
|
||||
|
||||
// KP256型を使いたいときは、これを事前にdefineする。
|
||||
#define EVAL_NNUE_KP256
|
||||
#if defined(EVAL_NNUE_KP256)
|
||||
#include "architectures/k-p_256x2-32-32.h"
|
||||
#else // #if defined(EVAL_NNUE_HALFKP256)
|
||||
|
||||
// NNUE評価関数のデフォルトは、halfKP256
|
||||
#include "architectures/halfkp_256x2-32-32.h"
|
||||
#endif
|
||||
//#include "architectures/k-p_256x2-32-32.h"
|
||||
#include "architectures/k-p-cr_256x2-32-32.h"
|
||||
//#include "architectures/halfkp_256x2-32-32.h"
|
||||
|
||||
namespace Eval {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user