The discrepancy in the calculation of the number of weight elements net.numWeightElements arises from the structure of the neural network and the connections between layers. Let's break down the calculation for a neural network with one hidden layer and two outputs:
1. Inputs to Hidden Layer:
- Number of inputs (m) = 25
- Number of neurons in the hidden layer (n) = 5
- Weights from inputs to hidden layer: m * n = 25 * 5 = 125
- Biases for hidden layer neurons: n = 5
2. Hidden Layer to Output Layer:
- Number of outputs (o) = 2
- Weights from hidden layer to output layer: n * o = 5 * 2 = 10
- Biases for output layer neurons: o = 2
The total number of weight elements is the sum of all weights and biases:
Total Weights = (m * n) + n + (n * o) + o = (25 * 5) + 5 + (5 * 2) + 2 = 125 + 5 + 10 + 2 = 142
This matches the value you observed (net.numWeightElements = 142). The original equation you used didn't account for all biases and connections between layers.