Struct SoftMax

Source
pub struct SoftMax;
Expand description

Softmax function (normalized exponential function).

Converts a vector of K real numbers into a probability distribution of K possible outcomes. The output values are in the range [0, 1] and sum to 1.

§Mathematical Definition

For an input vector x, the Softmax function is defined as:

\text{Softmax}(x_i) = \frac{e^{x_i}}{\sum_{j=1}^{K} e^{x_j}}

§Examples

use tensorrs::activation::{Function, SoftMax};
use tensorrs::linalg::Matrix;
use tensorrs::matrix;

let softmax = SoftMax::new();
let input = matrix![[1.0, 2.0, 3.0]];
let output = softmax.call(input);
println!("Softmax output: {}", output);
//[{0.09003057 0.24472848 0.66524094},
// {0.090030566 0.24472846 0.66524094}]

§See Also

Implementations§

Source§

impl SoftMax

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl<T: Float> Function<T> for SoftMax

Source§

fn derivative(&self, matrix: Matrix<T>) -> Matrix<T>

$Softmax'(x_i)= Softmax(x_i) * (δ_{ij} - Softmax(x_j))$

$δ_{ij}$ - the Kronecker symbol, which is 1 when i = j, and 0 otherwise

WARNING UNTESTED WELL AND DO NOT WORK NORMAL

Source§

fn name(&self) -> String

Source§

fn call(&self, matrix: Matrix<T>) -> Matrix<T>

Applies the function to the input matrix. Read more
Source§

fn is_linear(&self) -> bool

Source§

fn get_data(&self) -> Option<Matrix<T>>

Source§

fn set_data(&mut self, _data: Matrix<T>)

Source§

fn get_weights(&self) -> Option<Matrix<T>>

Source§

fn get_bias(&self) -> Option<Matrix<T>>

Source§

fn is_bias(&self) -> bool

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

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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