class

Softmin

extendsModule
Softmin(dim: int | None = None)
source

Softmin activation function.

Applies softmax to the negated input along a specified dimension:

Softmin(xi)=exijexj\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.0900]])
>>> # 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)

Methods (3)

dunder

__init__

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

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

fn

forward

Tensor
forward(x: Tensor)
source

Apply the activation function element-wise.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.