/* SPDX-License-Identifier: LicenseRef-Starship-1.0 * Copyright (c) 2023-2026 Robert A. James */ /* inference.h -- the inference engine (Loops #5 and #6), for a node's heartbeat (v4/mesh.h): #189 Phase 7, * Task 3 (Captain Bob, 2026-11-13: "Rewrite for v4"). v3's inference_engine.c, in its own Q48.16 arithmetic, * to the bit: what it computes from a heat trajectory -- the variance, the window width where the variance * stops changing (Levene), the decay slope (a log-linear regression) -- and the run that applies them, with its * early exit when the variance has moved less than 5%. v3's results are the specification; * v4/tests/test_inference.c compares the two. * * Nothing here uses the C library; the caller supplies the scratch. */ #ifndef V4_INFERENCE_H #define V4_INFERENCE_H #include typedef uint64_t v4_q48; /* v3's q48_16_t */ v4_q48 v4_q48_mul(v4_q48 a, v4_q48 b); v4_q48 v4_q48_div(v4_q48 a, v4_q48 b); v4_q48 v4_q48_exp(v4_q48 q); v4_q48 v4_q48_log(uint64_t x); /* v3's compute_variance_q48, find_variance_inflection (window width, 256 .. 4096), infer_decay_slope_q48 */ v4_q48 v4_inference_variance(const uint64_t *heat, uint64_t n); uint32_t v4_inference_window_width(const uint64_t *heat, uint64_t n); uint64_t v4_inference_decay_slope(const uint64_t *heat, uint64_t n); /* v3's InferenceOutputs, and its inference_engine_run on a trajectory already taken: l5 and l6 are L8's gates * on the window and slope inference */ typedef struct { uint32_t adaptive_window_width; uint64_t adaptive_decay_slope; v4_q48 window_variance_q48; v4_q48 slope_fit_quality_q48; uint8_t early_exited; } v4_inference_out; void v4_inference_run(const uint64_t *trajectory, uint64_t n, int l5, int l6, v4_inference_out *out); #endif