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 / tests / runtime / rx_cog_engines.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 | /* |
| 18 | * rx_cog_engines.h -- stand-in cognition engines for the cognitive routing |
| 19 | * qualification. |
| 20 | * |
| 21 | * They are real computations on tasks whose right answer is known, so the |
| 22 | * test can measure quality. They are not AIEN. "General" here is the largest |
| 23 | * trained network in the set, named for the role it plays in the ladder. |
| 24 | * |
| 25 | * RECOGNIZE: label a 16-dimensional observation by a fixed nonlinear rule |
| 26 | * the engines never see; they learn it from labelled examples. |
| 27 | * PLAN: find a path on a grid within a length bound, or say there is none. |
| 28 | */ |
| 29 | #ifndef RX_COG_ENGINES_H |
| 30 | #define RX_COG_ENGINES_H |
| 31 | |
| 32 | #include "runtime/rx_route.h" |
| 33 | |
| 34 | #include <stdint.h> |
| 35 | |
| 36 | #define COG_DIM 16 |
| 37 | #define GRID_W 96 |
| 38 | #define GRID_H 96 |
| 39 | #define GRID_CELLS (GRID_W * GRID_H) |
| 40 | #define PATH_MAX_STEPS 2048 |
| 41 | |
| 42 | typedef struct { |
| 43 | float x[COG_DIM]; |
| 44 | } RecInput; |
| 45 | |
| 46 | typedef struct { |
| 47 | int label; |
| 48 | } RecOutput; |
| 49 | |
| 50 | typedef struct { |
| 51 | const uint8_t *blocked; /* GRID_CELLS, shared by all requests of one map */ |
| 52 | uint16_t start, goal; |
| 53 | uint16_t bound; /* the path may have at most this many steps */ |
| 54 | } PlanInput; |
| 55 | |
| 56 | typedef struct { |
| 57 | int status; /* 1 path, 0 proven none, -1 unknown */ |
| 58 | uint16_t len; |
| 59 | uint16_t path[PATH_MAX_STEPS]; |
| 60 | } PlanOutput; |
| 61 | |
| 62 | enum { ENG_POLICY = 11, ENG_NEURAL = 12, ENG_GENERAL = 13, ENG_ENSEMBLE = 14, |
| 63 | ENG_GREEDY = 21, ENG_FOCUSED = 22, ENG_JSPACE = 23 }; |
| 64 | |
| 65 | /* Ground truth. */ |
| 66 | int rec_truth(const RecInput *in); |
| 67 | void rec_sample(uint64_t *rng, RecInput *in); |
| 68 | /* Shortest path length, or -1 when unreachable. */ |
| 69 | int plan_truth(const PlanInput *in); |
| 70 | int plan_correct(const PlanInput *in, const PlanOutput *out, int truth_len); |
| 71 | void plan_map(uint64_t seed, uint8_t *blocked); |
| 72 | void plan_sample(uint64_t *rng, const uint8_t *blocked, PlanInput *in); |
| 73 | |
| 74 | /* Train the learned engines (deterministic from the seed). */ |
| 75 | void cog_engines_train(uint64_t seed, uint32_t examples, uint32_t epochs); |
| 76 | /* Perturb the neural module's weights (a damaged module). */ |
| 77 | void cog_damage_neural(uint64_t seed, float scale); |
| 78 | void cog_restore_neural(void); |
| 79 | |
| 80 | int cog_register_all(RxCogRouter *r); |
| 81 | RxCogEngineFn cog_engine_fn(uint32_t id); |
| 82 | |
| 83 | uint64_t cog_rng(uint64_t *s); |
| 84 | |
| 85 | #endif |