Struct NeuralNetworkTopology

Source
pub struct NeuralNetworkTopology<const I: usize, const O: usize> {
    pub input_layer: [Arc<RwLock<NeuronTopology>>; I],
    pub hidden_layers: Vec<Arc<RwLock<NeuronTopology>>>,
    pub output_layer: [Arc<RwLock<NeuronTopology>>; O],
    pub mutation_rate: f32,
    pub mutation_passes: usize,
}
Expand description

A stateless neural network topology. This is the struct you want to use in your agent’s inheritance. See NeuralNetwork::from for how to convert this to a runnable neural network.

Fields§

§input_layer: [Arc<RwLock<NeuronTopology>>; I]

The input layer of the neural network. Uses a fixed length of I.

§hidden_layers: Vec<Arc<RwLock<NeuronTopology>>>

The hidden layers of the neural network. Because neurons have a flexible connection system, all of them exist in the same flat vector.

§output_layer: [Arc<RwLock<NeuronTopology>>; O]

The output layer of the neural netowrk. Uses a fixed length of O.

§mutation_rate: f32

The mutation rate used in NeuralNetworkTopology::mutate after crossover/division.

§mutation_passes: usize

The number of mutation passes (and thus, maximum number of possible mutations that can occur for each entity in the generation).

Implementations§

Source§

impl<const I: usize, const O: usize> NeuralNetworkTopology<I, O>

Source

pub fn new( mutation_rate: f32, mutation_passes: usize, rng: &mut impl Rng, ) -> Self

Creates a new NeuralNetworkTopology.

Source

pub fn add_connection( &mut self, from: NeuronLocation, to: NeuronLocation, weight: f32, ) -> bool

Creates a new connection between the neurons. If the connection is cyclic, it does not add a connection and returns false. Otherwise, it returns true.

Source

pub fn get_neuron(&self, loc: NeuronLocation) -> Arc<RwLock<NeuronTopology>>

Gets a neuron pointer from a NeuronLocation. You shouldn’t ever need to directly call this unless you are doing complex custom mutations.

Source

pub fn rand_neuron( &self, rng: &mut impl Rng, ) -> (Arc<RwLock<NeuronTopology>>, NeuronLocation)

Gets a random neuron and its location.

Trait Implementations§

Source§

impl<const I: usize, const O: usize> Clone for NeuralNetworkTopology<I, O>

Source§

fn clone(&self) -> Self

Returns a copy 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<const I: usize, const O: usize> Debug for NeuralNetworkTopology<I, O>

Source§

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

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

impl<const I: usize, const O: usize> DivisionReproduction for NeuralNetworkTopology<I, O>

Source§

fn divide(&self, rng: &mut impl Rng) -> Self

Create a new child with mutation. Similar to RandomlyMutable::mutate, but returns a new instance instead of modifying the original. If it is simply returning a cloned and mutated version, consider using a constant mutation rate.
Source§

impl<const I: usize, const O: usize> From<&NeuralNetworkTopology<I, O>> for NNTSerde<I, O>

Available on crate feature serde only.
Source§

fn from(value: &NeuralNetworkTopology<I, O>) -> Self

Converts to this type from the input type.
Source§

impl<const I: usize, const O: usize> From<&NeuralNetworkTopology<I, O>> for NeuralNetwork<I, O>

Source§

fn from(value: &NeuralNetworkTopology<I, O>) -> Self

Converts to this type from the input type.
Source§

impl<const I: usize, const O: usize> From<NNTSerde<I, O>> for NeuralNetworkTopology<I, O>

Source§

fn from(value: NNTSerde<I, O>) -> Self

Converts to this type from the input type.
Source§

impl<const I: usize, const O: usize> PartialEq for NeuralNetworkTopology<I, O>

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<const I: usize, const O: usize> RandomlyMutable for NeuralNetworkTopology<I, O>

Source§

fn mutate(&mut self, rate: f32, rng: &mut impl Rng)

Mutate the genome with a given mutation rate (0..1)

Auto Trait Implementations§

§

impl<const I: usize, const O: usize> Freeze for NeuralNetworkTopology<I, O>

§

impl<const I: usize, const O: usize> RefUnwindSafe for NeuralNetworkTopology<I, O>

§

impl<const I: usize, const O: usize> Send for NeuralNetworkTopology<I, O>

§

impl<const I: usize, const O: usize> Sync for NeuralNetworkTopology<I, O>

§

impl<const I: usize, const O: usize> Unpin for NeuralNetworkTopology<I, O>

§

impl<const I: usize, const O: usize> UnwindSafe for NeuralNetworkTopology<I, O>

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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, 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