13
$\begingroup$

It is said that activation functions in neural networks help introduce non-linearity.

  • What does this mean?
  • What does non-linearity mean in this context?
  • How does introduction of this non-linearity help?
  • Are there any other purposes of activation functions?
$\endgroup$
11
$\begingroup$

Almost all of the functionalities provided by the non-linear activation functions are given by other answers. Let me sum them up:

  • First, what does non-linearity mean? It means something (a function in this case) which is not linear with respect to a given variable/variables i.e. $f(c1.x1 + c2.x2...cn.xn + b) != c1.f(x1) + c2.f(x2) ... cn.f(xn) + b.$ `
  • What does non-linearity mean in this context? It means that the Neural Network can successfully approximate functions (up-to a certain error $e$ decided by the user) which does not follow linearity or it can successfully predict the class of a function which is divided by a decision boundary which is not linear.
  • Why does it help? I hardly think you can find any physical world phenomenon which follows linearity straightforwardly. So you need a non-linear function which can approximate the non-linear phenomenon. Also a good intuition would be any decision boundary or a function is a linear combination of polynomial combinations of the input features (so ultimately non-linear).
  • Purposes of activation function? In addition to introducing non-linearity every activation function has its own features.

Sigmoid $\frac{1} {(1 + e ^ {-(w1*x1...wn*xn + b)})}$

This is one of the most common activation function and is monotonically increasing everywhere. This is generally used at the final output node as it squashes values between 0 and 1 (if output is required to be 0 or 1).Thus above 0.5 is considered 1 while below 0.5 as 0, although a different threshold (not 0.5) maybe set. Its main advantage is that its differentiation is easy and uses already calculated values and supposedly horseshoe crab neurons have this activation function in their neurons.

Tanh $\frac{e ^ {(w1*x1...wn*xn + b)} - e ^ {-(w1*x1...wn*xn + b)})}{(e ^ { (w1*x1...wn*xn + b)} + e ^ {-(w1*x1...wn*xn + b)}}$

This has an advantage over the sigmoid activation function as it tends to centre the output to 0 which has an effect of better learning on the subsequent layers (acts as a feature normaliser). A nice explanation here. Negative and positive output values maybe considered as 0 and 1 respectively. Used mostly in RNN's.

Re-Lu activation function - This is another very common simple non-linear (linear in positive range and negative range exclusive of each other) activation function which has the advantage of removing the problem of vanishing gradient faced by the above two i.e. gradient tends to 0 as x tends to +infinity or -infinity. Here is an answer about Re-Lu's approximation power in-spite of its apparent linearity. ReLu's have a disadvantage of having dead neurons which result in larger NN's.

Also you can design your own activation functions depending on your specialized problem. You may have a quadratic activation function which will approximate quadratic functions much better. But then, you have to design a cost function which should be somewhat convex in nature, so that you can optimise it using first order differentials and the NN actually converges to a decent result. This is the main reason why standard activation functions are used. But I believe with proper mathematical tools, there is a huge potential for new and eccentric activation functions.

For example, say you are trying to approximate a single variable quadratic function say $a.x^2 + c$. This will be best approximated by a quadratic activation $w1.x^2 + b$ where$w1$ and $b$ will be the trainable parameters. But designing a loss function which follows the conventional first order derivative method (gradient descent) can be quite tough for non-monotically increasing function.

For Mathematicians: In the sigmoid activation function $(1 / (1 + e ^ {-(w1*x1...wn*xn + b)})$ we see that $e ^ {-(w1*x1...wn*xn + b)}$ is always < 1. By binomial expansion, or by reverse calculation of the infinite GP series we get $sigmoid(y)$ = $1 + y + y^2.....$. Now in a NN $y = e ^ {-(w1*x1...wn*xn + b)}$. Thus we get all the powers of $y$ which is equal to $e ^ {-(w1*x1...wn*xn + b)}$ thus each power of $y$ can be thought of as a multiplication of several decaying exponentials based on a feature $x$, for eaxmple $y^2 = e^ {-2(w1x1)} * e^ {-2(w2x2)} * e^ {-2(w3x3)} *...... e^ {-2(b)}$. Thus each feature has a say in the scaling of the graph of $y^2$.

Another way of thinking would be to expand the exponentials according to Taylor Series: enter image description here

So we get a very complex combination, with all the possible polynomial combinations of input variables present. I believe if a Neural Network is structured correctly the NN can fine tune the these polynomial combinations by just modifying the connection weights and selecting polynomial terms maximum useful, and rejecting terms by subtracting output of 2 nodes weighted properly.

The $tanh$ activation can work in the same way since output of $|tanh| < 1$. I am not sure how Re-Lu's work though, but due to itsrigid structure and probelm of dead neurons werequire larger networks with ReLu's for good approximation.

But for a formal mathematical proof one has to look at the Universal Approximation Theorem.

For non-mathematicians some better insights visit these links:

Activation Functions by Andrew Ng - for more formal and scientific answer

How does neural network classifier classify from just drawing a decision plane?

Differentiable activation function A visual proof that neural nets can compute any function

$\endgroup$
  • 3
    $\begingroup$ I would argue that ReLU is actually more common in NNs today than sigmoid :) $\endgroup$ – Andreas Storvik Strauman Apr 8 '18 at 21:28
  • $\begingroup$ @AndreasStorvikStrauman and you are quite correct...But sigmoid has a child called softmax :) $\endgroup$ – DuttaA Sep 1 '18 at 11:31
7
$\begingroup$

If you would just have linear layers in a neural network all the layers would essentially collapse to one linear layer and therefore a "deep" neural network architecture effectively wouldn't be deep anymore and just a linear classifier.

y = f(W1*W2*W3*x) = f(W*x)

(W corresponds to the matrix that represents the network weights and biases for one layer, and f() to the activation function)

Now with the introduction of a non-linear activation unit after every linear transformation this won't happen anymore

y = f1( W1*f2( W2*f3( W3*x)))

Each layer can now build up on the results of the preceding non-linear layer which essentially leads to a complex non-linear function that is able to approximate every possible function with the right weighting and enough depth/width.

$\endgroup$
4
$\begingroup$

I have very simple NN, just 2 layers the first has 2 and the last just 1 neuron and the input size is 2.

the inputs are x1,x1.

Weights of the first layer are w11,w12 and w21, w22. we haven't activations so the outputs of neurons in the fist layer are o1 = w11*x1+w12*x2 o2 = w21*x1+w22*x2

lets calculate output of the last layer, its weights are z1, z2 out = z1*o1 + z2+o2 just substitute o1 and o2 and you will get: out = z1(*w11*x1+w12*x2) + z2(w21*x1+w22*x2) or out = (z1*w11+z2*w21)*x1 + (z2*w22+z1*w12)*x2 And look at this! if we create NN just with one layer with weights (z1*w11+z2*w21) and (z2*w22+z1*w12) it will be equivalent to our 2 layers NN. The conclusion: without nonlinearity computational power of multilayer NN equal to 1 layer NN.

Also you can think of sigmoid function as differentiable IF statement that gives a probability. And awery new layers can create new, more complex combination of IF statements. For example, first layer combines fitures and gives probabilites that there are eyes, tail, and ears on the picture, the second combines new, more complex fitures from last lauer and gives prob that there is a cat. For more information: Hacker's guide to Neural Networks

$\endgroup$
  • $\begingroup$ When a hacker creates an artificial intelligence is that intelligence a hacker? $\endgroup$ – FauChristian Aug 4 '18 at 9:28
4
$\begingroup$

Let's first talk about linearity. Linearity means the map (f) used is a linear map (eg: f(x+y) = f(x)+f(y) and f(cx) = cf(x)). That definition is pretty intuitive if you think of a linear function.

However, it's more important to think of linearity in terms of linear separability of data, which means the data can be separated into different classes by drawing a line/hyperplane (a linear decision boundary) through the data. If we cannot do that, then the data is not linearly separable. Often times data from a more complex (and thus more relevant) problem setting is not linearly separable so it is in our interest to model these.

To model non linear decision boundaries of data, we can utilize a neural network which introduces non linearity. Neural networks classify data that is not linearly separable by transforming data using some nonlinear function (or our activation function) so the resulting transformed points become linearly separable.

Different activation functions are used for different problem setting contexts. You can read more about that here: https://www.amazon.com/Deep-Learning-Adaptive-Computation-Machine/dp/0262035618/ref=asap_bc?ie=UTF8.

For an example of non linearly separable data, see the xor data set here: http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/nn06_rbfn_xor/html/nn06_rbfn_xor_2_newrb_01.png

Can you draw a single line to separate the two classes?

$\endgroup$
2
$\begingroup$

First Degree Linear Polynomials

Non-linearity is not the correct mathematical term. Those that use it probably intend to refer to a first degree polynomial relationship between input and output, the kind of relationship that would be graphed as a straight line, a flat plane, or a higher degree surface with no curvature.

To model relations more complex than y = a1x1 + a2x2 + ... + b, more than just those two terms of a Taylor series approximation is needed.

Tune-able Functions with Non-zero Curvature

Artificial networks such as the multi-layer perceptron and its variants are matrices of functions with non-zero curvature that, when taken collectively as a circuit, can be tuned with attenuation grids to approximate more complex functions of non-zero curvature. These more complex functions generally have multiple inputs (independent variables).

The attenuation grids are simply matrix-vector products, the matrix being the parameters that are tuned to create a circuit that approximates the more complex curved, multivariate function with simpler curved functions.

Oriented with the multi-dimensional signal entering at the left and the result appearing on the right (left-to-right causality), as in the electrical engineering convention, the vertical columns are called layers of activations, mostly for historical reasons. They are actually arrays of simple curved functions. The most commonly used activations today are these.

  • ReLU
  • Leaky ReLU
  • ELU
  • Threshold (binary step)
  • Logistic

The identity function is sometimes used to pass through signals untouched for various structural convenience reasons.

These are less used but were in vogue at one point or another. They are still used but have lost popularity because they place additional overhead on back propagation computations and tend to lose in contests for speed and accuracy.

  • Softmax
  • Sigmoid
  • TanH
  • ArcTan

The more complex of these can be parametrized and all of them can be perturbed with pseudo-random noise to improve reliability.

Why Bother With All of That?

Artificial networks are not necessary for tuning well developed classes of relationships between input and desired output. For instance, these are easily optimized using well developed optimization techniques.

  • Higher degree polynomials — Often directly solvable using techniques derived directly from linear algebra
  • Periodic functions — Can be treated with Fourier methods
  • Curve fitting — converges well using the Levenberg–Marquardt algorithm, a damped least-squares approach

For these, approaches developed long before the advent of artificial networks can often arrive at an optimal solution with less computational overhead and more precision and reliability.

Where artificial networks excel is in the acquisition of functions about which the practitioner is largely ignorant or the tuning of the parameters of known functions for which specific convergence methods have not yet been devised.

Multi-layer perceptrons (ANNs) tune the parameters (attenuation matrix) during training. Tuning is directed by gradient descent or one of its variants to produce a digital approximation of an analog circuit that models the unknown functions. The gradient descent is driven by some criteria toward which circuit behavior is driven by comparing outputs with that criteria. The criteria can be any of these.

  • Matching labels (the desired output values corresponding to the training example inputs)
  • The need to pass information through narrow signal paths and reconstruct from that limited information
  • Another criteria inherent in the network
  • Another criteria arising from a signal source from outside the network

In Summary

In summary, activation functions provide the building blocks that can be used repeatedly in two dimensions of the network structure so that, combined with an attenuation matrix to vary the weight of signaling from layer to layer, is known to be able to approximate an arbitrary and complex function.

Deeper Network Excitement

The post-millenial excitement about deeper networks is because the patterns in two distinct classes of complex inputs have been successfully identified and put into use within larger business, consumer, and scientific markets.

  1. Heterogeneous and semantically complex structures
  2. Media files and streams (images, video, audio)
$\endgroup$
  • $\begingroup$ But the question was about the purpose of activation and not the use of ANN $\endgroup$ – DuttaA Aug 4 '18 at 7:10
  • $\begingroup$ @DuttaA, you're comment was accurate. Thank you. The answer had only one sentence that directly answered the question, and the tie into the rest of that answer wasn't very well communicated. I substantially edited it. $\endgroup$ – FauChristian Aug 4 '18 at 9:25
  • $\begingroup$ This actually is the best answer, should have more upvotes and should be the accepted answer. $\endgroup$ – DuttaA Aug 30 '18 at 19:58
2
$\begingroup$

There is no purpose to an activation function in an artificial network, just like there is no purpose to 3 in the factors of the number of 21. Multi-layer perceptrons and recurrent neural networks were defined as a matrix of cells each of which contains one. Remove the activation functions and all that is left is a series of useless matrix multiplications. Remove the 3 from 21 and the result is not a less effective 21 but a completely different number 7.

Activation functions do not help introduce non-linearity, they are the sole components in network forward propagation that do not fit a first degree polynomial form. If a thousand layers had an activation function $ax$, where $a$ is a constant, the parameters and activations of the thousand layers could be reduced to a single dot product and no function could be simulated by the deep network other than those that reduce to $ax$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.