BLOG · 26/10/2024
Learn the basics of ANNs and CNNs, their math, and Python implementations.
Neural Networks are a key component of artificial intelligence and machine learning. They are designed to recognize patterns and make decisions based on input data. Inspired by the human brain, these networks consist of layers of interconnected nodes (or neurons) that process information.
At their core, neural networks consist of interconnected nodes called neurons. These neurons are organized in layers:
1.Artificial Neural Networks (ANN):
import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
# Example of using sigmoid function
inputs = np.array([0.5, 0.1])
weights = np.array([0.4, 0.6])
bias = 0.2
weighted_sum = np.dot(inputs, weights) + bias
output = sigmoid(weighted_sum)
print(output)
2.Convolutional Neural Networks (CNN):
import tensorflow as tf
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
Neural networks, particularly ANNs and CNNs, form the backbone of many AI applications today. Understanding their structure and mathematical foundations is essential for anyone interested in exploring the field of machine learning.