io-chess
UCI chess engine
Loading...
Searching...
No Matches
ExpertRouter Class Reference

#include <ExpertRouter.hpp>

Classes

struct  ExpertWeights

Public Types

enum  Expert : int {
  TACTICAL = 0 , STRATEGIC = 1 , MAJOR_END = 2 , MINOR_END = 3 ,
  SURVIVOR = 4 , KILLER = 5
}

Static Public Member Functions

static void compute_weights (const ChessInput &input, float eval_cp, ExpertWeights &out)
static void compute_weights (const FactorizedInput &input, float eval_cp, ExpertWeights &out)
static void get_top_k (const ExpertWeights &weights, int k, int *indices, float *probs)

Static Public Attributes

static constexpr int NUM_EXPERTS = 6
static constexpr int NUM_BASE = 4
static constexpr int NUM_AUX = 2
static constexpr float PHASE_ENDGAME_THRESHOLD = 0.65f
static constexpr float CCT_TACTICAL_THRESHOLD = 14.0f
static constexpr float CCT_STRATEGIC_THRESHOLD = 6.0f
static constexpr float KILLER_CP_THRESHOLD
static constexpr float SURVIVOR_CP_THRESHOLD
static constexpr float AUX_RAMP_RANGE = 500.0f
static constexpr float CCT_WEIGHT_CHECK = 10.0f
static constexpr float CCT_WEIGHT_MAJOR_THREAT = 3.0f
static constexpr float PIECE_VALUE_PAWN = 1.0f
static constexpr float PIECE_VALUE_KNIGHT = 3.0f
static constexpr float PIECE_VALUE_BISHOP = 3.0f
static constexpr float PIECE_VALUE_ROOK = 5.0f
static constexpr float PIECE_VALUE_QUEEN = 9.0f
static constexpr float SCORE_MAX = 5.0f
static constexpr float SCORE_MIN = 0.5f

Static Private Member Functions

static float compute_phase (const ChessInput &input)
static float compute_phase (const FactorizedInput &input)
static float compute_cct (const ChessInput &input)
static bool has_overlap_factorized (const FactorizedInput &input, int attacker_group_begin, int attacker_group_end, int target_presence_group)
static float compute_cct (const FactorizedInput &input)
static bool has_major_pieces (const ChessInput &input)
static float compute_major_ratio (const ChessInput &input)
static float compute_major_ratio (const FactorizedInput &input)
static float compute_material_imbalance (const ChessInput &input)
static int count_layer (const uint8_t layer[64])
static bool has_overlap (const uint8_t a[64], const uint8_t b[64])
static float piece_threat_value (const ChessInput &input, int threat_layer, int piece_layer, float piece_value)
static float fast_exp (float x)
static float sigmoid (float x)
static void softmax (const float *scores, float *probs, int n)

Detailed Description

ExpertRouter - Computes expert weights for Residual MoE architecture

RESIDUAL ARCHITECTURE: Base Experts (0-3): Softmax group, sum to 1.0 - provides foundation Aux Experts (4-5): Independent gates (0-1) - provides residual bonus

6 Experts: BASE GROUP (Softmax): 0: TACTICAL - High CCT middlegame positions 1: STRATEGIC - Low CCT middlegame positions 2: MAJOR_END - Endgame with rooks/queens 3: MINOR_END - Endgame without major pieces AUX GROUP (Independent gates): 4: SURVIVOR - Resistance bonus when losing 5: KILLER - Progress bonus when winning

Member Enumeration Documentation

◆ Expert

Enumerator
TACTICAL 
STRATEGIC 
MAJOR_END 
MINOR_END 
SURVIVOR 
KILLER 

Member Function Documentation

◆ compute_cct() [1/2]

float ExpertRouter::compute_cct ( const ChessInput & input)
inlinestaticprivate

Compute CCT (Checks, Captures, Threats) score. Higher = more tactical.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_cct() [2/2]

float ExpertRouter::compute_cct ( const FactorizedInput & input)
inlinestaticprivate
Here is the call graph for this function:

◆ compute_major_ratio() [1/2]

float ExpertRouter::compute_major_ratio ( const ChessInput & input)
inlinestaticprivate

Compute major piece ratio for endgame blending.

Returns 0.0 for pure minor endgame (no rooks/queens) Returns 1.0 for major-heavy endgame (lots of rooks/queens) Intermediate values for mixed endgames

Formula: major_material / (major_material + minor_material)

Here is the caller graph for this function:

◆ compute_major_ratio() [2/2]

float ExpertRouter::compute_major_ratio ( const FactorizedInput & input)
inlinestaticprivate

◆ compute_material_imbalance()

float ExpertRouter::compute_material_imbalance ( const ChessInput & input)
inlinestaticprivate

Compute material imbalance between sides (in pawn units)

◆ compute_phase() [1/2]

float ExpertRouter::compute_phase ( const ChessInput & input)
inlinestaticprivate

Get pre-computed Game Phase from FeatureExtractor globals. 0.0 = Opening, 1.0 = Deep Endgame. (Computed in FeatureExtractor using Material * Mobility formula)

Here is the caller graph for this function:

◆ compute_phase() [2/2]

float ExpertRouter::compute_phase ( const FactorizedInput & input)
inlinestaticprivate

◆ compute_weights() [1/2]

void ExpertRouter::compute_weights ( const ChessInput & input,
float eval_cp,
ExpertWeights & out )
inlinestatic

Compute expert weights using Residual MoE architecture.

Output format (6 floats): [0-3]: Base experts (TACTICAL, STRATEGIC, MAJOR_END, MINOR_END) - softmax, sum=1 [4]: SURVIVOR gate - independent 0-1 (active when losing) [5]: KILLER gate - independent 0-1 (active when winning)

Parameters
inputThe ChessInput features
eval_cpEvaluation in centipawns (positive = side to move winning)
outOutput weights structure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_weights() [2/2]

void ExpertRouter::compute_weights ( const FactorizedInput & input,
float eval_cp,
ExpertWeights & out )
inlinestatic

Compute expert weights directly from factorized features. This avoids extracting ChessInput when factorized preprocessing is selected.

Here is the call graph for this function:

◆ count_layer()

int ExpertRouter::count_layer ( const uint8_t layer[64])
inlinestaticprivate

Count number of set squares in a layer (value > 0) Optimized using 64-bit strides.

Here is the caller graph for this function:

◆ fast_exp()

float ExpertRouter::fast_exp ( float x)
inlinestaticprivate

Fast approximation of exp(x). Range: Valid for inputs approx -87 to +87. Speed: ~10x faster than std::exp.

Here is the caller graph for this function:

◆ get_top_k()

void ExpertRouter::get_top_k ( const ExpertWeights & weights,
int k,
int * indices,
float * probs )
inlinestatic

Get top-k expert indices and their weights.

Parameters
weightsThe computed expert weights
kNumber of experts to select (typically 2)
indicesOutput array of expert indices (sorted by weight, descending)
probsOutput array of normalized probabilities for selected experts

◆ has_major_pieces()

bool ExpertRouter::has_major_pieces ( const ChessInput & input)
inlinestaticprivate

Check if position has major pieces (rooks or queens)

◆ has_overlap()

bool ExpertRouter::has_overlap ( const uint8_t a[64],
const uint8_t b[64] )
inlinestaticprivate

Check if two layers have any overlap (both non-zero at same square) Optimized using 64-bit strides.

Here is the caller graph for this function:

◆ has_overlap_factorized()

bool ExpertRouter::has_overlap_factorized ( const FactorizedInput & input,
int attacker_group_begin,
int attacker_group_end,
int target_presence_group )
inlinestaticprivate
Here is the caller graph for this function:

◆ piece_threat_value()

float ExpertRouter::piece_threat_value ( const ChessInput & input,
int threat_layer,
int piece_layer,
float piece_value )
inlinestaticprivate

Get threat value for pieces of a specific type

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigmoid()

float ExpertRouter::sigmoid ( float x)
inlinestaticprivate

Fast sigmoid approximation using fast_exp. sigmoid(x) = 1 / (1 + exp(-x)) Range: 0.0 to 1.0 (centered at 0.0)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ softmax()

void ExpertRouter::softmax ( const float * scores,
float * probs,
int n )
inlinestaticprivate

Optimized Softmax with Safety Fallback. If numerical instability occurs, defaults to TACTICAL/STRATEGIC split.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ AUX_RAMP_RANGE

float ExpertRouter::AUX_RAMP_RANGE = 500.0f
staticconstexpr

◆ CCT_STRATEGIC_THRESHOLD

float ExpertRouter::CCT_STRATEGIC_THRESHOLD = 6.0f
staticconstexpr

◆ CCT_TACTICAL_THRESHOLD

float ExpertRouter::CCT_TACTICAL_THRESHOLD = 14.0f
staticconstexpr

◆ CCT_WEIGHT_CHECK

float ExpertRouter::CCT_WEIGHT_CHECK = 10.0f
staticconstexpr

◆ CCT_WEIGHT_MAJOR_THREAT

float ExpertRouter::CCT_WEIGHT_MAJOR_THREAT = 3.0f
staticconstexpr

◆ KILLER_CP_THRESHOLD

float ExpertRouter::KILLER_CP_THRESHOLD
staticconstexpr
Initial value:
=
150.0f

◆ NUM_AUX

int ExpertRouter::NUM_AUX = 2
staticconstexpr

◆ NUM_BASE

int ExpertRouter::NUM_BASE = 4
staticconstexpr

◆ NUM_EXPERTS

int ExpertRouter::NUM_EXPERTS = 6
staticconstexpr

◆ PHASE_ENDGAME_THRESHOLD

float ExpertRouter::PHASE_ENDGAME_THRESHOLD = 0.65f
staticconstexpr

◆ PIECE_VALUE_BISHOP

float ExpertRouter::PIECE_VALUE_BISHOP = 3.0f
staticconstexpr

◆ PIECE_VALUE_KNIGHT

float ExpertRouter::PIECE_VALUE_KNIGHT = 3.0f
staticconstexpr

◆ PIECE_VALUE_PAWN

float ExpertRouter::PIECE_VALUE_PAWN = 1.0f
staticconstexpr

◆ PIECE_VALUE_QUEEN

float ExpertRouter::PIECE_VALUE_QUEEN = 9.0f
staticconstexpr

◆ PIECE_VALUE_ROOK

float ExpertRouter::PIECE_VALUE_ROOK = 5.0f
staticconstexpr

◆ SCORE_MAX

float ExpertRouter::SCORE_MAX = 5.0f
staticconstexpr

◆ SCORE_MIN

float ExpertRouter::SCORE_MIN = 0.5f
staticconstexpr

◆ SURVIVOR_CP_THRESHOLD

float ExpertRouter::SURVIVOR_CP_THRESHOLD
staticconstexpr
Initial value:
=
150.0f

The documentation for this class was generated from the following file: