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§
Trait Implementations§
Source§impl<T: Float> Function<T> for SoftMax
impl<T: Float> Function<T> for SoftMax
Source§fn derivative(&self, matrix: Matrix<T>) -> Matrix<T>
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
fn name(&self) -> String
Source§fn call(&self, matrix: Matrix<T>) -> Matrix<T>
fn call(&self, matrix: Matrix<T>) -> Matrix<T>
Applies the function to the input matrix. Read more
fn is_linear(&self) -> bool
fn get_data(&self) -> Option<Matrix<T>>
fn set_data(&mut self, _data: Matrix<T>)
fn get_weights(&self) -> Option<Matrix<T>>
fn get_bias(&self) -> Option<Matrix<T>>
fn is_bias(&self) -> bool
Auto Trait Implementations§
impl Freeze for SoftMax
impl RefUnwindSafe for SoftMax
impl Send for SoftMax
impl Sync for SoftMax
impl Unpin for SoftMax
impl UnwindSafe for SoftMax
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> 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