MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_sem_diffuse

Function cbm_sem_diffuse

src/semantic/semantic.c:2054–2073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2052/* ── Graph diffusion ─────────────────────────────────────────────── */
2053
2054void cbm_sem_diffuse(cbm_sem_vec_t *combined, const cbm_sem_vec_t *neighbors, int neighbor_count,
2055 float alpha) {
2056 if (!combined || !neighbors || neighbor_count <= 0) {
2057 return;
2058 }
2059 /* Blend: combined = (1-α) × combined + α × mean(neighbors) */
2060 cbm_sem_vec_t mean;
2061 memset(&mean, 0, sizeof(mean));
2062 for (int n = 0; n < neighbor_count; n++) {
2063 for (int i = 0; i < CBM_SEM_DIM; i++) {
2064 mean.v[i] += neighbors[n].v[i];
2065 }
2066 }
2067 float inv_n = CBM_SEM_UNIT_POS / (float)neighbor_count;
2068 float one_minus_alpha = CBM_SEM_UNIT_POS - alpha;
2069 for (int i = 0; i < CBM_SEM_DIM; i++) {
2070 combined->v[i] = (one_minus_alpha * combined->v[i]) + (alpha * mean.v[i] * inv_n);
2071 }
2072 cbm_sem_normalize(combined);
2073}

Callers 1

test_semantic.cFile · 0.85

Calls 1

cbm_sem_normalizeFunction · 0.85

Tested by

no test coverage detected