omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / physics0 / score / pd0_score.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* PD-0 scorer (spec section 6). Holds generator-side truth; never linked into a learner. */ |
| 18 | #ifndef PD0_SCORE_H |
| 19 | #define PD0_SCORE_H |
| 20 | #include "pd0_fmt.h" |
| 21 | #include "pd0_codes.h" |
| 22 | #define PD0_MAX_TRUE_TERMS 32 |
| 23 | #define PD0_MAX_FIT 65536u |
| 24 | typedef struct { uint8_t target; uint8_t expo[PD0_MAX_VARS + PD0_MAX_CHAN]; int64_t coef; } pd0_true_term; |
| 25 | typedef struct { |
| 26 | uint8_t n_obs, n_channels; |
| 27 | uint32_t size_bound; /* 6.2 S*+2 */ |
| 28 | int64_t inbox_bound, extrap_bound, onestep_bound; /* 6.1, micro; onestep_bound 0 = not scored */ |
| 29 | int score_constants; int64_t const_tol_ppm; /* 6.3 */ |
| 30 | int require_latent; int64_t latent_ref_factor; /* L6: reference must fail by this factor */ |
| 31 | uint32_t n_true_terms; pd0_true_term true_terms[PD0_MAX_TRUE_TERMS]; |
| 32 | } pd0_score_params; |
| 33 | typedef struct { int64_t init[PD0_MAX_OBS]; pd0_step steps[PD0_MAX_STEPS]; int64_t truth[PD0_MAX_STEPS][PD0_MAX_OBS]; uint8_t in_box; } pd0_score_episode; |
| 34 | typedef struct { int64_t before[PD0_MAX_OBS]; uint8_t chan; int64_t value; int64_t after[PD0_MAX_OBS]; } pd0_transition; |
| 35 | /* learner-side prediction interfaces (observed variables only) */ |
| 36 | typedef int (*pd0_rollout_fn)(void *ctx, const int64_t *init, const pd0_step *steps, uint32_t n, int64_t *out); |
| 37 | typedef int (*pd0_predict_fn)(void *ctx, const int64_t *state, uint8_t chan, int64_t value, int64_t *next); |
| 38 | typedef struct { int code; uint32_t fail_mask; int64_t inbox_nrmse, extrap_nrmse, onestep_nrmse, ref_nrmse; uint32_t size, bits; } pd0_score_result; |
| 39 | #define PD0_FAIL_BIT(code) (1u << ((code) - 300)) |
| 40 | /* declared_stored_numbers: count of stored numbers in any non-parametric component (spec 6.2: one term each) */ |
| 41 | int pd0_score(const pd0_score_params *P, const pd0_rel *rel, uint32_t declared_stored_numbers, |
| 42 | pd0_rollout_fn roll, pd0_predict_fn pred, void *ctx, |
| 43 | const pd0_score_episode *eps, uint32_t n_eps, |
| 44 | const pd0_transition *fit, uint32_t n_fit, pd0_score_result *out); |
| 45 | /* relation-backed predictors (ctx = const pd0_rel *) */ |
| 46 | int pd0_rel_rollout_fn(void *ctx, const int64_t *init, const pd0_step *steps, uint32_t n, int64_t *out); |
| 47 | int pd0_rel_predict_fn(void *ctx, const int64_t *state, uint8_t chan, int64_t value, int64_t *next); |
| 48 | /* harness reference: greedy sparse least squares over the degree<=3 monomial library, latent-free */ |
| 49 | int pd0_reference_fit(uint8_t n_obs, uint8_t n_channels, uint32_t max_terms_per_eq, const pd0_transition *fit, uint32_t n_fit, pd0_rel *out); |
| 50 | #endif |