Perform one full-batch gradient-descent step for a tanh neuron, using the supplied inputs, targets, weights, bias, and learning rate.
pi=tanh(xiTw+b) L=i=1∑B(pi−yi)2 θnew=θ−η∇θLHere x is one input row, w is weights, b is bias, p is its prediction, y is its target, B is the batch size, and L is the summed loss. The parameter vector theta contains the weights and bias, and eta is learning_rate. Both parameter updates use gradients at the original parameter values. An empty batch has zero loss and gradients and leaves the parameters unchanged.
Return a tuple of six PyTorch tensors in this order: loss before the update, loss after the update, updated weights, updated bias, weight gradients, and bias gradient. Losses and bias values are zero-dimensional; weight tensors retain the input weight shape. Preserve the common input dtype and device.
Input: inputs = [[1]], targets = [1], weights = [0], bias = 0, learning_rate = 0.1
Output: (1.0, 0.384463, [0.2], 0.2, [-2.0], -2.0)
Explanation: Both parameter gradients are -2; the update changes the weight and bias to 0.2 and reduces the loss.
Input: inputs = [[1,-1],[0,2]], targets = [0.5,-0.25], weights = [0.2,-0.3], bias = 0.1, learning_rate = 0
Output: (0.046366, 0.046366, [0.2, -0.3], 0.1, [0.052727, -0.720004], -0.280911)
Input: inputs = [[0]], targets = [0], weights = [2], bias = 0, learning_rate = 0.5
Output: (0.0, 0.0, [2.0], 0.0, [0.0], 0.0)
torch.mv evaluates a matrix-vector product for a batch.
sum along dimension zero combines per-example contributions.
clone can keep updated parameters separate from the supplied tensors.
Accepts: array
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Perform one full-batch gradient-descent step for a tanh neuron, using the supplied inputs, targets, weights, bias, and learning rate.
pi=tanh(xiTw+b) L=i=1∑B(pi−yi)2 θnew=θ−η∇θLHere x is one input row, w is weights, b is bias, p is its prediction, y is its target, B is the batch size, and L is the summed loss. The parameter vector theta contains the weights and bias, and eta is learning_rate. Both parameter updates use gradients at the original parameter values. An empty batch has zero loss and gradients and leaves the parameters unchanged.
Return a tuple of six PyTorch tensors in this order: loss before the update, loss after the update, updated weights, updated bias, weight gradients, and bias gradient. Losses and bias values are zero-dimensional; weight tensors retain the input weight shape. Preserve the common input dtype and device.
Input: inputs = [[1]], targets = [1], weights = [0], bias = 0, learning_rate = 0.1
Output: (1.0, 0.384463, [0.2], 0.2, [-2.0], -2.0)
Explanation: Both parameter gradients are -2; the update changes the weight and bias to 0.2 and reduces the loss.
Input: inputs = [[1,-1],[0,2]], targets = [0.5,-0.25], weights = [0.2,-0.3], bias = 0.1, learning_rate = 0
Output: (0.046366, 0.046366, [0.2, -0.3], 0.1, [0.052727, -0.720004], -0.280911)
Input: inputs = [[0]], targets = [0], weights = [2], bias = 0, learning_rate = 0.5
Output: (0.0, 0.0, [2.0], 0.0, [0.0], 0.0)
torch.mv evaluates a matrix-vector product for a batch.
sum along dimension zero combines per-example contributions.
clone can keep updated parameters separate from the supplied tensors.
Accepts: array
Accepts: array
Accepts: array
Accepts: number
Accepts: number