pub struct ModuleEvalFn<B: Backend, R: ParamReshaper<B>, F> { /* private fields */ }Expand description
Bridges a flat population tensor to per-member module scoring.
Implements BatchFitnessFn<B, Tensor<B, 2>>: each row of the
(pop_size, num_params) population is unflattened into a module via the
ParamReshaper, passed to a host-side scorer, and the resulting scalar
is collected into the fitness tensor in the scorer’s natural value
space. Direction is declared once via ObjectiveSense (default
ObjectiveSense::Maximize; pass with_sense
for a cost scorer like MSE) and reconciled by the harness — no hand-negation
in the scorer.
§Gradient isolation
B: Backend, not AutodiffBackend. The reconstructed modules carry no
gradient tracking — scorer performs forward-only work (loss, rollout
return, …).
§Type Parameters
R: aParamReshaperproducingR::Module.F: a host-sideFn(&R::Module) -> f32scorer (MSE, accuracy, negative episode return, …).
§Device convention
Population rows are sliced on the supplied device; the reshaper splats
them into modules on that same device. Callers must construct the
population and the reshaper’s template on one device.
Implementations§
Source§impl<B, R, F> ModuleEvalFn<B, R, F>
impl<B, R, F> ModuleEvalFn<B, R, F>
Sourcepub fn new(reshaper: R, scorer: F) -> Self
pub fn new(reshaper: R, scorer: F) -> Self
Build an evaluator from a reshaper and a per-module scorer, defaulting
the objective sense to ObjectiveSense::Maximize (accuracy, reward,
episode return). Use with_sense for a cost scorer
such as MSE.
Sourcepub fn with_sense(reshaper: R, scorer: F, sense: ObjectiveSense) -> Self
pub fn with_sense(reshaper: R, scorer: F, sense: ObjectiveSense) -> Self
Build an evaluator with an explicit ObjectiveSense.
Trait Implementations§
Source§impl<B, R, F> BatchFitnessFn<B, Tensor<B, 2>> for ModuleEvalFn<B, R, F>
impl<B, R, F> BatchFitnessFn<B, Tensor<B, 2>> for ModuleEvalFn<B, R, F>
Source§fn evaluate_batch(
&mut self,
population: &Tensor<B, 2>,
device: &B::Device,
) -> Tensor<B, 1>
fn evaluate_batch( &mut self, population: &Tensor<B, 2>, device: &B::Device, ) -> Tensor<B, 1>
Score every row of population by reconstructing one module per row.
§Panics
Panics at batch entry if the population width (population.dims()[1])
differs from the reshaper’s num_params,
failing fast before any per-row work rather than mid-loop inside
ParamReshaper::unflatten.
Source§fn sense(&self) -> ObjectiveSense
fn sense(&self) -> ObjectiveSense
Auto Trait Implementations§
impl<B, R, F> Freeze for ModuleEvalFn<B, R, F>
impl<B, R, F> RefUnwindSafe for ModuleEvalFn<B, R, F>where
R: RefUnwindSafe,
F: RefUnwindSafe,
impl<B, R, F> Send for ModuleEvalFn<B, R, F>where
F: Send,
impl<B, R, F> Sync for ModuleEvalFn<B, R, F>where
F: Sync,
impl<B, R, F> Unpin for ModuleEvalFn<B, R, F>
impl<B, R, F> UnsafeUnpin for ModuleEvalFn<B, R, F>where
R: UnsafeUnpin,
F: UnsafeUnpin,
impl<B, R, F> UnwindSafe for ModuleEvalFn<B, R, F>where
R: UnwindSafe,
F: 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
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>
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>
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