klyn.math.nn.layers.Dense.backward
method
public backward(inputs as NDArray<T>, upstream as NDArray<T>) as DenseGradients<T>
Description

Computes exact affine derivatives using the current weights. Call before updating parameters. Batch reduction belongs to the loss; this method sums parameter gradients without averaging a second time.

Parameters
ParameterDescription
inputsUnmodified inputs used for the corresponding forward pass.
upstreamDerivative of the loss with respect to outputs [samples, units].
Returns

Input, weight and bias derivatives; no parameters are updated.

Throws
  • ValueException if input or derivative shapes do not agree.
Example

gradients = layer.backward(batch, loss.gradient)