lua - Add Bias to a Matrix in Torch -


in torch, how add bias vector each input when have batch input? suppose have input 3*2 matrix (where 2 = number of classes)

  0.8191  0.2630  0.5344  0.4537  0.7380  0.5885 

and want add bias value each element in output matrix:

bias: 0.6588  0.6525 

my final output should like:

1.4779  0.9155 1.1931  1.1063 1.3967  1.2410 

i new torch , figuring out syntax.

you can expand bias have same dimensions input:

expandedbias=torch.expand(bias,3,2)

yields:

th> expandedbias 0.6588 0.6525 0.6588 0.6525 0.6588 0.6525

after can add them:

output=a+expandedbias

to give:

th> a+expandedbias 1.4779 0.9155 1.1931 1.1063 1.3967 1.2410


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -