Skip to main content

StreamingEWC

Struct StreamingEWC 

Source
pub struct StreamingEWC { /* private fields */ }
Available on crate feature alloc only.
Expand description

Streaming EWC: prevents catastrophic forgetting via Fisher regularization.

Maintains a diagonal Fisher Information Matrix as an exponential moving average of squared gradients. When drift is detected, the anchor point (parameter snapshot) shifts, allowing adaptation to the new regime while preserving knowledge of the old.

§Example

use irithyll_core::continual::{StreamingEWC, ContinualStrategy};
use irithyll_core::drift::DriftSignal;

let mut ewc = StreamingEWC::with_defaults(4);
let params = vec![1.0, 2.0, 3.0, 4.0];
ewc.set_anchor(&params);

let mut grads = vec![0.1, -0.2, 0.3, -0.4];
ewc.pre_update(&params, &mut grads);
// Gradients are modified by EWC penalty toward anchor

Implementations§

Source§

impl StreamingEWC

Source

pub fn new(n_params: usize, ewc_lambda: f64, fisher_alpha: f64) -> Self

Create a new StreamingEWC with explicit hyperparameters.

§Arguments
  • n_params – number of parameters to protect
  • ewc_lambda – regularization strength; higher = stronger memory
  • fisher_alpha – EWMA decay for Fisher; closer to 1.0 = longer memory
§Panics

Panics if fisher_alpha is not in [0.0, 1.0].

Source

pub fn with_defaults(n_params: usize) -> Self

Create a new StreamingEWC with default hyperparameters.

Defaults: ewc_lambda = 1.0, fisher_alpha = 0.99.

Source

pub fn fisher(&self) -> &[f64]

Current diagonal Fisher information.

Source

pub fn anchor(&self) -> &[f64]

Current anchor parameters.

Source

pub fn ewc_lambda(&self) -> f64

Current EWC regularization strength.

Source

pub fn n_updates(&self) -> u64

Number of updates processed.

Source

pub fn is_initialized(&self) -> bool

Whether the anchor has been initialized.

Source

pub fn set_anchor(&mut self, params: &[f64])

Manually set the anchor to a parameter snapshot.

§Panics

Panics if params.len() != n_params().

Source

pub fn penalty(&self, params: &[f64]) -> f64

Compute the EWC penalty value for given parameters.

Returns (ewc_lambda / 2) * sum_i F_i * (theta_i - anchor_i)^2.

Returns 0.0 if the anchor has not been set.

Trait Implementations§

Source§

impl ContinualStrategy for StreamingEWC

Source§

fn pre_update(&mut self, params: &[f64], gradients: &mut [f64])

Modify gradients before weight update. Called before each parameter update. params = current parameter values, gradients = computed gradients (modified in-place).
Source§

fn post_update(&mut self, _params: &[f64])

Called after weight update with the new parameter values.
Source§

fn on_drift(&mut self, params: &[f64], signal: DriftSignal)

React to a drift signal. E.g., update anchor point, recompute masks.
Source§

fn n_params(&self) -> usize

Number of parameters this strategy covers.
Source§

fn reset(&mut self)

Reset to initial state.

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 = 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.