Skip to content
class

Softmin

extendsModule
Softmin(dim: int | None = None)

Softmin activation function.

Applies softmax to the negated input along a specified dimension:

Softmin(xi)=e−xi∑je−xj\text{Softmin}(x_i) = \frac{e^{-x_i}}{\sum_j e^{-x_j}}

Equivalent to Softmax(-x). The result is a valid probability distribution where lower values receive higher weight — the inverse of softmax. Useful when scores represent costs or distances rather than affinities.

Parameters

dimint or None= None
The dimension along which softmin is computed. Default: None.

Notes

  • Input: (∗)(*) — any shape.
  • Output: (∗)(*) — same shape as input; values along dim are non-negative and sum to 1.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.Softmin(dim=-1)
>>> x = lucid.tensor([[1.0, 2.0, 3.0]])
>>> m(x)
tensor([[0.6652, 0.2447, 0.09003]])
>>> # Lowest-cost option gets the highest weight
>>> costs = lucid.tensor([[0.1, 0.5, 0.9]])
>>> weights = nn.Softmin(dim=-1)(costs)
>>> weights.shape
(1, 3)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(dim: int | None = None)

Initialise the Softmin module. See the class docstring for parameter semantics.

Instance methods

2
fn

extra_repr

→str
extra_repr()

Return a string representation of the layer's configuration.

fn

forward

→Tensor
forward(input: Tensor)

Apply the activation function element-wise.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input.