pub struct WeightOnly<B, S, M>{ /* private fields */ }Expand description
Composes a flat-genome Strategy with a fixed-topology Burn Module.
§Type Parameters
B: Burn backend (non-autodiff — see module docs).S: inner strategy withGenome = Tensor<B, 2>(GA, ES, DE, …).M: the network whose weights are evolved.
§Example
ⓘ
let template = MyMlp::<B>::new(&device);
let strategy = WeightOnly::new(GeneticAlgorithm::<B>::new(), template.clone());
let params = GaConfig::default_for(64, strategy.num_params());
// pair with a ModuleEvalFn over the same template in the harnessImplementations§
Source§impl<B, S, M> WeightOnly<B, S, M>
impl<B, S, M> WeightOnly<B, S, M>
Sourcepub fn new(inner: S, template: M) -> Self
pub fn new(inner: S, template: M) -> Self
Build a wrapper from an inner strategy and a template module.
The template is cloned into a ModuleReshaper; its float-leaf count
becomes num_params, which must equal the inner
strategy’s configured genome width.
Sourcepub fn num_params(&self) -> usize
pub fn num_params(&self) -> usize
Genome width — the number of float parameters in the template module.
Sourcepub fn reshaper(&self) -> &ModuleReshaper<B, M>
pub fn reshaper(&self) -> &ModuleReshaper<B, M>
Borrow the owned reshaper (e.g. to build a matching fitness adapter).
Trait Implementations§
Source§impl<B, S, M> Debug for WeightOnly<B, S, M>
impl<B, S, M> Debug for WeightOnly<B, S, M>
Source§impl<B, S, M> Strategy<B> for WeightOnly<B, S, M>
impl<B, S, M> Strategy<B> for WeightOnly<B, S, M>
Source§fn init(
&self,
params: &Self::Params,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> Self::State
fn init( &self, params: &Self::Params, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> Self::State
Pure delegation to the inner strategy’s init.
Source§fn ask(
&self,
params: &Self::Params,
state: &Self::State,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> (Self::Genome, Self::State)
fn ask( &self, params: &Self::Params, state: &Self::State, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (Self::Genome, Self::State)
Pure delegation to the inner strategy’s ask. No reshaping here — the
genome stays a flat (pop_size, num_params) tensor.
Source§fn tell(
&self,
params: &Self::Params,
population: Self::Genome,
fitness: Tensor<B, 1>,
state: Self::State,
rng: &mut dyn Rng,
) -> (Self::State, StrategyMetrics)
fn tell( &self, params: &Self::Params, population: Self::Genome, fitness: Tensor<B, 1>, state: Self::State, rng: &mut dyn Rng, ) -> (Self::State, StrategyMetrics)
Pure delegation to the inner strategy’s tell. Reshaping to a module
already happened in the fitness adapter that produced fitness.
Auto Trait Implementations§
impl<B, S, M> Freeze for WeightOnly<B, S, M>
impl<B, S, M> RefUnwindSafe for WeightOnly<B, S, M>where
S: RefUnwindSafe,
M: RefUnwindSafe,
impl<B, S, M> Send for WeightOnly<B, S, M>
impl<B, S, M> Sync for WeightOnly<B, S, M>where
M: Sync,
impl<B, S, M> Unpin for WeightOnly<B, S, M>
impl<B, S, M> UnsafeUnpin for WeightOnly<B, S, M>where
S: UnsafeUnpin,
M: UnsafeUnpin,
impl<B, S, M> UnwindSafe for WeightOnly<B, S, M>where
S: UnwindSafe,
M: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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