# Question about add Bias after moltiplication

**URL:** <https://discourse.processing.org/t/question-about-add-bias-after-moltiplication/2808>\
**Category:** Coding Questions\
**Created:** [August 20, 2018, 10:53pm UTC](https://discourse.processing.org/t/question-about-add-bias-after-moltiplication/2808 "2018-08-20T22:53:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manatee](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manatee](https://discourse.processing.org/u/Manatee)\
**Post date:** [August 20, 2018, 10:53pm UTC](https://discourse.processing.org/t/question-about-add-bias-after-moltiplication/2808/1 "2018-08-20T22:53:20Z")

</div>

I saw this ([https://www.youtube.com/watch?v=MPmLWsHzPlU](https://www.youtube.com/watch?v=MPmLWsHzPlU)) video where the teacher explain how to build a god network after trying by myself Im stuck with this problem.  
He said to add the bias after moltiplication between W \* INPUT, but in this first case I have example  
Network(4 IN, 16 HIDDEN, 4 OUT), So the Matrix IN would be a 4 row 1 column and the matrix Weight\_InHid would be 16, 4 and according to Algebra you can moltiply only if columns of A(IN) = Row of B(Weight\_InHd), and It would be fine, then When I add the Bias to Hidden It will become +1 bigger and in the next feedforward I will get the dimension of the 2 Matrices different and I can’t do that!  
Anyone can explain where is the trick?  
Im pretty tired maybe im doing something super wrong!  
Here a piace of code

```auto
CONSTRUCTOR
  Net(int I_node, int H_node, int O_node)
  {
    input_nodes = I_node;
    hidden_nodes = H_node;
    output_nodes = O_node;
    
    weights_ih = new Matrix(H_node, I_node);
    weights_ho = new Matrix(O_node, H_node);
    
    weights_ih.randomize(); //-1 and 1
    weights_ho.randomize();     
  }
float[] feedforward(float[] input_array)
  {
    Matrix inputs = new Matrix();
    Matrix outputs = new Matrix();
    inputs = inputs.singleColumnMatrixFromArray(input_array);    
    
    //Generating the HIDDEN OUTPUTS--------------------
    //Now multiply the 2 matrices, weight_ih * input
    Matrix hidden = new Matrix();            
    hidden = weights_ih; //Clone weights_ih into hidden as temp matrix  
    
    hidden = hidden.multiply(inputs); //Multiply the 2 matrices hidden(weights_ih) * input    
    hidden = hidden.activate(); //Finally activation sigmoid :D    
    hidden = hidden.addBias(); //Add 1 single row with value 1
    hidden.output(); //Print matrix
    //-------------------------------------------------

    //Generating the OUTPUT'S OUTPUT    
    outputs = weights_ho;    
    outputs = outputs.multiply(hidden);//HERE I GET the error of compatibility between matrices
    outputs.addBias();
    outputs.activate();      
    float[] guess = outputs.toArray();
    //Send it to the caller
    return guess;
  }

```

---

<div class="post-metadata">

**Author:** ![Manatee](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manatee](https://discourse.processing.org/u/Manatee)\
**Post date:** [August 20, 2018, 11:08pm UTC](https://discourse.processing.org/t/question-about-add-bias-after-moltiplication/2808/2 "2018-08-20T23:08:15Z")

</div>

I put a +1 in the constructor when I initialized weights\_ih and weights\_ho:

```auto
weights_ih = new Matrix(H_node, I_node+1);
weights_ho = new Matrix(O_node, H_node+1);

```

and now it is work!  
I dont know why but it’s cool now expect for the 1 more output useless 😃  
Feel free to reply please cause I want to understand better what’s going on before use this algorithm
