Skip to main content

LearningEngine

Struct LearningEngine 

Source
pub struct LearningEngine { /* private fields */ }
Expand description

The HELM orchestration hub that bundles all six learning sub-modules.

§Examples

use lmm_agent::cognition::learning::engine::LearningEngine;
use lmm_agent::cognition::learning::config::LearningConfig;

let mut engine = LearningEngine::new(LearningConfig::default());
assert!(engine.q_table().is_empty());
assert_eq!(engine.episode_count(), 0);

Implementations§

Source§

impl LearningEngine

Source

pub fn new(config: LearningConfig) -> Self

Constructs a new LearningEngine from a LearningConfig.

§Examples
use lmm_agent::cognition::learning::engine::LearningEngine;
use lmm_agent::cognition::learning::config::LearningConfig;

let engine = LearningEngine::new(LearningConfig::default());
assert_eq!(engine.episode_count(), 0);
Source

pub fn config(&self) -> &LearningConfig

Returns a reference to the current configuration.

Source

pub fn q_table(&self) -> &QTable

Returns a reference to the Q-table.

Source

pub fn reset_epsilon(&mut self, epsilon: f64)

Resets the Q-table exploration epsilon.

Source

pub fn episode_count(&self) -> usize

Returns the total number of completed episodes.

Source

pub fn total_reward(&self) -> f64

Returns the accumulated total reward.

Source

pub fn record_step( &mut self, signal: &CognitionSignal, state: u64, action: ActionKey, next_state: u64, )

Records one ThinkLoop step into all active learning sub-modules.

This should be called inside ThinkLoop::run after each step produces a CognitionSignal.

§Arguments
  • signal - The signal produced by this ThinkLoop iteration.
  • state - FNV-1a state key for the current query.
  • action - The action applied to produce signal.query.
  • next_state - FNV-1a state key for the observation after the action.
§Examples
use lmm_agent::cognition::learning::engine::LearningEngine;
use lmm_agent::cognition::learning::config::LearningConfig;
use lmm_agent::cognition::learning::q_table::{ActionKey, QTable};
use lmm_agent::cognition::signal::CognitionSignal;

let mut engine = LearningEngine::new(LearningConfig::default());
let sig = CognitionSignal::new(0, "a b".into(), "a b c".into(), 1.0, 0.0);
let s = QTable::state_key("a b");
let s2 = QTable::state_key("a b c");
engine.record_step(&sig, s, ActionKey::Narrow, s2);
assert!(!engine.q_table().is_empty());
Source

pub fn recommend_action( &mut self, state: u64, goal: &str, step: usize, ) -> ActionKey

Selects the recommended action for state using the Q-table and meta priors.

If a meta-adapter warm-start is available, it is added as a prior bias to the greedy Q selection before applying ε-greedy exploration.

§Examples
use lmm_agent::cognition::learning::engine::LearningEngine;
use lmm_agent::cognition::learning::config::LearningConfig;
use lmm_agent::cognition::learning::q_table::{ActionKey, QTable};

let mut engine = LearningEngine::new(LearningConfig::default());
let s = QTable::state_key("hello world");
let action = engine.recommend_action(s, "hello world", 0);
assert!(ActionKey::all().contains(&action));
Source

pub fn end_of_episode( &mut self, cold: &ColdStore, index: &mut KnowledgeIndex, goal: &str, avg_reward: f64, )

Finalises a completed episode: distils knowledge, stores meta-prototype, synthesises PMI facts, and decays ε.

§Arguments
  • cold - The agent’s cold store after drain_to_cold.
  • index - The agent’s knowledge index for distillation output.
  • goal - The natural-language goal that was pursued.
  • avg_reward - Mean reward across all steps in this episode.
§Examples
use lmm_agent::cognition::learning::engine::LearningEngine;
use lmm_agent::cognition::learning::config::LearningConfig;
use lmm_agent::cognition::memory::ColdStore;
use lmm_agent::cognition::knowledge::KnowledgeIndex;

let mut engine = LearningEngine::new(LearningConfig::default());
let cold = ColdStore::default();
let mut idx = KnowledgeIndex::new();
engine.end_of_episode(&cold, &mut idx, "test goal", 0.5);
assert_eq!(engine.episode_count(), 1);
Source

pub fn federate(&mut self, snapshot: &AgentSnapshot)

Merges a remote AgentSnapshot into the local Q-table (federated step).

Only active when LearningMode::Federated is enabled.

§Examples
use lmm_agent::cognition::learning::engine::LearningEngine;
use lmm_agent::cognition::learning::config::LearningConfig;
use lmm_agent::cognition::learning::q_table::{ActionKey, QTable};
use lmm_agent::types::AgentSnapshot;

let mut engine = LearningEngine::new(LearningConfig::default());
let remote_qt = QTable::new(0.1, 0.9, 0.0, 1.0, 0.0);
let snap = AgentSnapshot { agent_id: "remote".into(), q_table: remote_qt, total_reward: 1.0 };
engine.federate(&snap);
assert_eq!(engine.aggregator().merge_count, 1);
Source

pub fn export_snapshot(&self, agent_id: impl Into<String>) -> AgentSnapshot

Exports an AgentSnapshot for federated sharing with other agents.

§Examples
use lmm_agent::cognition::learning::engine::LearningEngine;
use lmm_agent::cognition::learning::config::LearningConfig;

let engine = LearningEngine::new(LearningConfig::default());
let snap = engine.export_snapshot("agent-1");
assert_eq!(snap.agent_id, "agent-1");
Source

pub fn aggregator(&self) -> &FederatedAggregator

Returns a reference to the federated aggregator.

Source

pub fn elastic(&self) -> &ElasticMemoryGuard

Returns a reference to the elastic memory guard.

Source

pub fn informal(&self) -> &InformalLearner

Returns a reference to the informal learner.

Source

pub fn meta(&self) -> &MetaAdapter

Returns a reference to the meta-adapter.

Source

pub fn distiller(&self) -> &KnowledgeDistiller

Returns a reference to the knowledge distiller.

Trait Implementations§

Source§

impl Clone for LearningEngine

Source§

fn clone(&self) -> LearningEngine

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LearningEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for LearningEngine

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for LearningEngine

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,