pub struct Perceptron<const N: usize> { /* private fields */ }Expand description
Perceptron
This is a single perceptron implementation. It contains weights, bias and an activation function. You can use this struct and its methods to create, manipulate and even implement your ways to train a perceptron (find the weights).
§Example
use only_brain::Perceptron;
use only_brain::ActivationFunction;
use only_brain::bvector;
fn main() {
let mut perceptron = Perceptron::<2>::new(ActivationFunction::Sigmoid);
perceptron.set_weights(bvector![0.5, -0.2]);
perceptron.set_bias(0.3);
println!("{}", perceptron);
let inputs = bvector![0.6, 0.4];
let output = perceptron.feed_forward(&inputs);
println!("Output: {}", output);
}Implementations§
Source§impl<const N: usize> Perceptron<N>
impl<const N: usize> Perceptron<N>
pub fn new(activation_function: ActivationFunction) -> Self
pub fn set_weights(&mut self, weights: BVector<f64, N>)
pub fn set_bias(&mut self, bias: f64)
pub fn feed_forward(&self, inputs: &BVector<f64, N>) -> f64
Trait Implementations§
Source§impl<const N: usize> Clone for Perceptron<N>
impl<const N: usize> Clone for Perceptron<N>
Source§impl<const N: usize> Debug for Perceptron<N>
impl<const N: usize> Debug for Perceptron<N>
Source§impl<const N: usize> Display for Perceptron<N>
impl<const N: usize> Display for Perceptron<N>
Source§impl<const N: usize> PartialEq for Perceptron<N>
impl<const N: usize> PartialEq for Perceptron<N>
impl<const N: usize> StructuralPartialEq for Perceptron<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for Perceptron<N>
impl<const N: usize> RefUnwindSafe for Perceptron<N>
impl<const N: usize> Send for Perceptron<N>
impl<const N: usize> Sync for Perceptron<N>
impl<const N: usize> Unpin for Perceptron<N>
impl<const N: usize> UnsafeUnpin for Perceptron<N>
impl<const N: usize> UnwindSafe for Perceptron<N>
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,
impl<T> Scalar for T
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.