pub struct HebbianState {
pub activations: Vec<ActivationRecord>,
pub coactivations: HashMap<(u32, u32), CoactivationPair>,
pub fingerprints: Vec<ActivationFingerprint>,
}Expand description
In-memory Hebbian state, loaded from binary files.
Fields§
§activations: Vec<ActivationRecord>§coactivations: HashMap<(u32, u32), CoactivationPair>§fingerprints: Vec<ActivationFingerprint>Implementations§
Source§impl HebbianState
impl HebbianState
Sourcepub fn load_or_init(output_dir: &Path, block_count: usize) -> Self
pub fn load_or_init(output_dir: &Path, block_count: usize) -> Self
Load or initialize Hebbian state for a given block count.
Sourcepub fn record_activation(&mut self, results: &[(u32, f32)], query_hash: u64)
pub fn record_activation(&mut self, results: &[(u32, f32)], query_hash: u64)
Record that a set of blocks were activated together by a query. This is the core Hebbian learning signal.
Sourcepub fn apply_drift(&mut self, headers: &[(f32, f32, f32)])
pub fn apply_drift(&mut self, headers: &[(f32, f32, f32)])
Apply Hebbian drift: co-activated blocks pull each other’s coordinates closer. Call this during rebuild or periodically.
Sourcepub fn effective_coords(
&self,
block_idx: usize,
original: (f32, f32, f32),
) -> (f32, f32, f32)
pub fn effective_coords( &self, block_idx: usize, original: (f32, f32, f32), ) -> (f32, f32, f32)
Get effective coordinates for a block (original + Hebbian drift).
Sourcepub fn energy(&self, block_idx: usize) -> f32
pub fn energy(&self, block_idx: usize) -> f32
Get the energy (heat) of a block. 1.0 = just activated, decays toward 0.
Sourcepub fn hot_indices(&self, threshold: f32) -> Vec<usize>
pub fn hot_indices(&self, threshold: f32) -> Vec<usize>
Block indices whose decayed energy is at or above threshold, ascending.
The energy lives in memory, so the candidate set can be built before any
block header is touched. A consumer that would otherwise scan all
699,110 headers to find the handful of hot blocks reads only those
headers. The result is exactly {i : energy(i) >= threshold}, in
ascending order, so a full-scan formulation and this one produce
bit-identical sums.
Sourcepub fn save(&self, output_dir: &Path) -> Result<(), String>
pub fn save(&self, output_dir: &Path) -> Result<(), String>
Save all Hebbian state to binary files. Writes the activation base in full, which is the correct thing after a rebuild or a remap.
Sourcepub fn save_dirty(&self, output_dir: &Path, dirty: &[u32]) -> Result<(), String>
pub fn save_dirty(&self, output_dir: &Path, dirty: &[u32]) -> Result<(), String>
Save after a recall: journal only the blocks that were actually activated, and rewrite the base only when the journal has reached its bound or the base is missing.
The caller passes the dirty indices because it is the one that knows them – recall activates exactly the top-k blocks it returned. Nothing is deferred to process exit on purpose: a CLI invocation is a whole process, so “write it later” would lose the learning entirely.
Sourcepub fn stats(&self) -> HebbianStats
pub fn stats(&self) -> HebbianStats
Get statistics about the Hebbian state.
Sourcepub fn latest_fingerprint(&self) -> Option<&ActivationFingerprint>
pub fn latest_fingerprint(&self) -> Option<&ActivationFingerprint>
Get the latest activation fingerprint (for mirror neuron sharing).
Sourcepub fn strongest_pairs(&self, n: usize) -> Vec<&CoactivationPair>
pub fn strongest_pairs(&self, n: usize) -> Vec<&CoactivationPair>
Get top-N strongest co-activation pairs.
Sourcepub fn remap_indexes(&mut self, old_to_new: &[u32])
pub fn remap_indexes(&mut self, old_to_new: &[u32])
Remap all block indexes after a rebuild reorders blocks.
old_to_new[old_idx] = new_idx. Blocks that were not in the old
layout get u32::MAX and are dropped.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HebbianState
impl RefUnwindSafe for HebbianState
impl Send for HebbianState
impl Sync for HebbianState
impl Unpin for HebbianState
impl UnsafeUnpin for HebbianState
impl UnwindSafe for HebbianState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more