5f6ce5ca1f
The co-activation accrual already works (hebb is an EWMA over co-firing); what
was missing is the promotion layer from design §9 that turns accrual into
durable structure. This adds it on top, entirely behind ENGRAM_CONSOLIDATION so
the OFF path is byte-identical to trunk.
CONNECTION threshold ("connection IS consolidation"): when a strongly-firing
InternalStateEvent is created (salience >= ENGRAM_CONSOL_CONN_MIN, default 0.6),
wire hebbian-associate edges from it to the top-K working-memory nodes active at
that instant (ENGRAM_CONSOL_WM_TOPK, default 5), provenance-tagged
"consolidated-from-ISE" and dedup-guarded. A sub-threshold ISE forms nothing (a
shower thought) and drifts out at the existing 48h prune.
PERMANENCE threshold (rare): engram_consolidate_permanence(node) marks a node
whose rehearsed ACT-R base-level clears ENGRAM_CONSOL_PERM_MIN durable via a
reversible metadata marker; engram_prune_telemetry then exempts it (gated, so no
trunk node is ever affected). Idempotent, no double-promote.
Thresholds are env-tunable for A/B without a rebuild.
MEASURED on a copy (throwaway HOME):
- Headline accrual curve (flag OFF, pure trunk) over N co-activations of a wired
pair — hebb_max: N=1 -> 1e-4 (=ETA), N=100 -> 0.010, N=1625 -> 0.150
(LINK_MIN, where an unwired pair consolidates), N=3000 -> 0.259; tracks the
analytic EWMA 1-0.9999^N within measurement noise (co-activation P~1).
- Strong ISE wired 2 edges to exactly the wm_top nodes (hebb-a, hebb-b); weak
ISE formed 0; edges carry the reversible provenance marker.
- Promoted node survived the 48h prune (2->1 nodes); ephemeral ISE swept.
- Flag OFF: ISE creation added 0 edges, permanence returned 0 (no-op).
ASan+UBSan clean.
125 lines
6.5 KiB
C
125 lines
6.5 KiB
C
/* test_interoception_p1_consol.c — M-INTEROCEPTION Priority 1.
|
|
* Two-threshold consolidation (ENGRAM_CONSOLIDATION, default OFF).
|
|
*
|
|
* Modes:
|
|
* accrual — flag OFF (pure trunk). Drive N co-activations of a WIRED pair and
|
|
* print act-stats at sampled N so the run script can plot the
|
|
* hebb accrual curve (headline measurement). No consolidation code
|
|
* runs; this measures the EXISTING EWMA accrual.
|
|
* connect — flag ON. Seed, activate to populate WM, then create a STRONG ISE
|
|
* (connects to wm_top) and a WEAK ISE (below the bar → nothing).
|
|
* Exports the graph so edges from each ISE can be counted.
|
|
* perm — flag ON. Load two OLD InternalStateEvent nodes; promote one to
|
|
* permanence; prune telemetry; export so the durable one is shown
|
|
* to survive while the ephemeral one is swept.
|
|
* offcheck — flag OFF. Prove creating an ISE forms NO edges and
|
|
* engram_consolidate_permanence is a no-op (byte-identical OFF path).
|
|
*/
|
|
#include "el_runtime.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static el_val_t S(const char* s){ return EL_STR(s); }
|
|
static el_val_t F(double d){ return el_from_float(d); }
|
|
|
|
static void build_seed(void){
|
|
el_val_t a = engram_node_full(S("hebbian potentiation strengthens co-active memory links"),
|
|
S("Concept"), S("hebb-a"), F(0.9), F(0.85), F(1.0), S("Semantic"),
|
|
S("hebbian,memory,activation"));
|
|
el_val_t b = engram_node_full(S("co-active memory links accrue hebbian associative weight"),
|
|
S("Concept"), S("hebb-b"), F(0.9), F(0.85), F(1.0), S("Semantic"),
|
|
S("hebbian,memory,weight"));
|
|
el_val_t c = engram_node_full(S("unrelated culinary recipe for sourdough bread"),
|
|
S("Fact"), S("distractor-1"), F(0.4), F(0.4), F(1.0), S("Semantic"), S("food"));
|
|
el_val_t d = engram_node_full(S("the weather forecast predicts rain tomorrow afternoon"),
|
|
S("Fact"), S("distractor-2"), F(0.4), F(0.4), F(1.0), S("Semantic"), S("weather"));
|
|
engram_connect(a, b, F(0.8), S("associate"));
|
|
engram_connect(a, c, F(0.3), S("associate"));
|
|
engram_connect(b, d, F(0.3), S("associate"));
|
|
}
|
|
static const char* QUERY =
|
|
"hebbian potentiation co-active memory links associative weight";
|
|
|
|
int main(int argc, char** argv){
|
|
if (argc < 3){ fprintf(stderr,"usage: %s <accrual|connect|perm|offcheck> <dir>\n",argv[0]); return 2; }
|
|
const char* mode = argv[1];
|
|
const char* dir = argv[2];
|
|
char p[1024];
|
|
|
|
if (!strcmp(mode,"accrual")){
|
|
build_seed();
|
|
int samples[] = {1,10,50,100,250,500,1000,1625,2000,2500,3000};
|
|
int ns = (int)(sizeof samples/sizeof samples[0]);
|
|
int NMAX = samples[ns-1];
|
|
int si = 0;
|
|
for (int n=1; n<=NMAX; n++){
|
|
engram_activate_json(S(QUERY), (el_val_t)3);
|
|
if (si<ns && n==samples[si]){
|
|
printf("SAMPLE %d %s\n", n, EL_CSTR(engram_act_stats_json()));
|
|
si++;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
if (!strcmp(mode,"connect")){
|
|
build_seed();
|
|
engram_activate_json(S(QUERY), (el_val_t)3);
|
|
long long e_before = (long long)(int64_t)engram_edge_count();
|
|
/* STRONG ISE — should connect to wm_top */
|
|
el_val_t ise_strong = engram_node_full(S("strong internal state: focused on hebbian consolidation"),
|
|
S("InternalStateEvent"), S("ise-strong"), F(0.9), F(0.8), F(1.0), S("Working"), S("ise"));
|
|
long long e_after_strong = (long long)(int64_t)engram_edge_count();
|
|
/* WEAK ISE — below the connection bar (salience 0.3 < default 0.6) */
|
|
el_val_t ise_weak = engram_node_full(S("weak internal state: idle drift"),
|
|
S("InternalStateEvent"), S("ise-weak"), F(0.3), F(0.3), F(1.0), S("Working"), S("ise"));
|
|
long long e_after_weak = (long long)(int64_t)engram_edge_count();
|
|
printf("ISE_STRONG_ID %s\n", EL_CSTR(ise_strong));
|
|
printf("ISE_WEAK_ID %s\n", EL_CSTR(ise_weak));
|
|
printf("EDGES before=%lld after_strong=%lld after_weak=%lld\n",
|
|
e_before, e_after_strong, e_after_weak);
|
|
snprintf(p,sizeof p,"%s/connect.json",dir);
|
|
el_val_t g = engram_save(S(p)); (void)g;
|
|
return 0;
|
|
}
|
|
|
|
if (!strcmp(mode,"perm")){
|
|
/* Two OLD ISE nodes (created_at far in the past → prunable at 48h). */
|
|
snprintf(p,sizeof p,"%s/seed.json",dir);
|
|
FILE* f=fopen(p,"w");
|
|
fprintf(f,"{\"nodes\":["
|
|
"{\"id\":\"ise-durable\",\"content\":\"promoted internal state\",\"node_type\":\"InternalStateEvent\","
|
|
"\"label\":\"ise-durable\",\"salience\":0.5,\"confidence\":1.0,\"created_at\":1000},"
|
|
"{\"id\":\"ise-ephemeral\",\"content\":\"transient internal state\",\"node_type\":\"InternalStateEvent\","
|
|
"\"label\":\"ise-ephemeral\",\"salience\":0.5,\"confidence\":1.0,\"created_at\":1000}"
|
|
"],\"edges\":[]}");
|
|
fclose(f);
|
|
if(!engram_load(S(p))){ fprintf(stderr,"load failed\n"); return 2; }
|
|
long long n_before = (long long)(int64_t)engram_node_count();
|
|
el_val_t promoted = engram_consolidate_permanence(S("ise-durable"));
|
|
long long removed = (long long)(int64_t)engram_prune_telemetry((el_val_t)0); /* default 48h */
|
|
long long n_after = (long long)(int64_t)engram_node_count();
|
|
printf("PROMOTED %lld\n", (long long)(int64_t)promoted);
|
|
printf("NODES before=%lld after=%lld removed=%lld\n", n_before, n_after, removed);
|
|
printf("DURABLE_NODE %s\n", EL_CSTR(engram_get_node_json(S("ise-durable"))));
|
|
printf("EPHEMERAL_NODE %s\n", EL_CSTR(engram_get_node_json(S("ise-ephemeral"))));
|
|
return 0;
|
|
}
|
|
|
|
if (!strcmp(mode,"offcheck")){
|
|
build_seed();
|
|
engram_activate_json(S(QUERY), (el_val_t)3);
|
|
long long e_before = (long long)(int64_t)engram_edge_count();
|
|
engram_node_full(S("strong internal state with flag OFF"),
|
|
S("InternalStateEvent"), S("ise-off"), F(0.9), F(0.8), F(1.0), S("Working"), S("ise"));
|
|
long long e_after = (long long)(int64_t)engram_edge_count();
|
|
el_val_t perm = engram_consolidate_permanence(S("ise-off"));
|
|
printf("OFF edges before=%lld after=%lld perm_ret=%lld\n",
|
|
e_before, e_after, (long long)(int64_t)perm);
|
|
return (e_before==e_after && (int64_t)perm==0) ? 0 : 1;
|
|
}
|
|
|
|
fprintf(stderr,"unknown mode %s\n",mode); return 2;
|
|
}
|