Op

Enum Op 

Source
pub enum Op<T> {
    Fn(&'static str, Arity, fn(&[T]) -> T),
    Var(&'static str, usize),
    Const(&'static str, T),
    MutableConst {
        name: &'static str,
        arity: Arity,
        value: T,
        supplier: fn() -> T,
        modifier: fn(&T) -> T,
        operation: fn(&[T], &T) -> T,
    },
}
Expand description

Op is an enumeration that represents the different types of operations that can be performed within the genetic programming framework. Each variant of the enum encapsulates a different kind of operation, allowing for a flexible and extensible way to define the behavior of nodes within trees and graphs.

The Op heavilty depends on it’s Arity to define how many inputs it expects. This is crucial for ensuring that the operations receive the correct number of inputs and that the structures built using these operations are built in ways that respect these input requirements. For example, an addition operation would typically have an arity of 2, while a constant operation would have an arity of 0. This is the base level of the GP system, meaning that everything built on top of it (trees, graphs, etc.) will relies heavily on how these operations are defined and used.

Variants§

§

Fn(&'static str, Arity, fn(&[T]) -> T)

  1. A stateless function operation:

§Arguments

  • A &'static str name (e.g., “Add”, “Sigmoid”)
  • Arity (how many inputs it takes)
  • Arc<dyn Fn(&\[T\]) -> T> for the actual function logic
§

Var(&'static str, usize)

  1. A variable-like operation:

§Arguments

  • String = a name or identifier
  • usize = an index to retrieve from some external context
§

Const(&'static str, T)

  1. A compile-time constant: e.g., 1, 2, 3, etc.

§Arguments

  • &'static str name
  • T the actual constant value
§

MutableConst

  1. A mutable const is a constant that can change over time:

§Arguments

  • &'static str name

  • Arity of how many inputs it might read

  • Current value of type T

  • An Arc<dyn Fn() -> T> for retrieving (or resetting) the value

  • An Arc<dyn Fn(&[T], &T) -> T> for updating or combining inputs & old value -> new value

    This suggests a node that can mutate its internal state over time, or one that needs a special function to incorporate the inputs into the next state.

Fields

§name: &'static str
§arity: Arity
§value: T
§supplier: fn() -> T
§modifier: fn(&T) -> T
§operation: fn(&[T], &T) -> T

Implementations§

Source§

impl Op<bool>

Source

pub fn and() -> Self

Source

pub fn or() -> Self

Source

pub fn not() -> Self

Source

pub fn xor() -> Self

Source

pub fn eq() -> Self

Source

pub fn ne() -> Self

Source

pub fn gt() -> Self

Source

pub fn ge() -> Self

Source

pub fn lt() -> Self

Source

pub fn le() -> Self

Source

pub fn if_else() -> Self

Source

pub fn and_then() -> Self

Source

pub fn or_else() -> Self

Source

pub fn nand() -> Self

Source

pub fn nor() -> Self

Source

pub fn xnor() -> Self

Source

pub fn implies() -> Self

Source

pub fn iff() -> Self

Source§

impl Op<f32>

Source

pub fn weight() -> Self

Source

pub fn weight_with(value: f32) -> Self

Source

pub fn add() -> Self

Source

pub fn sub() -> Self

Source

pub fn mul() -> Self

Source

pub fn div() -> Self

Source

pub fn sum() -> Self

Source

pub fn diff() -> Self

Source

pub fn prod() -> Self

Source

pub fn neg() -> Self

Source

pub fn pow() -> Self

Source

pub fn sqrt() -> Self

Source

pub fn abs() -> Self

Source

pub fn exp() -> Self

Source

pub fn log() -> Self

Source

pub fn sin() -> Self

Source

pub fn cos() -> Self

Source

pub fn max() -> Self

Source

pub fn min() -> Self

Source

pub fn tan() -> Self

Source

pub fn ceil() -> Self

Source

pub fn floor() -> Self

Source

pub fn sigmoid() -> Self

Source

pub fn tanh() -> Self

Source

pub fn relu() -> Self

Source

pub fn leaky_relu() -> Self

Source

pub fn elu() -> Self

Source

pub fn linear() -> Self

Source

pub fn mish() -> Self

Source

pub fn swish() -> Self

Source

pub fn softplus() -> Self

Source§

impl<T> Op<T>

Source

pub fn name(&self) -> &str

Source

pub fn arity(&self) -> Arity

Source

pub fn is_fn(&self) -> bool

Source

pub fn is_var(&self) -> bool

Source

pub fn is_const(&self) -> bool

Source

pub fn is_mutable_const(&self) -> bool

Source§

impl<T> Op<T>

Source

pub fn var(index: usize) -> Self

Source

pub fn vars(range: Range<usize>) -> Vec<Self>

Source

pub fn constant(value: T) -> Self
where T: Display,

Source

pub fn named_constant(name: &'static str, value: T) -> Self

Source

pub fn identity() -> Self
where T: Clone,

Trait Implementations§

Source§

impl<T> Clone for Op<T>
where T: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Op<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Op<T>
where T: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Display for Op<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Eval<[T], T> for Op<T>
where T: Clone,

Source§

fn eval(&self, inputs: &[T]) -> T

Source§

impl<T> Factory<(), Op<T>> for Op<T>
where T: Clone,

Source§

fn new_instance(&self, _: ()) -> Op<T>

Source§

impl<T: Clone> From<Op<T>> for NodeStore<Op<T>>

Source§

fn from(value: Op<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Op<T>> for NodeValue<Op<T>>

Source§

fn from(value: Op<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Op<T>> for TreeNode<Op<T>>

Source§

fn from(value: Op<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Op<T>> for Vec<TreeNode<Op<T>>>

Source§

fn from(value: Op<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Hash for Op<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> PartialEq for Op<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TreeRewriterRule<Op<f32>> for OpTreeRewriteRule<f32>

Source§

fn apply<'a>(&self, node: &'a mut TreeNode<Op<f32>>) -> bool

Source§

impl<T> Send for Op<T>

Source§

impl<T> Sync for Op<T>

Auto Trait Implementations§

§

impl<T> Freeze for Op<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Op<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Op<T>
where T: Unpin,

§

impl<T> UnwindSafe for Op<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<I, O, T> EvalMut<I, O> for T
where T: Eval<I, O>, I: ?Sized,

Source§

fn eval_mut(&mut self, input: &I) -> O

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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