Evaluate a neuron using the supplied inputs, weights, and bias.
a=b+i=1∑nwixiHere x is inputs, w is weights, b is bias, n is the vector length, i indexes matching entries, and a is the preactivation. When nonlinear is true, the output is tanh of a; otherwise it is a. Empty vectors leave the bias as the preactivation.
Return one zero-dimensional PyTorch tensor, preserving the common input dtype and device.
Input: inputs = [1,2], weights = [0.5,-1], bias = 0.25, nonlinear = false
Output: -1.25
Explanation: The weighted sum is -1.5; adding the bias gives -1.25.
Input: inputs = [0], weights = [2], bias = 0, nonlinear = true
Output: 0.0
Input: inputs = [], weights = [], bias = 1.5, nonlinear = true
Output: 0.905148
torch.sum reduces an empty vector to scalar zero.
torch.tanh preserves a tensor’s shape, dtype, and device.
Accepts: array
Accepts: array
Accepts: number
Evaluate a neuron using the supplied inputs, weights, and bias.
a=b+i=1∑nwixiHere x is inputs, w is weights, b is bias, n is the vector length, i indexes matching entries, and a is the preactivation. When nonlinear is true, the output is tanh of a; otherwise it is a. Empty vectors leave the bias as the preactivation.
Return one zero-dimensional PyTorch tensor, preserving the common input dtype and device.
Input: inputs = [1,2], weights = [0.5,-1], bias = 0.25, nonlinear = false
Output: -1.25
Explanation: The weighted sum is -1.5; adding the bias gives -1.25.
Input: inputs = [0], weights = [2], bias = 0, nonlinear = true
Output: 0.0
Input: inputs = [], weights = [], bias = 1.5, nonlinear = true
Output: 0.905148
torch.sum reduces an empty vector to scalar zero.
torch.tanh preserves a tensor’s shape, dtype, and device.
Accepts: array
Accepts: array
Accepts: number