Answers.Body: <p>The output of any node is simply a scalar number. For a given input you get a specific scalar output. What is being shown is the surfaces that get generated as you VARY x1 and x2 over their input range.
  To answer your first question it is always best to scale your inputs.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-26T01:02:53.893Z
Answers.LastActivityDate: 2020-04-26T01:02:53.893Z
Answers.UserDisplayName: Gerry P
Answers.Body: <p>Hi and welcome to the community. It's important to understand these basic concepts very clearly.</p>
  
  <p>You have to first understand the basic unit of a neural network, a single node/neuron/perceptron. Let us forget all about Neural Networks for a bit, and talk about something far simpler.</p>
  
  <p><strong>Linear Regression</strong></p>
  
  <p><a href="https://i.sstatic.net/p0Ot9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/p0Ot9.png" alt="A Linear Regression"></a></p>
  
  <p>In the above figure, we clearly have one independent variable on the x-axis, and one dependent variable on the y-axis. The red line has an intercept of zero, and let's say a slope of 0.5. Therefore,
  <span class="math-container">$$ y = 0.5x + 0 $$</span> </p>
  
  <p>This, right here, is a single perceptron. You take a value of x, lets say 8, pass it through the the node, and get a value as output, 4. Simple!
  But what is the model in this case? Is it the output? No. Its the set [0.5, 0] that represents the red line above. The outputs are simply points on that line.</p>
  
  <p><strong>A neural network model is always a set of values - a matrix or a tensor, if you will.</strong></p>
  
  <p>The plots in your question, do not represent outputs. <strong>They represent the models.</strong> But now that you've possibly understood what a linear model with one indpendent variable looks like, I hope you can appreciate that having 2 independent variables will give us a plane in 3-D space. This is called multiple regression.</p>
  
  <p><a href="https://i.sstatic.net/dMONi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dMONi.png" alt="multiple regression"></a></p>
  
  <p>This forms the first layer of a neural network with linear activation functions. Assuming <span class="math-container">$ x_{i} $</span> and <span class="math-container">$ x_{j} $</span> as the two independent variables, the first layer computes
  <span class="math-container">$$ y_{1} = w_{1}x_{i} + w_{2}x_{j} + b_{1} $$</span></p>
  
  <p>Note that while <span class="math-container">$ y_{1} $</span> is the output of the first layer, the set <span class="math-container">$ [w_{1}, w_{2}, b_{1}] $</span> is the model of the first layer and can be plotted as a plane in 3D space.
  The second layer, again a linear layer, computes
  <span class="math-container">$$ y_{2} = w_{3}y_{1} + b_{2} $$</span></p>
  
  <p>Substitute <span class="math-container">$ y_{1} $</span> in above and what do you get? Another linear model!</p>
  
  <p><span class="math-container">$$ y_{2} = w_{3}(w_{1}x_{i} + w_{2}x_{j} + b_{1}) + b_{2} $$</span></p>
  
  <p>Adding layers to a neural network is only compounding of functions.</p>
  
  <p><strong>Compounding linear functions on linear functions result in linear functions.</strong></p>
  
  <p>Well, then, what was the point of adding a layer? Seems useless, right?</p>
  
  <p>Yes, adding linear layers to a neural network is absolutely useless. But what happens if the activation functions of each perceptron, each layer was not linear? For example the sigmoid or the most widely used today, ReLU.</p>
  
  <p><strong>Compounding non-linear functions on non-linear functions can increase non-linearity.</strong></p>
  
  <p>The ReLU looks like this
  <span class="math-container">$$ y = max(0, x) $$</span>
  <a href="https://i.sstatic.net/3oIXS.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3oIXS.png" alt="relu"></a></p>
  
  <p>This is definitely non-linear but not as non-linear as let's say the sine wave. But can we approximate the sine wave by somehow "compounding" multiple, say <span class="math-container">$ N $</span> ReLUs?</p>
  
  <p><span class="math-container">$$ \sin(x) \approx a + \sum_{N}b*max(0, c + dx)$$</span></p>
  
  <p>And here the variables <span class="math-container">$ a, b,c, d $</span> are the trainable "weights" in neural network terminology.</p>
  
  <p><a href="https://i.sstatic.net/qR5eG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qR5eG.png" alt="sinx_as_relu"></a></p>
  
  <p>If you remember the structure of the perceptron, the first operation is often denoted as a summation over all the inputs. This is how non-linearity is approximated in Neural Networks. Now one may ask: <em>So, summing over non-linear functions can approximate any function, right? So a single hidden layer between input layer and output layer (one that sums over all the outputs of the hidden layer units) should be enough? Why do we often see neural network architectures with so many hidden layers?</em> This is one of the most important yet often overlooked aspect of neural networks and deep-learning.</p>
  
  <p>To quote, Dr. Ian J Goodfellow, one of the brightest minds in AI, </p>
  
  <blockquote>
    <p>A feedforward network with a single (hidden) layer is sufficient to represent any function, but the layer may be infeasibly large and may fail to learn and generalize correctly.</p>
  </blockquote>
  
  <p>So, what is the ideal number of hidden layers? There's no magic number! ;-)</p>
  
  <p>For more mathematical rigor on how neural networks approximate non-linear functions, one should learn about the <a href="https://en.wikipedia.org/wiki/Universal_approximation_theorem" rel="nofollow noreferrer">Universal Approximation Theorem</a>. Beginners should check <a href="http://neuralnetworksanddeeplearning.com/chap4.html" rel="nofollow noreferrer">this</a> out.</p>
  
  <p>But why should we care for increased non-linearity? For that I'd direct you to <a href="https://stats.stackexchange.com/questions/275358/why-is-increasing-the-non-linearity-of-neural-networks-desired">this.</a></p>
  
  <p>Note that all of the above discussion is with respect to regression. For classification, the non-linear surface learned is regarded as a decision boundary and points above and below the surface are classified into different classes. However, an alternative, and arguably better, way to look at this is that given a dataset that is not linearly seperable, a neural network first transforms the input dataset into a linearly seperable form and then uses a linear decision boundary on it. For more on this, definitely check out Christopher Olah's amazing <a href="http://colah.github.io/posts/2014-03-NN-Manifolds-Topology/" rel="nofollow noreferrer">blog</a>.</p>
  
  <p>Finally, yes all independent variables must be normalized before training a neural network. This is to equalize the scale of different variables. More info <a href="https://medium.com/@urvashilluniya/why-data-normalization-is-necessary-for-machine-learning-models-681b65a05029" rel="nofollow noreferrer">here</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-26T10:06:11.313Z
Answers.Text: Wow, thank so much to all who answered me, I think it is clear right now. Allways love to say in my own words what I understood, so here are 3 simple yes/noquestions to make sure (watch pic attached as above as my own answer to myself). Thank you very much once again. Igor
Answers.UserDisplayName: Igor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-26T08:15:05.130Z
Answers.LastActivityDate: 2020-04-26T18:44:29.710Z
Answers.LastEditDate: 2020-04-26T18:44:29.710Z
Answers.UserDisplayName: Ananda
Body: <p>Desperate trying to understand something for couple of weeks. All those questions are actually one big question.Please help me. Time-codes and screens in my question refer to this great(IMHO) 3d explanation:</p>
  
  <p><a href="https://www.youtube.com/watch?v=UojVVG4PAG0&amp;list=PLVZqlMpoM6kaJX_2lLKjEhWI0NlqHfqzp&amp;index=2" rel="nofollow noreferrer">https://www.youtube.com/watch?v=UojVVG4PAG0&amp;list=PLVZqlMpoM6kaJX_2lLKjEhWI0NlqHfqzp&amp;index=2</a></p>
  
  <p>....
  Here is the case: Say I have 2 inputs (lets call them X1 and X2) into my ANN. Say X1= persons age and X2=years of education.</p>
  
  <p>1) <strong>First question:</strong> do I plug those numbers as is or normalize them 0-1 as a "preprocessing"?</p>
  
  <p>2) As I have 2 weights and 1 bias, actually I am going to plug my inputs to X1*W1+X2*W2=output formula.  This is 2d plane in a 3d space if I am not mistaken(time-code 5:31):
  <a href="https://i.sstatic.net/oV1Nj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/oV1Nj.png" alt="2d plane in 3d space"></a></p>
  
  <p>Thus when I plug in my variables, like in regression I will get on a Z axis my output.  <strong>So the second question is: am I right up to here?</strong></p>
  
  <p>-----------------From here come  real important couple of  questions.</p>
  
  <p>3) My output (before I plug it into the activation function) is just a simple number, IT IS NOT A PLANE and NOT A SURFACE, but a simple scalar, without any sigh on it coming from 2d surface in a 3d space(though it does come from there). Thus, when I plug this number (which was Z value in a previous step) into the activation function (say sigmoid) my number enters there in to the X axis,  and we get as an output some Y value. As I understand  this operation was <strong>totally 2d operation</strong>, is was 2d sigmoid and not some kind of 3dsigmoidal surface.</p>
  
  <p><strong>So here is the question:</strong> If I am right, why do we see in this movie (and couple of other places) such an explanation?
  (time-code 12:55):<a href="https://i.sstatic.net/9Xomw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9Xomw.png" alt=" 3d-sigmoidal surface "></a></p>
  
  <p>4)Now lets say that I was right in the previous step and as an output from the activation function I do get a simple number not a 2d surface and not a 3d one. I just have some number like I had in the very beginning of the ANN as an input (age, education etc). If i want to add another layer of neurons, this very number enters there  <strong>as is</strong> not telling any one the "secret" that it was created by some kind of sigmoid. In this next layer this number is about to take similar transformations as it happened to age and education in a previous layer, it is going to be Xn in just the same scenario: sigmoid(Xn<em>Wn+Xm</em>Wm=output) and in the end we will get once again just a number. If I am right, why in the movie they say (time-code 14:50 ) that when we add together two activation functions we get something unlinear. They show result of such "addition" first as 2d (time-code 14:50 and 14:58).
  <a href="https://i.sstatic.net/FR2Hh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FR2Hh.png" alt="addition of 2 activation functions "></a> 
  <strong>So, Here comes my question:</strong>  how come that they "add" two activation functions, if to the second activation function reaches just a simple number as said above he is not telling any one the "secret" that it was created by some kind of sigmoid.</p>
  
  <p>5) And then again, they show this addition of 3d surfaces (time-code 19:39 )<br>
  <a href="https://i.sstatic.net/AUtkg.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AUtkg.png" alt="19:39 "></a> How it is possible? I mean again there should not happen any addition of surfaces, because no surface passes to next step but a number. What do I miss?</p>
  
Tags: <neural-networks><ai-basics><activation-functions><hidden-layers><weights>
Title: How are non-linear surfaces formed in the training of a neural network?
UserDisplayName: Igor
ThreadText: # How are non-linear surfaces formed in the training of a neural network?
  
  (Asked by: username_0 on 2020-04-25)
  
  Desperate trying to understand something for couple of weeks. All those questions are actually one big question.Please help me. Time-codes and screens in my question refer to this great(IMHO) 3d explanation:
  
  <https://www.youtube.com/watch?v=UojVVG4PAG0&list=PLVZqlMpoM6kaJX_2lLKjEhWI0NlqHfqzp&index=2>
  
  ....
  Here is the case: Say I have 2 inputs (lets call them X1 and X2) into my ANN. Say X1= persons age and X2=years of education.
  
  1) **First question:** do I plug those numbers as is or normalize them 0-1 as a "preprocessing"?
  
  2) As I have 2 weights and 1 bias, actually I am going to plug my inputs to X1\*W1+X2\*W2=output formula. This is 2d plane in a 3d space if I am not mistaken(time-code 5:31):
  [![2d plane in 3d space](https://i.sstatic.net/oV1Nj.png)](https://i.sstatic.net/oV1Nj.png)
  
  Thus when I plug in my variables, like in regression I will get on a Z axis my output. **So the second question is: am I right up to here?**
  
  -----------------From here come real important couple of questions.
  
  3) My output (before I plug it into the activation function) is just a simple number, IT IS NOT A PLANE and NOT A SURFACE, but a simple scalar, without any sigh on it coming from 2d surface in a 3d space(though it does come from there). Thus, when I plug this number (which was Z value in a previous step) into the activation function (say sigmoid) my number enters there in to the X axis, and we get as an output some Y value. As I understand this operation was **totally 2d operation**, is was 2d sigmoid and not some kind of 3dsigmoidal surface.
  
  **So here is the question:** If I am right, why do we see in this movie (and couple of other places) such an explanation?
  (time-code 12:55):[![ 3d-sigmoidal surface ](https://i.sstatic.net/9Xomw.png)](https://i.sstatic.net/9Xomw.png)
  
  4)Now lets say that I was right in the previous step and as an output from the activation function I do get a simple number not a 2d surface and not a 3d one. I just have some number like I had in the very beginning of the ANN as an input (age, education etc). If i want to add another layer of neurons, this very number enters there **as is** not telling any one the "secret" that it was created by some kind of sigmoid. In this next layer this number is about to take similar transformations as it happened to age and education in a previous layer, it is going to be Xn in just the same scenario: sigmoid(Xn*Wn+Xm*Wm=output) and in the end we will get once again just a number. If I am right, why in the movie they say (time-code 14:50 ) that when we add together two activation functions we get something unlinear. They show result of such "addition" first as 2d (time-code 14:50 and 14:58).
  [![addition of 2 activation functions ](https://i.sstatic.net/FR2Hh.png)](https://i.sstatic.net/FR2Hh.png)
  **So, Here comes my question:** how come that they "add" two activation functions, if to the second activation function reaches just a simple number as said above he is not telling any one the "secret" that it was created by some kind of sigmoid.
  
  5) And then again, they show this addition of 3d surfaces (time-code 19:39 )  
  [![19:39 ](https://i.sstatic.net/AUtkg.png)](https://i.sstatic.net/AUtkg.png) How it is possible? I mean again there should not happen any addition of surfaces, because no surface passes to next step but a number. What do I miss?
  
  **Tags:** neural-networks, ai-basics, activation-functions, hidden-layers, weights
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-04-26. Score: 3 | Accepted answer
  
  Hi and welcome to the community. It's important to understand these basic concepts very clearly.
  
  You have to first understand the basic unit of a neural network, a single node/neuron/perceptron. Let us forget all about Neural Networks for a bit, and talk about something far simpler.
  
  **Linear Regression**
  
  [![A Linear Regression](https://i.sstatic.net/p0Ot9.png)](https://i.sstatic.net/p0Ot9.png)
  
  In the above figure, we clearly have one independent variable on the x-axis, and one dependent variable on the y-axis. The red line has an intercept of zero, and let's say a slope of 0.5. Therefore,
  $$ y = 0.5x + 0 $$
  
  This, right here, is a single perceptron. You take a value of x, lets say 8, pass it through the the node, and get a value as output, 4. Simple!
  But what is the model in this case? Is it the output? No. Its the set [0.5, 0] that represents the red line above. The outputs are simply points on that line.
  
  **A neural network model is always a set of values - a matrix or a tensor, if you will.**
  
  The plots in your question, do not represent outputs. **They represent the models.** But now that you've possibly understood what a linear model with one indpendent variable looks like, I hope you can appreciate that having 2 independent variables will give us a plane in 3-D space. This is called multiple regression.
  
  [![multiple regression](https://i.sstatic.net/dMONi.png)](https://i.sstatic.net/dMONi.png)
  
  This forms the first layer of a neural network with linear activation functions. Assuming $ x\_{i} $ and $ x\_{j} $ as the two independent variables, the first layer computes
  $$ y\_{1} = w\_{1}x\_{i} + w\_{2}x\_{j} + b\_{1} $$
  
  Note that while $ y\_{1} $ is the output of the first layer, the set $ [w\_{1}, w\_{2}, b\_{1}] $ is the model of the first layer and can be plotted as a plane in 3D space.
  The second layer, again a linear layer, computes
  $$ y\_{2} = w\_{3}y\_{1} + b\_{2} $$
  
  Substitute $ y\_{1} $ in above and what do you get? Another linear model!
  
  $$ y\_{2} = w\_{3}(w\_{1}x\_{i} + w\_{2}x\_{j} + b\_{1}) + b\_{2} $$
  
  Adding layers to a neural network is only compounding of functions.
  
  **Compounding linear functions on linear functions result in linear functions.**
  
  Well, then, what was the point of adding a layer? Seems useless, right?
  
  Yes, adding linear layers to a neural network is absolutely useless. But what happens if the activation functions of each perceptron, each layer was not linear? For example the sigmoid or the most widely used today, ReLU.
  
  **Compounding non-linear functions on non-linear functions can increase non-linearity.**
  
  The ReLU looks like this
  $$ y = max(0, x) $$
  [![relu](https://i.sstatic.net/3oIXS.png)](https://i.sstatic.net/3oIXS.png)
  
  This is definitely non-linear but not as non-linear as let's say the sine wave. But can we approximate the sine wave by somehow "compounding" multiple, say $ N $ ReLUs?
  
  $$ \sin(x) \approx a + \sum\_{N}b\*max(0, c + dx)$$
  
  And here the variables $ a, b,c, d $ are the trainable "weights" in neural network terminology.
  
  [![sinx_as_relu](https://i.sstatic.net/qR5eG.png)](https://i.sstatic.net/qR5eG.png)
  
  If you remember the structure of the perceptron, the first operation is often denoted as a summation over all the inputs. This is how non-linearity is approximated in Neural Networks. Now one may ask: *So, summing over non-linear functions can approximate any function, right? So a single hidden layer between input layer and output layer (one that sums over all the outputs of the hidden layer units) should be enough? Why do we often see neural network architectures with so many hidden layers?* This is one of the most important yet often overlooked aspect of neural networks and deep-learning.
  
  To quote, Dr. Ian J Goodfellow, one of the brightest minds in AI,
  
  > A feedforward network with a single (hidden) layer is sufficient to represent any function, but the layer may be infeasibly large and may fail to learn and generalize correctly.
  
  So, what is the ideal number of hidden layers? There's no magic number! ;-)
  
  For more mathematical rigor on how neural networks approximate non-linear functions, one should learn about the [Universal Approximation Theorem](https://en.wikipedia.org/wiki/Universal_approximation_theorem). Beginners should check [this](http://neuralnetworksanddeeplearning.com/chap4.html) out.
  
  But why should we care for increased non-linearity? For that I'd direct you to [this.](https://stats.stackexchange.com/questions/275358/why-is-increasing-the-non-linearity-of-neural-networks-desired)
  
  Note that all of the above discussion is with respect to regression. For classification, the non-linear surface learned is regarded as a decision boundary and points above and below the surface are classified into different classes. However, an alternative, and arguably better, way to look at this is that given a dataset that is not linearly seperable, a neural network first transforms the input dataset into a linearly seperable form and then uses a linear decision boundary on it. For more on this, definitely check out Christopher Olah's amazing [blog](http://colah.github.io/posts/2014-03-NN-Manifolds-Topology/).
  
  Finally, yes all independent variables must be normalized before training a neural network. This is to equalize the scale of different variables. More info [here](https://medium.com/@urvashilluniya/why-data-normalization-is-necessary-for-machine-learning-models-681b65a05029).
  
  > **Comments:**
  > **username_0**: Wow, thank so much to all who answered me, I think it is clear right now. Allways love to say in my own words what I understood, so here are 3 simple yes/noquestions to make sure (watch pic attached as above as my own answer to myself). Thank you very much once again. Igor  
  
  ---
  
  ### Answer by username_1 on 2020-04-26. Score: 1
  
  The output of any node is simply a scalar number. For a given input you get a specific scalar output. What is being shown is the surfaces that get generated as you VARY x1 and x2 over their input range.
  To answer your first question it is always best to scale your inputs.
  
  
  ---
  
  