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_main.c

41 lines · 2491 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/* pd0-learner: deterministic offline fit over a raw PD0REC1 stream on stdin
18 * (records are treated as FIT unless an episode index appears in the optional
19 * SELECT list). Prints the learner report and the PDLAW1 bytes of the best
20 * candidate as hex. Used by the determinism test; holds no world knowledge.
21 * Usage: pd0-learner <n_obs> <n_channels> [select-every-k] < records */
22#include "pd0_learner.h"
23#include "pd0_codes.h"
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28int main(int argc, char **argv)
29{
30 if (argc < 3) { fprintf(stderr, "usage: pd0-learner <n_obs> <n_channels> [select-every-k]\n"); return 2; }
31 pd0l_desc d; memset(&d, 0, sizeof d); d.n_obs = (uint8_t)atoi(argv[1]); d.n_channels = (uint8_t)atoi(argv[2]); int k = argc > 3 ? atoi(argv[3]) : 4;
32 for (int c = 0; c < d.n_channels; c++) { d.chan_min[c] = -2000000; d.chan_max[c] = 2000000; } for (int j = 0; j < d.n_obs; j++) { d.reset_min[j] = -2000000; d.reset_max[j] = 2000000; }
33 d.dt_micro = 50000; d.episode_max_steps = 100; d.budget_steps = 3000; d.budget_episodes = 300;
34 pd0_learner *L = pd0_learner_new(&d, 1); if (!L) return 2;
35 static uint8_t buf[1 << 22]; size_t n = fread(buf, 1, sizeof buf, stdin), off = 0; pd0_rec r; size_t used;
36 while (off < n && pd0_rec_parse(buf + off, n - off, &r, &used) == PD0V_OK) { pd0_learner_observe(L, &r, (k > 0 && (int)(r.episode % (uint32_t)k) == k - 1) ? TAG_SELECT : TAG_FIT); off += used; }
37 pd0_learner_fit(L);
38 static char jb[1 << 20]; pd0_learner_report(L, jb, sizeof jb); puts(jb);
39 const pd0l_candidate *c = pd0_learner_candidate(L, 0); if (c) { uint8_t law[8192]; pd0_rel rel = c->rel; size_t ln = pd0_rel_write(&rel, law, sizeof law); printf("PDLAW1 "); for (size_t i = 0; i < ln; i++) printf("%02x", law[i]); printf("\n"); }
40 pd0_learner_free(L); return 0;
41}