Skip to main content

SelfModel

Struct SelfModel 

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

Top-level self-model — orchestrates metric tracking, forecasting, alerting, and confidence calibration.

Implementations§

Source§

impl SelfModel

Source

pub fn new() -> Self

Create a new self-model with default history capacity and alert rules.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new self-model with the given history capacity per metric.

Source

pub fn record(&self, kind: MetricKind, value: f32)

Record a metric sample.

Source

pub fn record_at(&self, kind: MetricKind, value: f32, timestamp: DateTime<Utc>)

Record a metric sample with an explicit timestamp (for testing/replay).

Source

pub fn forecast(&self, kind: MetricKind, horizon: usize) -> Option<Forecast>

Forecast a metric horizon samples into the future.

Source

pub fn forecast_all(&self, horizon: usize) -> Vec<(MetricKind, Forecast)>

Forecast all tracked metrics.

Source

pub fn check_alerts(&self) -> Vec<Alert>

Check all alert rules against current forecasts.

Source

pub fn confidence(&self) -> f32

Get the overall system confidence (0.0–1.0). Confidence <0.5 triggers conservative dispatch.

Source

pub fn snapshot(&self) -> SelfModelSnapshot

Take a snapshot of the entire self-model state.

Source

pub fn add_alert_rule(&self, rule: AlertRule)

Add a custom alert rule.

Source

pub fn tracked_count(&self) -> usize

Get the number of tracked metrics.

Source

pub fn sample_count(&self, kind: MetricKind) -> usize

Get the number of samples for a specific metric.

Source

pub fn record_cognitive(&self, metrics: &CognitiveMetrics)

Record cognitive metrics from an imagination/research cycle.

Convenience method that records all four cognitive metrics at once.

Source

pub fn record_cognitive_at( &self, metrics: &CognitiveMetrics, timestamp: DateTime<Utc>, )

Record cognitive metrics with an explicit timestamp (for testing/replay).

Source

pub fn forecast_cognitive(&self, horizon: usize) -> CognitiveForecast

Forecast cognitive metrics horizon samples ahead.

Returns forecasts for all four cognitive metrics that have enough history.

Source

pub fn check_cognitive_alerts(&self) -> Vec<Alert>

Check cognitive-specific alert rules.

Returns alerts for cognitive metrics only (imagination quality, research output, scenario confidence, simulation variance).

Source

pub fn to_json(&self) -> Value

Serialize the full self-model state for persistence.

Includes per-metric histories (with timestamps), alert rules, and the confidence calibrator state, so a restarted process resumes forecasting, drift alerts, and confidence exactly where it left off.

Source

pub fn from_json(&self, value: &Value) -> Result<(), String>

Restore self-model state from previously persisted JSON.

Unknown or malformed fields are skipped; partial state restores gracefully. Returns an error only if the top-level shape is wrong.

Trait Implementations§

Source§

impl Default for SelfModel

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.