pub struct NeuralNetwork {
pub genome: EneCode,
pub graph: DiGraph<Nn, f32>,
pub node_identity_map: HashMap<String, NodeIndex>,
/* private fields */
}Expand description
NeuralNetwork is a struct that represents a directed graph
based feed-forward neural network, initialized from an EneCode genome.
The struct encapsulates the genome (genetic blueprint), graph-based network, node-identity mapping, and network output.
§Fields
genome- The genetic blueprint (EneCode) of the neural network.graph- The directed graph (DiGraph) frompetgraphthat represents the network.node_identity_map- A HashMap mapping each neuron ID (String) to its index (NodeIndex) in the graph.network_output- A vector holding the output values of the output neurons.
§Example Usage
use evo_rl::graph::NeuralNetwork;
use evo_rl::enecode::EneCode;
// Assume genome is a properly initialized EneCode
let mut network = NeuralNetwork::new(genome);
// Assume input is a properly initialized Vec<f32>
network.fwd(input);
let output = network.fetch_network_output();Fields§
§genome: EneCode§graph: DiGraph<Nn, f32>§node_identity_map: HashMap<String, NodeIndex>Implementations§
Source§impl NeuralNetwork
impl NeuralNetwork
Sourcepub fn serialize_genome(&self) -> String
pub fn serialize_genome(&self) -> String
Returns serialized representation of genome
Sourcepub fn recombine_enecode<R: Rng>(
&self,
rng: &mut R,
partner: &NeuralNetwork,
) -> Result<EneCode, GraphConstructionError>
pub fn recombine_enecode<R: Rng>( &self, rng: &mut R, partner: &NeuralNetwork, ) -> Result<EneCode, GraphConstructionError>
Cross over recombination of genetic code
Sourcepub fn mutate(
&mut self,
mutation_rate: f32,
mutation_sd: f32,
topology_mutation_rate: f32,
)
pub fn mutate( &mut self, mutation_rate: f32, mutation_sd: f32, topology_mutation_rate: f32, )
Run mutation for this network
pub fn transfer(self) -> Self
Sourcepub fn fwd(&mut self, input: Vec<f32>)
pub fn fwd(&mut self, input: Vec<f32>)
Forward propagate through the neural network. This function takes a vector of input values and populates the network output.
Sourcepub fn fetch_network_output(&self) -> Vec<f32>
pub fn fetch_network_output(&self) -> Vec<f32>
Fetch the output of the network as a vector of floating-point numbers.
Trait Implementations§
Source§impl Clone for NeuralNetwork
impl Clone for NeuralNetwork
Source§fn clone(&self) -> NeuralNetwork
fn clone(&self) -> NeuralNetwork
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NeuralNetwork
impl Debug for NeuralNetwork
Source§impl From<&NeuralNetwork> for EneCode
Creates genome from neural network after recombination and mutation
impl From<&NeuralNetwork> for EneCode
Creates genome from neural network after recombination and mutation
Source§fn from(network: &NeuralNetwork) -> Self
fn from(network: &NeuralNetwork) -> Self
Converts to this type from the input type.
Source§impl ToPyObject for NeuralNetwork
impl ToPyObject for NeuralNetwork
Auto Trait Implementations§
impl Freeze for NeuralNetwork
impl RefUnwindSafe for NeuralNetwork
impl Send for NeuralNetwork
impl Sync for NeuralNetwork
impl Unpin for NeuralNetwork
impl UnwindSafe for NeuralNetwork
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.