iTranslated by AI
[Activation Functions] 02: Five Types of Activation Functions

Introduction
In the previous article, I introduced an overview of activation functions.
↓ Past... ↓
From this time, let's dive into more specific content.
Now, there are several types of activation functions. By changing the activation function used, the method of transformation changes, and thus the final result also changes. Each activation function has a specific role, and it is somewhat predetermined that "in this situation, use this activation function."
There are many types of activation functions, but knowing about 5 or 6 types is generally enough.
In this article, I will introduce 5 representative activation functions.

I will explain these five in order.
Please stick around until the end.
↓ You can also watch it as a video ↓
1. Step Function
First, let's introduce the step function.

The step function is an activation function that outputs 0 if the neuron's value is 0 or less, and 1 if it is 0 or more. In other words, if the neuron's value is negative, it converts it to 0, and if it's positive, it converts it to 1.
For example, -30 is converted to 0, 0 becomes 0, 23 becomes 1, and 4598 becomes 1. In this way, even if the neuron's value becomes extremely large or extremely small, using the step function allows you to smooth it out to 0 or 1.

Conversely, since the step function can only output 1 and 0, important information such as the previous calculation results or whether a value was "really large" or "really small" is lost.

This lack of expressivity is the disadvantage of the step function.
While this step function is rarely used in actual neural networks, it is a fundamental activation function, so please keep it in the back of your mind.
2. Sigmoid Function
Next, let's introduce the sigmoid function.
The sigmoid function is an activation function that converts the neuron's value into a range from 0 to 1.

The smaller the neuron's value, the closer the output is to 0, and the larger the value, the closer the output is to 1. Compared to the step function, which can only output 0 or 1, using the sigmoid function allows for subtle values such as 0.2, 0.5, or 0.9. Thus, it can be said that it doesn't suppress the original neuron's value too much.
Also, converting from 0 to 1 means, in other words, it can be converted into a "ratio" (percentage) from 0% to 100%.

Let's look at an example. For instance, if the result of the sigmoid transformation is 0.45, it can be thought of as 45%, and if it's 0.99, it's 99%. Utilizing this property, the sigmoid function can be used in the output layer for "binary classification problems."

A binary classification problem is a problem of classifying things into two categories.
For example, consider the problem of classifying images of dogs and cats. By slightly changing the perspective, this problem can be rephrased not as "is it a dog or a cat?" but as "is it a dog, or not a dog?"
When solving this problem using a neural network, the sigmoid function is used as the activation function of the output layer.

For example, if the output value of the sigmoid function is 0.77, it means the network is saying, "This image is a dog with a 77% probability!" Since it's a binary classification problem, it's also saying, "This image is a cat with the remaining 23% probability."
In this way, the sigmoid function is often used for the output layer of "binary classification problems."
While the sigmoid function is useful, it also has a fatal flaw: it causes the "vanishing gradient problem."

When a neural network learns, it updates its weights appropriately by performing a process called "backpropagation." At this time, if the sigmoid function is used as the "activation function for hidden layers," a problem occurs where learning does not progress at all.
This problem, where learning fails to progress, is called the "vanishing gradient problem." Please look it up for more details.
To solve this fatal vanishing gradient problem, the "ReLU function," which I will introduce next, began to attract attention.
3. ReLU Function
Next, I will introduce the ReLU function.
The ReLU function is an activation function characterized by outputting 0 if the neuron's value is 0 or less, and outputting the value as it is if it is 0 or more.

The difference from the step function mentioned earlier is that if the neuron's value is positive, that numerical value is passed on to the next layer as is.

For example, -30 is converted to 0, 0 becomes 0, 23 becomes 23, and 4598 becomes 4598.
By keeping positive values this way, you can connect to the next neuron without losing the previous expression (calculation results).
On the other hand, negative numbers are simply discarded.

This is based on the idea of regarding negative numbers as "noise" and intentionally discarding them. By decisively removing unnecessary information like this, it has the effect of making it easier to bring out the features of the data.
The ReLU function, with these characteristics, is very compatible with image data.

Images are composed of sets of numbers, and those numbers are always expressed as positive values. Therefore, if the result of processing that image with a neural network turns out to be negative data, it makes sense to treat it as irregular noise and discard it.
Also, outputting 0 can be said to mean "outputting nothing" to the next neuron. To put it more technically, this can be rephrased as "not activating."

Actually, this "outputting nothing" behavior is a phenomenon that frequently occurs in the human brain as well.
By making such efforts to stay as close as possible to the workings of the human brain, we can further improve the accuracy of artificial intelligence.
4. Softmax Function
Next, let's introduce the Softmax function. The Softmax function is an activation function that converts values into a "percentage representation."

In other words, it is a function that transforms and outputs values such that the total sum of the neurons equals 1.0 (100%). It might be confusing at first, so let's explain it step by step.
The Softmax function requires a slightly different way of thinking compared to the activation functions introduced so far.

The previous activation functions considered only the value of a single neuron as input, transformed that value, and output it. For example, if a neuron's value was -3, it converted that value to 0.
On the other hand, the Softmax function takes the values of many neurons as input, transforms them effectively using those values, and outputs multiple values.
Let's look at a concrete example.

For instance, consider creating an AI to classify animals using a neural network. Suppose there are 3 neurons in the input layer, 4 in the first hidden layer, 4 in the second hidden layer, and 3 in the output layer.
Let's feed an image of an animal into this neural network. Images are made of many numbers. When an image is input into the neural network, those numbers pass through the input layer and the hidden layers to reach the output layer.
Suppose the values of the three neurons that emerged in the output layer at this time are "1", "15", and "4", respectively.

In such a case, the result is the neuron with the "largest value" among the three.
For example:
- If the first neuron is the largest, the neural network determines that "the input image is a dog!"
- If the second neuron is the largest, the neural network determines that "the input image is a cat!"
- If the third neuron is the largest, the neural network determines that "the input image is a monkey!"
In this example, the output was "1", "15", and "4", so the second neuron is the largest. This means the neural network identified it as a "cat."
While these raw values are fine, the Softmax function converts this result into a "percentage representation" to make it easier to understand. In a case like dog "1", cat "15", and monkey "4", it transforms them into something like dog "5%", cat "75%", and monkey "20%". By using a percentage representation like this, the final results become much clearer.
The Softmax function is very commonly used as the activation function for the output layer in such classification problems.
5. Identity Function
Lastly, let's introduce the identity function. The identity function is an activation function that outputs the input as it is without any transformation.

You might think, "If it doesn't transform anything, what's the point of an activation function?" Indeed, it doesn't actually perform any processing.

However, this identity function becomes important when solving "regression problems."
A regression problem is a problem of predicting actual numerical values.

In the classification problem mentioned earlier, we prepared labels like "dog," "cat," and "monkey" and predicted which label fits and to what extent. Ultimately, each ratio is calculated as a percentage, and the one with the highest ratio becomes the identification result.
On the other hand, in regression problems, actual numbers are output, such as "tomorrow's average temperature is 15°C" or "next week's store sales are 220,000 yen." Simply put, classification problems predict ratios, while regression problems predict numerical values.
And the identity function is often used for the output layer of regression problems. It occupies the same position as the Softmax function mentioned earlier. Instead of calculating ratios like the Softmax function, by passing the raw values to the output, results such as 15°C or 220,000 yen can be output correctly.
To be honest, it's not a big problem even if it's not there.
Conclusion

In this article, I introduced 5 representative activation functions. By understanding the characteristics of each and using them appropriately, you can create more accurate artificial intelligence.
In the next article, I will introduce concepts such as the necessity of activation functions and non-linear transformations. Since it will include more advanced content, your understanding of activation functions will deepen further.
↓ Next... ↓
Discussion