nabla_ml::nab_math

Struct NabMath

Source
pub struct NabMath;
Expand description

Mathematical functions for NDArray

Implementations§

Source§

impl NabMath

Source

pub fn sigmoid(x: &NDArray) -> NDArray

Computes the sigmoid function element-wise

sigmoid(x) = 1 / (1 + exp(-x))

§Arguments
  • x - Input NDArray
§Returns

NDArray with sigmoid applied element-wise

Source

pub fn sigmoid_derivative(x: &NDArray) -> NDArray

Computes the derivative of sigmoid function element-wise

sigmoid’(x) = sigmoid(x) * (1 - sigmoid(x))

§Arguments
  • x - Input NDArray
§Returns

NDArray with sigmoid derivative applied element-wise

Source

pub fn tanh(x: &NDArray) -> NDArray

Computes the hyperbolic tangent function element-wise

tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))

§Arguments
  • x - Input NDArray
§Returns

NDArray with tanh applied element-wise

Source

pub fn tanh_derivative(x: &NDArray) -> NDArray

Computes the derivative of tanh function element-wise

tanh’(x) = 1 - tanh²(x)

§Arguments
  • x - Input NDArray
§Returns

NDArray with tanh derivative applied element-wise

Source

pub fn relu(x: &NDArray) -> NDArray

Computes the ReLU function element-wise

ReLU(x) = max(0, x)

§Arguments
  • x - Input NDArray
§Returns

NDArray with ReLU applied element-wise

Source

pub fn relu_derivative(x: &NDArray) -> NDArray

Computes the derivative of ReLU function element-wise

ReLU’(x) = 1 if x > 0, 0 otherwise

§Arguments
  • x - Input NDArray
§Returns

NDArray with ReLU derivative applied element-wise

Source

pub fn softmax(x: &NDArray, _axis: Option<usize>) -> NDArray

Computes the softmax function along the specified axis

softmax(x) = exp(x) / sum(exp(x))

§Arguments
  • x - Input NDArray
  • axis - Axis along which to compute softmax (default: -1 for last axis)
§Returns

NDArray with softmax applied along specified axis

Source

pub fn softmax_derivative(x: &NDArray) -> NDArray

Computes the derivative of softmax function

§Arguments
  • x - Input NDArray (softmax output)
§Returns

NDArray with softmax derivative

Source

pub fn leaky_relu(x: &NDArray, alpha: Option<f64>) -> NDArray

Computes the Leaky ReLU function element-wise

LeakyReLU(x) = max(alpha * x, x)

§Arguments
  • x - Input NDArray
  • alpha - Slope for negative values (default: 0.01)
§Returns

NDArray with Leaky ReLU applied element-wise

Source

pub fn leaky_relu_derivative(x: &NDArray, alpha: Option<f64>) -> NDArray

Computes the derivative of Leaky ReLU function

§Arguments
  • x - Input NDArray
  • alpha - Slope for negative values (default: 0.01)
§Returns

NDArray with Leaky ReLU derivative

Source

pub fn elu(x: &NDArray, alpha: Option<f64>) -> NDArray

Computes the ELU (Exponential Linear Unit) function

ELU(x) = x if x > 0, alpha * (exp(x) - 1) if x <= 0

§Arguments
  • x - Input NDArray
  • alpha - Scale for negative values (default: 1.0)
§Returns

NDArray with ELU applied element-wise

Source

pub fn elu_derivative(x: &NDArray, alpha: Option<f64>) -> NDArray

Computes the derivative of ELU function

§Arguments
  • x - Input NDArray
  • alpha - Scale for negative values (default: 1.0)
§Returns

NDArray with ELU derivative

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V