1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 17:19:36 +00:00

Added enpassant feature. Added k-p-cr-ep_256x2-32-32 architecture.

This commit is contained in:
Hisayori Noda 2019-07-07 19:24:46 +09:00
parent 92052bc16b
commit df827ea7ee
5 changed files with 136 additions and 1 deletions

View file

@ -47,6 +47,7 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
eval/nnue/features/k.o \
eval/nnue/features/p.o \
eval/nnue/features/castling_right.o \
eval/nnue/features/enpassant.o \
eval/nnue/nnue_test_command.o \
extra/sfen_packer.o \
learn/gensfen2019.o \

View file

@ -0,0 +1,38 @@
// NNUE評価関数で用いる入力特徴量とネットワーク構造の定義
#include "../features/feature_set.h"
#include "../features/k.h"
#include "../features/p.h"
#include "../features/castling_right.h"
#include "../features/enpassant.h"
#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/clipped_relu.h"
namespace Eval {
namespace NNUE {
// 評価関数で用いる入力特徴量
using RawFeatures = Features::FeatureSet<Features::K, Features::P,
Features::CastlingRight, Features::EnPassant>;
// 変換後の入力特徴量の次元数
constexpr IndexType kTransformedFeatureDimensions = 256;
namespace Layers {
// ネットワーク構造の定義
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

View file

@ -0,0 +1,47 @@
// NNUE評価関数の入力特徴量Kの定義
#if defined(EVAL_NNUE)
#include "enpassant.h"
#include "index_list.h"
namespace Eval {
namespace NNUE {
namespace Features {
// 特徴量のうち、値が1であるインデックスのリストを取得する
void EnPassant::AppendActiveIndices(
const Position& pos, Color perspective, IndexList* active) {
// コンパイラの警告を回避するため、配列サイズが小さい場合は何もしない
if (RawFeatures::kMaxActiveDimensions < kMaxActiveDimensions) return;
auto epSquare = pos.state()->epSquare;
if (epSquare == SQ_NONE) {
return;
}
if (perspective == BLACK) {
epSquare = Inv(epSquare);
}
auto file = file_of(epSquare);
active->push_back(file);
}
// 特徴量のうち、一手前から値が変化したインデックスのリストを取得する
void EnPassant::AppendChangedIndices(
const Position& pos, Color perspective,
IndexList* removed, IndexList* added) {
// Not implemented.
assert(false);
}
} // namespace Features
} // namespace NNUE
} // namespace Eval
#endif // defined(EVAL_NNUE)

View file

@ -0,0 +1,48 @@
// NNUE評価関数の入力特徴量Kの定義
#ifndef _NNUE_FEATURES_ENPASSANT_H_
#define _NNUE_FEATURES_ENPASSANT_H_
#if defined(EVAL_NNUE)
#include "../../../evaluate.h"
#include "features_common.h"
namespace Eval {
namespace NNUE {
namespace Features {
// 特徴量K玉の位置
class EnPassant {
public:
// 特徴量名
static constexpr const char* kName = "EnPassant";
// 評価関数ファイルに埋め込むハッシュ値
static constexpr std::uint32_t kHashValue = 0x02924F91u;
// 特徴量の次元数
static constexpr IndexType kDimensions = 8;
// 特徴量のうち、同時に値が1となるインデックスの数の最大値
static constexpr IndexType kMaxActiveDimensions = 1;
// 差分計算の代わりに全計算を行うタイミング
static constexpr TriggerEvent kRefreshTrigger = TriggerEvent::kAnyPieceMoved;
// 特徴量のうち、値が1であるインデックスのリストを取得する
static void AppendActiveIndices(const Position& pos, Color perspective,
IndexList* active);
// 特徴量のうち、一手前から値が変化したインデックスのリストを取得する
static void AppendChangedIndices(const Position& pos, Color perspective,
IndexList* removed, IndexList* added);
};
} // namespace Features
} // namespace NNUE
} // namespace Eval
#endif // defined(EVAL_NNUE)
#endif

View file

@ -7,7 +7,8 @@
// 入力特徴量とネットワーク構造が定義されたヘッダをincludeする
//#include "architectures/k-p_256x2-32-32.h"
#include "architectures/k-p-cr_256x2-32-32.h"
//#include "architectures/k-p-cr_256x2-32-32.h"
#include "architectures/k-p-cr-ep_256x2-32-32.h"
//#include "architectures/halfkp_256x2-32-32.h"
namespace Eval {