Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to implement biases in Neural Networks

I can make a neural network, I just need a clarification on bias implementation. Which way is better: Implement the Bias matrices B1, B2, .. Bn for each layer in their own, seperate matrix from the weight matrix, or, include the biases in the weight matrix by adding a 1 to the previous layer output (input for this layer). In images, I am asking whether this implementation:

enter image description here

Or this implementation:

enter image description here

Is the best. Thank you

like image 975
Kai Avatar asked Jun 29 '18 23:06

Kai


1 Answers

I think the best way is to have two separate matrices, one for the weitghts and one for the bias. Why? :

  • I don't believe there is an increase on the computational load since W*x and W*x + b should be equivalent running on GPU. Mathematically and computationally they are equivalent.

  • Greater modularity. Let's say you want to initialize the weights and the bias using different initializers (ones, zeros, glorot...). By having two separate matrices this is straightforward.

  • Easier to read and maintain.

like image 181
WristMan Avatar answered Oct 07 '22 11:10

WristMan