majorado / IA

I invented a Mathematical Neuron model Y = Hz (Σ (weight * input) + bias) Activation of the layers in the frequencies of 8hz, 6hz and 4hz. Objective here is to enable "scalar learning" or SLM. With the reduction of the gradient, we obtain exponential transformation of the data, we can even make the matrix inversion diagonally and work with a sphere of the data volume. Deep Learning in exponential growth!
MIT License
0 stars 0 forks source link

Activation Functions: The Heartbeat of Neural Networks #13

Open majorado opened 1 month ago

majorado commented 1 month ago

Activation Functions: The Heartbeat of Neural Networks

Activation functions are the nonlinear mathematical functions introduced into the architecture of artificial neural networks (ANNs). They play a crucial role in enabling the network to learn complex patterns in data. Without activation functions, a neural network would simply be a linear model, incapable of capturing the intricacies of real-world data.

Understanding Activation Functions

Activation functions are applied to the output of each neuron in a neural network. Their primary purpose is to introduce non-linearity. Without this non-linearity, a neural network would be equivalent to a single-layer perceptron, and its ability to learn complex patterns would be severely limited.

Common Activation Functions

1. Sigmoid Function

The sigmoid function is one of the earliest activation functions used. It maps input values to a range of 0 to 1.

import numpy as np

def sigmoid(x):
  return 1 / (1 + np.exp(-x))

2. Tanh Function

Similar to the sigmoid function, the tanh function maps input values to a range of -1 to 1.

def tanh(x):
  return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))

3. ReLU (Rectified Linear Unit)

ReLU is the most commonly used activation function today. It returns the input if it is positive, otherwise it returns 0.

def relu(x):
  return np.maximum(0, x)

4. Leaky ReLU

Leaky ReLU is a variation of ReLU that allows a small, non-zero gradient for negative inputs.

def leaky_relu(x, alpha=0.01):
  return np.maximum(alpha*x, x)

5. Softmax Function

Softmax is often used in the output layer of classification models to produce probability-like values.

def softmax(x):
  exp_x = np.exp(x)
  return exp_x / np.sum(exp_x, axis=1, keepdims=True)

Choosing the Right Activation Function

The choice of activation function depends on several factors, including:

Advanced Activation Functions

While the above functions are commonly used, research has led to the development of more complex activation functions:

Using Activation Functions in Keras

Keras provides built-in activation functions for most common types. For custom activation functions, you can create a custom layer.

from tensorflow.keras.layers import Activation

model.add(Dense(64))
model.add(Activation('relu'))  # Using built-in ReLU

Conclusion

Activation functions are essential components of neural networks. Understanding their properties and choosing the right function for a specific problem is crucial for building effective models. By combining theoretical knowledge with practical implementation, you can effectively leverage activation functions to create powerful neural networks.