Skip to main content

Perceptron

Struct Perceptron 

Source
pub struct Perceptron {
    pub weights: Vec<f64>,
    pub bias: f64,
    pub mistakes: usize,
}
Expand description

Online Perceptron classifier.

Fields§

§weights: Vec<f64>

Weight vector w ∈ ℝ^d.

§bias: f64

Bias term b.

§mistakes: usize

Number of mistakes made so far.

Implementations§

Source§

impl Perceptron

Source

pub fn new(dim: usize) -> Self

Create a new zero-initialized Perceptron.

Source

pub fn predict(&self, x: &[f64]) -> f64

Predict the label for input x: sign(w·x + b).

Source

pub fn update(&mut self, x: &[f64], label: f64) -> bool

Online update: if prediction wrong, w ← w + y·x, b ← b + y.

Source

pub fn mistake_bound(radius: f64, margin: f64) -> usize

Perceptron mistake bound: M ≤ (R/γ)² where R = radius, γ = margin.

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> 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, 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.