NeuralNetwork

Struct NeuralNetwork 

Source
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) from petgraph that 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

Source

pub fn new(genome: EneCode) -> Self

Create a new NeuralNetwork from an EneCode genome.

Source

pub fn serialize_genome(&self) -> String

Returns serialized representation of genome

Source

pub fn recombine_enecode<R: Rng>( &self, rng: &mut R, partner: &NeuralNetwork, ) -> Result<EneCode, GraphConstructionError>

Cross over recombination of genetic code

Source

pub fn mutate( &mut self, mutation_rate: f32, mutation_sd: f32, topology_mutation_rate: f32, )

Run mutation for this network

Source

pub fn transfer(self) -> Self

Source

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.

Source

pub fn fetch_network_output(&self) -> Vec<f32>

Fetch the output of the network as a vector of floating-point numbers.

Source

pub fn write_dot(&self, file_path: &Path)

Write the graph as a .dot file for visualization/inspection

Trait Implementations§

Source§

impl Clone for NeuralNetwork

Source§

fn clone(&self) -> NeuralNetwork

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 Debug for NeuralNetwork

Source§

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

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

impl From<&NeuralNetwork> for EneCode

Creates genome from neural network after recombination and mutation

Source§

fn from(network: &NeuralNetwork) -> Self

Converts to this type from the input type.
Source§

impl ToPyObject for NeuralNetwork

Source§

fn to_object(&self, py: Python<'_>) -> PyObject

Converts self into a Python object.

Auto Trait Implementations§

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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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

Source§

impl<T> Ungil for T
where T: Send,