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(¶ms);
let mut grads = vec![0.1, -0.2, 0.3, -0.4];
ewc.pre_update(¶ms, &mut grads);
// Gradients are modified by EWC penalty toward anchorImplementations§
Source§impl StreamingEWC
impl StreamingEWC
Sourcepub fn with_defaults(n_params: usize) -> Self
pub fn with_defaults(n_params: usize) -> Self
Create a new StreamingEWC with default hyperparameters.
Defaults: ewc_lambda = 1.0, fisher_alpha = 0.99.
Sourcepub fn ewc_lambda(&self) -> f64
pub fn ewc_lambda(&self) -> f64
Current EWC regularization strength.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Whether the anchor has been initialized.
Sourcepub fn set_anchor(&mut self, params: &[f64])
pub fn set_anchor(&mut self, params: &[f64])
Trait Implementations§
Source§impl ContinualStrategy for StreamingEWC
impl ContinualStrategy for StreamingEWC
Source§fn pre_update(&mut self, params: &[f64], gradients: &mut [f64])
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])
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)
fn on_drift(&mut self, params: &[f64], signal: DriftSignal)
React to a drift signal. E.g., update anchor point, recompute masks.
Auto Trait Implementations§
impl Freeze for StreamingEWC
impl RefUnwindSafe for StreamingEWC
impl Send for StreamingEWC
impl Sync for StreamingEWC
impl Unpin for StreamingEWC
impl UnsafeUnpin for StreamingEWC
impl UnwindSafe for StreamingEWC
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
Mutably borrows from an owned value. Read more