nerva_numpy.softmax_functions

Softmax and log-softmax functions together with stable variants.

This module provides both function-only forms and simple callable classes.

Functions

log_softmax(X)

Row-wise log-softmax (numerically unsafe version).

log_softmax_jacobian(x)

Jacobian matrix of log_softmax for a single row vector.

softmax(X)

Row-wise softmax with explicit normalization (numerically unsafe).

softmax_jacobian(x)

Jacobian matrix of softmax for a single row vector.

stable_log_softmax(X)

Row-wise log-softmax with max-subtraction for stability.

stable_log_softmax_jacobian(x)

Jacobian matrix of stable log_softmax (same as log_softmax).

stable_softmax(X)

Row-wise softmax using max-subtraction for numerical stability.

stable_softmax_jacobian(x)

Jacobian matrix of stable softmax for a single row vector.

Classes

LogSoftmaxFunction()

Callable implementing row-wise log-softmax and its Jacobian.

SoftmaxFunction()

Callable implementing row-wise softmax and its Jacobian.

StableLogSoftmaxFunction()

Callable implementing numerically stable row-wise log-softmax and its Jacobian.

StableSoftmaxFunction()

Callable implementing numerically stable row-wise softmax and its Jacobian.

nerva_numpy.softmax_functions.softmax(X: numpy.ndarray) numpy.ndarray[source]

Row-wise softmax with explicit normalization (numerically unsafe).

nerva_numpy.softmax_functions.softmax_jacobian(x: numpy.ndarray) numpy.ndarray[source]

Jacobian matrix of softmax for a single row vector.

nerva_numpy.softmax_functions.stable_softmax(X: numpy.ndarray) numpy.ndarray[source]

Row-wise softmax using max-subtraction for numerical stability.

nerva_numpy.softmax_functions.stable_softmax_jacobian(x: numpy.ndarray) numpy.ndarray[source]

Jacobian matrix of stable softmax for a single row vector.

nerva_numpy.softmax_functions.log_softmax(X: numpy.ndarray) numpy.ndarray[source]

Row-wise log-softmax (numerically unsafe version).

nerva_numpy.softmax_functions.log_softmax_jacobian(x: numpy.ndarray) numpy.ndarray[source]

Jacobian matrix of log_softmax for a single row vector.

nerva_numpy.softmax_functions.stable_log_softmax(X: numpy.ndarray) numpy.ndarray[source]

Row-wise log-softmax with max-subtraction for stability.

nerva_numpy.softmax_functions.stable_log_softmax_jacobian(x: numpy.ndarray) numpy.ndarray[source]

Jacobian matrix of stable log_softmax (same as log_softmax).

class nerva_numpy.softmax_functions.SoftmaxFunction[source]

Bases: object

Callable implementing row-wise softmax and its Jacobian.

jacobian(X: numpy.ndarray) numpy.ndarray[source]
class nerva_numpy.softmax_functions.StableSoftmaxFunction[source]

Bases: object

Callable implementing numerically stable row-wise softmax and its Jacobian.

jacobian(X: numpy.ndarray) numpy.ndarray[source]
class nerva_numpy.softmax_functions.LogSoftmaxFunction[source]

Bases: object

Callable implementing row-wise log-softmax and its Jacobian.

jacobian(X: numpy.ndarray) numpy.ndarray[source]
class nerva_numpy.softmax_functions.StableLogSoftmaxFunction[source]

Bases: object

Callable implementing numerically stable row-wise log-softmax and its Jacobian.

jacobian(X: numpy.ndarray) numpy.ndarray[source]