ContinualMetaLearner

Struct ContinualMetaLearner 

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

Continual meta-learning with memory

Implementations§

Source§

impl ContinualMetaLearner

Source

pub fn new( meta_learner: QuantumMetaLearner, memory_capacity: usize, replay_ratio: f64, ) -> Self

Create new continual meta-learner

Examples found in repository?
examples/quantum_meta_learning.rs (lines 314-318)
297fn continual_meta_learning_demo() -> Result<()> {
298    let layers = vec![
299        QNNLayerType::EncodingLayer { num_features: 4 },
300        QNNLayerType::VariationalLayer { num_params: 8 },
301        QNNLayerType::MeasurementLayer {
302            measurement_basis: "computational".to_string(),
303        },
304    ];
305
306    let qnn = QuantumNeuralNetwork::new(layers, 4, 4, 2)?;
307
308    let algorithm = MetaLearningAlgorithm::Reptile {
309        inner_steps: 5,
310        inner_lr: 0.05,
311    };
312
313    let meta_learner = QuantumMetaLearner::new(algorithm, qnn);
314    let mut continual_learner = ContinualMetaLearner::new(
315        meta_learner,
316        10,  // memory capacity
317        0.3, // replay ratio
318    );
319
320    println!("   Created Continual Meta-Learner:");
321    println!("   - Memory capacity: 10 tasks");
322    println!("   - Replay ratio: 30%");
323
324    // Generate sequence of tasks
325    let generator = TaskGenerator::new(4, 2);
326
327    println!("\n   Learning sequence of tasks...");
328    for i in 0..20 {
329        let task = if i < 10 {
330            generator.generate_rotation_task(30)
331        } else {
332            generator.generate_sinusoid_task(30)
333        };
334
335        continual_learner.learn_task(task)?;
336
337        if i % 5 == 4 {
338            println!(
339                "   Learned {} tasks, memory contains {} unique tasks",
340                i + 1,
341                continual_learner.memory_buffer_len()
342            );
343        }
344    }
345
346    println!("\n   Continual learning prevents catastrophic forgetting");
347
348    Ok(())
349}
Source

pub fn learn_task(&mut self, new_task: MetaTask) -> Result<()>

Learn new task while preserving old knowledge

Examples found in repository?
examples/quantum_meta_learning.rs (line 335)
297fn continual_meta_learning_demo() -> Result<()> {
298    let layers = vec![
299        QNNLayerType::EncodingLayer { num_features: 4 },
300        QNNLayerType::VariationalLayer { num_params: 8 },
301        QNNLayerType::MeasurementLayer {
302            measurement_basis: "computational".to_string(),
303        },
304    ];
305
306    let qnn = QuantumNeuralNetwork::new(layers, 4, 4, 2)?;
307
308    let algorithm = MetaLearningAlgorithm::Reptile {
309        inner_steps: 5,
310        inner_lr: 0.05,
311    };
312
313    let meta_learner = QuantumMetaLearner::new(algorithm, qnn);
314    let mut continual_learner = ContinualMetaLearner::new(
315        meta_learner,
316        10,  // memory capacity
317        0.3, // replay ratio
318    );
319
320    println!("   Created Continual Meta-Learner:");
321    println!("   - Memory capacity: 10 tasks");
322    println!("   - Replay ratio: 30%");
323
324    // Generate sequence of tasks
325    let generator = TaskGenerator::new(4, 2);
326
327    println!("\n   Learning sequence of tasks...");
328    for i in 0..20 {
329        let task = if i < 10 {
330            generator.generate_rotation_task(30)
331        } else {
332            generator.generate_sinusoid_task(30)
333        };
334
335        continual_learner.learn_task(task)?;
336
337        if i % 5 == 4 {
338            println!(
339                "   Learned {} tasks, memory contains {} unique tasks",
340                i + 1,
341                continual_learner.memory_buffer_len()
342            );
343        }
344    }
345
346    println!("\n   Continual learning prevents catastrophic forgetting");
347
348    Ok(())
349}
Source

pub fn memory_buffer_len(&self) -> usize

Get memory buffer length

Examples found in repository?
examples/quantum_meta_learning.rs (line 341)
297fn continual_meta_learning_demo() -> Result<()> {
298    let layers = vec![
299        QNNLayerType::EncodingLayer { num_features: 4 },
300        QNNLayerType::VariationalLayer { num_params: 8 },
301        QNNLayerType::MeasurementLayer {
302            measurement_basis: "computational".to_string(),
303        },
304    ];
305
306    let qnn = QuantumNeuralNetwork::new(layers, 4, 4, 2)?;
307
308    let algorithm = MetaLearningAlgorithm::Reptile {
309        inner_steps: 5,
310        inner_lr: 0.05,
311    };
312
313    let meta_learner = QuantumMetaLearner::new(algorithm, qnn);
314    let mut continual_learner = ContinualMetaLearner::new(
315        meta_learner,
316        10,  // memory capacity
317        0.3, // replay ratio
318    );
319
320    println!("   Created Continual Meta-Learner:");
321    println!("   - Memory capacity: 10 tasks");
322    println!("   - Replay ratio: 30%");
323
324    // Generate sequence of tasks
325    let generator = TaskGenerator::new(4, 2);
326
327    println!("\n   Learning sequence of tasks...");
328    for i in 0..20 {
329        let task = if i < 10 {
330            generator.generate_rotation_task(30)
331        } else {
332            generator.generate_sinusoid_task(30)
333        };
334
335        continual_learner.learn_task(task)?;
336
337        if i % 5 == 4 {
338            println!(
339                "   Learned {} tasks, memory contains {} unique tasks",
340                i + 1,
341                continual_learner.memory_buffer_len()
342            );
343        }
344    }
345
346    println!("\n   Continual learning prevents catastrophic forgetting");
347
348    Ok(())
349}

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Ungil for T
where T: Send,