feat: enhance training and evaluation processes with new parameters and normalization options
This commit is contained in:
@@ -19,6 +19,7 @@ Try to stick to these commands for consistency.
|
|||||||
| `api` | Model / shared types | (none) |
|
| `api` | Model / shared types | (none) |
|
||||||
| `core` | Primary business logic | api, rule |
|
| `core` | Primary business logic | api, rule |
|
||||||
| `rule` | Game rules | api |
|
| `rule` | Game rules | api |
|
||||||
|
| `bot` | Bots and AI | api,rule,io |
|
||||||
| `io` | Export formats | api, core |
|
| `io` | Export formats | api, core |
|
||||||
| `ui` | Entrypoint & UI | core, io |
|
| `ui` | Entrypoint & UI | core, io |
|
||||||
|
|
||||||
|
|||||||
@@ -133,8 +133,15 @@ class NNUE:
|
|||||||
for j <- 0 until 32 do
|
for j <- 0 until 32 do
|
||||||
output += l2Output(j) * l3Weights(j)
|
output += l2Output(j) * l3Weights(j)
|
||||||
|
|
||||||
// Convert from sigmoid(output) back to centipawns (output is trained as sigmoid(eval/400))
|
// Convert from tanh-normalized output back to centipawns
|
||||||
// Inverse sigmoid: eval/400 = ln(output / (1 - output))
|
// Training uses: eval_normalized = tanh(eval_cp / 300)
|
||||||
// But for simplicity, just scale directly: output ≈ sigmoid(eval/400), so eval ≈ 400 * (output - 0.5) * 2
|
// Inverse: eval_cp = 300 * atanh(output)
|
||||||
val cp = (output * 400f).toInt
|
// atanh(x) = 0.5 * ln((1 + x) / (1 - x))
|
||||||
|
val cp = if math.abs(output) >= 0.9999f then
|
||||||
|
// Clamp for numerical stability (avoid ln of very small numbers)
|
||||||
|
if output > 0f then 20000 else -20000
|
||||||
|
else
|
||||||
|
val atanh = 0.5f * math.log((1f + output) / (1f - output)).toFloat
|
||||||
|
(300f * atanh).toInt
|
||||||
|
|
||||||
math.max(-20000, math.min(20000, cp))
|
math.max(-20000, math.min(20000, cp))
|
||||||
|
|||||||
Reference in New Issue
Block a user