beetlebug▾
/

ztcl::tensor softmax

Gives the softmax of each row of a matrix.

ztcl::tensor softmax TENSOR

Description

Gives exp(x - max) divided by the sum of the row, for each row of a float matrix.

Returns

A tensor.

Examples

Each example of this page runs after package require ztcl::tensor.

% ztcl::tensor softmax [ztcl::tensor of {{1 2 3}} -dtype f64]
tensor f64 {1 3} {0.09003057317038046 0.24472847105479764 0.6652409557748218}

Errors

% ztcl::tensor softmax [ztcl::tensor ones 3]
tensor softmax: the command needs rank 2
-errorcode ZTCL TENSOR

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.4
Compute cost
A cost for each element operation by its kind (a copy, an add, a division, a math function, a multiply-add of a matmul), set so that one compute unit takes about the time of one unit of plain Tcl. docs/modules/tensor.md has the table.