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
.
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>
impl<const I: usize, const O: usize> NeuralNetworkTopology<I, O>
Sourcepub fn new(
mutation_rate: f32,
mutation_passes: usize,
rng: &mut impl Rng,
) -> Self
pub fn new( mutation_rate: f32, mutation_passes: usize, rng: &mut impl Rng, ) -> Self
Creates a new NeuralNetworkTopology
.
Sourcepub fn add_connection(
&mut self,
from: NeuronLocation,
to: NeuronLocation,
weight: f32,
) -> bool
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.
Sourcepub fn get_neuron(&self, loc: NeuronLocation) -> Arc<RwLock<NeuronTopology>>
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.
Sourcepub fn rand_neuron(
&self,
rng: &mut impl Rng,
) -> (Arc<RwLock<NeuronTopology>>, NeuronLocation)
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> DivisionReproduction for NeuralNetworkTopology<I, O>
impl<const I: usize, const O: usize> DivisionReproduction for NeuralNetworkTopology<I, O>
Source§fn divide(&self, rng: &mut impl Rng) -> Self
fn divide(&self, rng: &mut impl Rng) -> Self
Source§impl<const I: usize, const O: usize> From<&NeuralNetworkTopology<I, O>> for NNTSerde<I, O>
Available on crate feature serde
only.
impl<const I: usize, const O: usize> From<&NeuralNetworkTopology<I, O>> for NNTSerde<I, O>
serde
only.