boundlab.zono.softmax_handler#
- boundlab.zono.softmax_handler(x, dim=-1, dtype=None)[source]#
Zonotope softmax transformer built from primitive handlers.
Softmax is decomposed as:
\[\mathrm{softmax}(x)_j = \frac{\exp(x_j)}{\sum_k \exp(x_k)}\]The implementation applies:
exp -> reduce-sum -> reciprocal -> element-wise product. For stability, it first shifts by the center maximum along the softmax dimension. Currently, only 2D inputs withdim == 1are supported.- Parameters:
- Returns:
An expression over-approximating
torch.softmax(x, dim=dim).- Return type:
Examples
>>> import torch >>> import boundlab.expr as expr >>> from boundlab.zono.softmax import softmax_handler >>> x = expr.ConstVal(torch.zeros(2, 3)) + 0.1 * expr.LpEpsilon([2, 3]) >>> y = softmax_handler(x, dim=1) >>> y.shape torch.Size([2, 3])