|
io-chess
UCI chess engine
|
#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) |
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
| enum ExpertRouter::Expert : int |
|
inlinestaticprivate |
Compute CCT (Checks, Captures, Threats) score. Higher = more tactical.


|
inlinestaticprivate |

|
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)

|
inlinestaticprivate |
|
inlinestaticprivate |
Compute material imbalance between sides (in pawn units)
|
inlinestaticprivate |
Get pre-computed Game Phase from FeatureExtractor globals. 0.0 = Opening, 1.0 = Deep Endgame. (Computed in FeatureExtractor using Material * Mobility formula)

|
inlinestaticprivate |
|
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)
| input | The ChessInput features |
| eval_cp | Evaluation in centipawns (positive = side to move winning) |
| out | Output weights structure |


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

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

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

|
inlinestatic |
Get top-k expert indices and their weights.
| weights | The computed expert weights |
| k | Number of experts to select (typically 2) |
| indices | Output array of expert indices (sorted by weight, descending) |
| probs | Output array of normalized probabilities for selected experts |
|
inlinestaticprivate |
Check if position has major pieces (rooks or queens)
|
inlinestaticprivate |
Check if two layers have any overlap (both non-zero at same square) Optimized using 64-bit strides.

|
inlinestaticprivate |

|
inlinestaticprivate |
Get threat value for pieces of a specific type


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


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


|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |