pub struct ExpressionTree { /* private fields */ }Expand description
A decoded expression tree stored in level-order (breadth-first) layout.
The coding prefix of a chromosome decodes to this structure (see
GepDecoder). Nodes are held in BFS order, so every
node’s children occupy a contiguous, strictly-higher index range. That lets
evaluation run as a single right-to-left sweep: when a parent is reached,
its children (higher indices) have already been computed.
Implementations§
Source§impl ExpressionTree
impl ExpressionTree
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of coding nodes (the open-reading-frame length).
Sourcepub fn nodes(&self) -> &[Symbol]
pub fn nodes(&self) -> &[Symbol]
Symbols in level order (root first). Primarily for tests/inspection.
Sourcepub fn depth(&self) -> usize
pub fn depth(&self) -> usize
Tree depth: edges on the longest root-to-leaf path (a single-node tree has depth 0). A bloat metric.
Sourcepub fn eval<F: FunctionSet>(
&self,
alphabet: &Alphabet<F>,
inputs: &[f32],
) -> f32
pub fn eval<F: FunctionSet>( &self, alphabet: &Alphabet<F>, inputs: &[f32], ) -> f32
Evaluates the tree on one input row.
Variable nodes resolve to inputs[input_index] (missing indices read as
0.0); constant nodes resolve to their stored value; function nodes call
FunctionSet::apply with their
children’s already-computed results, then sanitize the result via
finite_or_clamp: a NaN collapses to 0.0 (it has no meaningful
sign or magnitude), while ±Inf clamps to ±EVAL_CLAMP (sign
preserved). Clamping — rather than zeroing — a diverged (±Inf) subtree
keeps its magnitude large, so it yields a large MSE and ranks worst
instead of masquerading as a perfect 0.0 predictor near zero-valued
targets (GEP finding tree.rs §1.2). This differs from the CGP evaluator’s
finite_or_zero rule, which zeros both.
alphabet must be the same one the tree was decoded with.
Trait Implementations§
Source§impl Clone for ExpressionTree
impl Clone for ExpressionTree
Source§fn clone(&self) -> ExpressionTree
fn clone(&self) -> ExpressionTree
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ExpressionTree
impl RefUnwindSafe for ExpressionTree
impl Send for ExpressionTree
impl Sync for ExpressionTree
impl Unpin for ExpressionTree
impl UnsafeUnpin for ExpressionTree
impl UnwindSafe for ExpressionTree
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<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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