interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / src / physics0 / learner / pd0_learner.h

86 lines · 5153 bytes Raw Blame History
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 learner (Physics-0 Discovery Engine, Direction 4): the first genuine
18 * learner. It sees only the describe record and PD0REC1 observation records
19 * the harness forwards (FIT and SELECT episodes), fits compact one-step
20 * relations over a bounded monomial vocabulary, keeps several candidates,
21 * and emits evidence for the independent ladder checker. It never declares
22 * a ladder state, never reads HOLDOUT/TRIAL/REP raw records, holds no file,
23 * no generator symbol, no level identity. Formats come from pd0_fmt.h
24 * (byte layouts only). Floating point is used only inside fitting; every
25 * serialised number is a micro-unit integer. */
26#ifndef PD0_LEARNER_H
27#define PD0_LEARNER_H
28#include "pd0_fmt.h"
29
30#define PD0L_MAX_TRANS 65536u
31#define PD0L_MAX_LIB 128u
32#define PD0L_MAX_CAND 8
33#define PD0L_MAX_SEL 10u /* terms per equation the search may select */
34#define PD0L_MAX_FORBID 4096u
35
36typedef struct {
37 uint8_t n_obs, n_channels;
38 int64_t dt_micro;
39 int64_t chan_min[PD0_MAX_CHAN], chan_max[PD0_MAX_CHAN];
40 int64_t reset_min[PD0_MAX_OBS], reset_max[PD0_MAX_OBS]; /* per variable (PD0DESC2); a one-pair describe is broadcast by the harness */
41 uint32_t episode_max_steps, budget_steps, budget_episodes;
42} pd0l_desc;
43
44typedef struct {
45 pd0_rel rel; /* serialisable relation (coefficients in micro) */
46 uint32_t bits; /* description_bits (spec 6.2 rule) */
47 uint32_t size; /* |R| */
48 int64_t fit_nrmse_micro; /* one-step NRMSE on FIT (integer evaluator) */
49 int64_t select_nrmse_micro; /* one-step NRMSE on SELECT (integer evaluator) */
50 double mdl_bits; /* description bits + residual code length on SELECT */
51 double lag1_autocorr[PD0_MAX_OBS]; /* residual lag-1 autocorrelation on FIT per variable */
52 int hidden_state_suspected; /* residuals carry memory the vocabulary cannot express */
53 int is_null;
54} pd0l_candidate;
55
56typedef struct pd0_learner pd0_learner;
57
58pd0_learner *pd0_learner_new(const pd0l_desc *d, uint64_t seed);
59void pd0_learner_free(pd0_learner *L);
60/* a FIT or SELECT record (tag TAG_FIT / TAG_SELECT); others are refused (-1) */
61int pd0_learner_observe(pd0_learner *L, const pd0_rec *r, uint8_t tag);
62/* the records of an episode that was TRIAL/REP and is now FIT after a refutation */
63uint32_t pd0_learner_n_transitions(const pd0_learner *L, uint8_t tag);
64/* exploration: seeded random reset + schedule inside the describe bounds */
65void pd0_learner_explore(pd0_learner *L, uint32_t episode_index, int64_t *reset, pd0_step *steps, uint32_t n_steps);
66/* fit: rebuilds the candidate set from FIT, ranked by MDL on SELECT. returns count (>= 1: the null is always present) */
67int pd0_learner_fit(pd0_learner *L);
68int pd0_learner_n_candidates(const pd0_learner *L);
69const pd0l_candidate *pd0_learner_candidate(const pd0_learner *L, int i); /* 0 = best */
70/* the strongest (variable or intervention, one-step change) correlation over all visible OK step
71 * records, with a permutation test (recorded seed). returns 0 or -1 (too few records). */
72int pd0_learner_correlation(const pd0_learner *L, uint64_t shuffle_seed, uint32_t n_shuffles, pd0_corr *out);
73/* planner stand-in (Direction 5 owns the real one): among n_random seeded schedules inside the
74 * bounds, not in the forbidden hash list, pick the one where the hypotheses disagree most.
75 * hyps[0] is the candidate. returns divergence in micro (D * 1e6), or -1 if none (NO_DISCRIMINATING_EXPERIMENT). */
76int64_t pd0_learner_propose(const pd0_learner *L, const pd0_rel *hyps, int n_hyp, uint64_t planner_seed, uint32_t n_random,
77 const uint8_t (*forbidden)[PD0_HASH], uint32_t n_forbidden, pd0_exp *out);
78/* a random schedule from a named stream (used for the random half of replication) */
79void pd0_learner_random_schedule(const pd0l_desc *d, uint64_t seed, const char *tag, uint32_t idx, int64_t *reset, pd0_step *steps, uint32_t n);
80/* prediction interface over a relation (observed variables in and out; latent starts at 0) */
81void pd0_learner_rollout(const pd0_rel *rel, const int64_t *init, const pd0_step *steps, uint32_t n, int64_t *out);
82/* one-step NRMSE of rel over the learner's records of a tag (integer evaluator, latent carried per episode) */
83int64_t pd0_learner_onestep_nrmse(const pd0_learner *L, const pd0_rel *rel, uint8_t tag);
84/* human report (JSON-ish, non-canonical) */
85size_t pd0_learner_report(const pd0_learner *L, char *buf, size_t cap);
86#endif