pub struct Neuron<T: Float> {
pub sum: T,
pub value: T,
pub activation_steepness: T,
pub activation_function: ActivationFunction,
pub connections: Vec<Connection<T>>,
pub is_bias: bool,
}Expand description
Represents a single neuron in the neural network
Fields§
§sum: TThe sum of inputs multiplied by weights
value: TThe output value after applying the activation function
activation_steepness: TThe steepness parameter for the activation function
activation_function: ActivationFunctionThe activation function to use
connections: Vec<Connection<T>>Incoming connections to this neuron
is_bias: boolWhether this is a bias neuron
Implementations§
Source§impl<T: Float> Neuron<T>
impl<T: Float> Neuron<T>
Sourcepub fn new(
activation_function: ActivationFunction,
activation_steepness: T,
) -> Self
pub fn new( activation_function: ActivationFunction, activation_steepness: T, ) -> Self
Creates a new neuron with the specified activation function and steepness
§Arguments
activation_function- The activation function to useactivation_steepness- The steepness parameter for the activation function
§Example
use ruv_fann::{Neuron, ActivationFunction};
let neuron = Neuron::<f32>::new(ActivationFunction::Sigmoid, 1.0);
assert_eq!(neuron.activation_function, ActivationFunction::Sigmoid);Sourcepub fn add_connection(&mut self, from_neuron: usize, weight: T)
pub fn add_connection(&mut self, from_neuron: usize, weight: T)
Adds a connection from another neuron to this neuron
§Arguments
from_neuron- Index of the source neuronweight- Initial weight of the connection
Sourcepub fn clear_connections(&mut self)
pub fn clear_connections(&mut self)
Clears all connections
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the neuron’s sum and value to zero (except for bias neurons which maintain value = 1.0)
Sourcepub fn calculate(&mut self, inputs: &[T])
pub fn calculate(&mut self, inputs: &[T])
Calculates the neuron’s output based on inputs and weights
§Arguments
inputs- Values from neurons in the previous layer
Sourcepub fn set_value(&mut self, value: T)
pub fn set_value(&mut self, value: T)
Sets the neuron’s output value directly (used for input neurons)
Sourcepub fn get_connection_weight(&self, index: usize) -> Option<T>
pub fn get_connection_weight(&self, index: usize) -> Option<T>
Gets the weight of a specific connection by index
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Neuron<T>where
T: Deserialize<'de> + Float,
impl<'de, T> Deserialize<'de> for Neuron<T>where
T: Deserialize<'de> + Float,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for Neuron<T>where
T: Freeze,
impl<T> RefUnwindSafe for Neuron<T>where
T: RefUnwindSafe,
impl<T> Send for Neuron<T>where
T: Send,
impl<T> Sync for Neuron<T>where
T: Sync,
impl<T> Unpin for Neuron<T>where
T: Unpin,
impl<T> UnwindSafe for Neuron<T>where
T: UnwindSafe,
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more