softmax
- namespace: Rindow\NeuralNetworks\Gradient\Func
- classname: Softmax
Differentiable softmax function.
Methods
softmax
$g->softmax(
Variable|NDArray $x
) : Variable
Create and execute the function in the builder method
Arguments
- x: The argument is Variable or NDArray. Implicitly create Variable for NDArray.
use Rindow\Math\Matrix\MatrixOperator;
use Rindow\NeuralNetworks\Builder\NeuralNetworks;
$mo = new MatrixOperator();
$nn = new NeuralNetworks($mo);
$g = $nn->gradient();
$a = $g->Variable([1,2,3]);
$c = $nn->with($tape=$g->GradientTape(),function() use ($g,$a) {
return $g->softmax($a);
});
$da = $tape->gradient($c,$a);
echo $mo->toString($c,'%6.3f')."\n";
# [ 0.090, 0.245, 0.665]