From 97b9accb9850711495bae4ecdb4c633f2a4d1b69 Mon Sep 17 00:00:00 2001 From: shravya312 Date: Sun, 10 Nov 2024 19:56:07 +0530 Subject: [PATCH 1/6] added RNN ML Algorithm --- docs/algorithms/RNN-ML-algorithm.md | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 docs/algorithms/RNN-ML-algorithm.md diff --git a/docs/algorithms/RNN-ML-algorithm.md b/docs/algorithms/RNN-ML-algorithm.md new file mode 100644 index 000000000..fdab1dc0b --- /dev/null +++ b/docs/algorithms/RNN-ML-algorithm.md @@ -0,0 +1,81 @@ +--- +id: rnn-ml-algorithm +title: Recurrent Neural Network (RNN) ML Algorithm +sidebar_label: RNN ML Algorithm +sidebar_position: 16 +description: "Recurrent Neural Networks (RNNs) are a type of neural network designed to recognize patterns in sequences of data, including time-series data, language processing, and other sequence-related tasks." +tags: [Neural Networks, Deep Learning, RNN, Sequence Modeling, NLP] +--- + +# Recurrent Neural Network (RNN) Algorithm + +## Overview +**Recurrent Neural Networks (RNNs)** are a type of neural network architecture tailored for sequential data. Unlike traditional feedforward neural networks, RNNs include cycles that allow them to maintain information across sequence steps. This makes RNNs ideal for tasks such as time-series forecasting, natural language processing (NLP), and other applications where order and context are crucial. + +## Problem Description +- **Input**: A sequence of data points, which may be a series of numbers, words, or any sequential data. + - Each element depends on the previous ones. + - Examples include sentences for NLP tasks or daily stock prices for time-series analysis. +- **Output**: Predictions or classifications based on the input sequence, such as forecasting future values or understanding text sentiment. +- **Challenges**: Traditional neural networks struggle with sequential dependencies and temporal patterns, while RNNs excel in capturing such dependencies through hidden states. + +## Solution Approach +**RNNs** process sequence data step-by-step, updating a **hidden state** that carries forward information from each previous step. This enables RNNs to remember context across the sequence, making them suitable for sequence-based learning tasks. + +### Key Steps +1. **Sequential Processing**: Process input data one element at a time, updating the hidden state at each step. +2. **Hidden State Calculation**: Each new hidden state is calculated based on the current input and the previous hidden state. +3. **Output Generation**: RNNs can produce an output at each step or only at the end of the sequence, depending on the task. +4. **Backpropagation Through Time (BPTT)**: Training RNNs requires a modified backpropagation process that considers the dependencies across the sequence. + +## Code Example (RNN in PyTorch) +The following is a simple implementation of an RNN model in PyTorch for processing sequential data. + +```python +import torch +import torch.nn as nn + +class SimpleRNN(nn.Module): + def __init__(self, input_size, hidden_size, output_size): + super(SimpleRNN, self).__init__() + self.hidden_size = hidden_size + self.rnn = nn.RNN(input_size, hidden_size, batch_first=True) + self.fc = nn.Linear(hidden_size, output_size) + + def forward(self, x): + h0 = torch.zeros(1, x.size(0), self.hidden_size) # Initial hidden state + out, _ = self.rnn(x, h0) # Pass through RNN + out = self.fc(out[:, -1, :]) # Pass through fully connected layer + return out + +# Example usage +model = SimpleRNN(input_size=10, hidden_size=20, output_size=1) +input_seq = torch.randn(5, 10, 10) # Example input sequence (batch_size=5, seq_len=10, input_size=10) +output = model(input_seq) +print(output) +``` + +## Complexity Analysis + +### Time Complexity +RNNs process data sequentially, making them computationally intensive for long sequences. + +- **Time Complexity**: `O(T)` + Each step in a sequence of length `T` requires constant time to process. + +### Space Complexity +RNNs maintain a hidden state for each step in the sequence. + +- **Space Complexity**: `O(T * H)` + Where `T` is the sequence length and `H` is the hidden size. + +## Applications + +- **Natural Language Processing (NLP)**: Utilized in tasks such as language modeling, sentiment analysis, and machine translation. +- **Time-Series Forecasting**: Ideal for predicting stock prices, weather, and other time-dependent data. +- **Speech Recognition**: Recognizes patterns in audio data, such as phonemes or words. +- **Image Captioning**: When combined with CNNs, RNNs can generate textual descriptions of images by interpreting sequences of image features. + +## Conclusion + +Recurrent Neural Networks are foundational models for sequential data tasks, allowing models to learn temporal dependencies. However, traditional RNNs face challenges with long-term dependencies, which are addressed by advanced architectures like Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU). Despite these limitations, RNNs remain widely used in NLP, time-series analysis, and other temporal applications. From 877a1e48b66ecb3d1c8e9760d1459c23db72e856 Mon Sep 17 00:00:00 2001 From: shravya312 Date: Sun, 10 Nov 2024 20:01:50 +0530 Subject: [PATCH 2/6] Added Computer Vision ML theory --- docs/algorithms/Computer-Vision-ML-Theory.md | 84 ++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 docs/algorithms/Computer-Vision-ML-Theory.md diff --git a/docs/algorithms/Computer-Vision-ML-Theory.md b/docs/algorithms/Computer-Vision-ML-Theory.md new file mode 100644 index 000000000..976d6767d --- /dev/null +++ b/docs/algorithms/Computer-Vision-ML-Theory.md @@ -0,0 +1,84 @@ +--- +id: computer-vision-algorithm +title: Computer Vision (CV) - An Overview +sidebar_label: Computer Vision Algorithm +sidebar_position: 17 +description: "Computer Vision (CV) enables machines to interpret and understand visual data from the world. It is widely applied in tasks such as object detection, image classification, and facial recognition." +tags: [Computer Vision, Deep Learning, Image Processing, Object Detection, Image Classification] +--- + +# Computer Vision (CV) - An Overview + +## Overview +**Computer Vision (CV)** is a field of artificial intelligence that enables computers to interpret and process visual information from the world, simulating human vision. CV techniques involve extracting features from images or videos, recognizing objects, and understanding spatial arrangements, which are fundamental to applications such as object detection, facial recognition, and autonomous driving. + +## Problem Description +- **Input**: Visual data, typically in the form of images or video frames. + - Each pixel or region in an image contains meaningful information, such as color, intensity, or texture. + - Examples include photographs for object classification or video feeds for real-time motion tracking. +- **Output**: Analysis, classification, or interpretation of the input data, such as identifying objects, detecting anomalies, or segmenting image regions. +- **Challenges**: Variability in lighting, scale, and perspective, as well as occlusions and background noise, make visual understanding complex and computationally intensive. + +## Solution Approach +**Computer Vision** employs multiple techniques to interpret and classify visual data, ranging from traditional image processing methods to advanced deep learning models. + +### Key Steps +1. **Preprocessing**: Prepare images through resizing, normalization, and augmentation to ensure consistency and improve model robustness. +2. **Feature Extraction**: Identify relevant visual features using filters or convolutional layers, which help the model understand shapes, edges, and textures. +3. **Object Detection and Classification**: Use algorithms to identify and categorize objects within images, often with convolutional neural networks (CNNs) or region-based methods. +4. **Post-processing**: Refine predictions through methods like non-maximum suppression (NMS) in object detection to reduce duplicate predictions. + +## Code Example (Image Classification using CNN in PyTorch) +The following is a basic example of a Convolutional Neural Network (CNN) implementation in PyTorch for classifying images. + +```python +import torch +import torch.nn as nn + +class SimpleCNN(nn.Module): + def __init__(self, num_classes): + super(SimpleCNN, self).__init__() + self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1) + self.conv2 = nn.Conv2d(16, 32, kernel_size=3, stride=1, padding=1) + self.fc1 = nn.Linear(32 * 8 * 8, 128) + self.fc2 = nn.Linear(128, num_classes) + self.pool = nn.MaxPool2d(2, 2) + self.relu = nn.ReLU() + + def forward(self, x): + x = self.pool(self.relu(self.conv1(x))) + x = self.pool(self.relu(self.conv2(x))) + x = x.view(-1, 32 * 8 * 8) + x = self.relu(self.fc1(x)) + x = self.fc2(x) + return x + +# Example usage +model = SimpleCNN(num_classes=10) +input_image = torch.randn(5, 3, 32, 32) # Example input image (batch_size=5, channels=3, height=32, width=32) +output = model(input_image) +print(output) +``` +# Computer Vision Complexity Analysis + +## Time Complexity +Computer Vision models, especially Convolutional Neural Networks (CNNs), require substantial computation for processing large images and multi-layer feature extraction. + +- **Time Complexity**: `O(W * H * D * K^2)` + - Where `W` and `H` are the width and height of the input image, `D` is the depth (channels), and `K` is the kernel size. + +## Space Complexity +Space requirements grow with the number of features extracted and the depth of the network layers. + +- **Space Complexity**: `O(N * W * H * D)` + - Where `N` is the number of images, `W` and `H` are the width and height, and `D` is the depth of the features stored at each layer. + +## Applications +1. **Object Detection**: Identifies and localizes objects in images, used in autonomous driving, surveillance, and more. +2. **Facial Recognition**: Recognizes and verifies individual faces for security, authentication, and tagging. +3. **Medical Imaging**: Analyzes medical scans (e.g., X-rays, MRIs) to assist in diagnosing diseases. +4. **Image Segmentation**: Divides images into segments to understand structure, used in autonomous navigation and medical imaging. +5. **Optical Character Recognition (OCR)**: Extracts text from images or scanned documents for digitization and analysis. + +## Conclusion +Computer Vision is integral to enabling machines to interpret the visual world. While CNNs are foundational models for many CV tasks, advanced architectures like Faster R-CNN, YOLO (You Only Look Once), and Mask R-CNN provide more accurate and efficient solutions for object detection and image segmentation. Despite challenges like high computational demands and sensitivity to variations, CV applications continue to expand, impacting fields such as healthcare, transportation, and security. From 27373c23a471638d2982b5dd09c4d3f8a2582060 Mon Sep 17 00:00:00 2001 From: shravya312 Date: Sun, 10 Nov 2024 20:08:19 +0530 Subject: [PATCH 3/6] Added Generative Adversial Network ML Algorithm theory --- docs/algorithms/GAN-ML-Algorithm.md | 108 ++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 docs/algorithms/GAN-ML-Algorithm.md diff --git a/docs/algorithms/GAN-ML-Algorithm.md b/docs/algorithms/GAN-ML-Algorithm.md new file mode 100644 index 000000000..7c8407e11 --- /dev/null +++ b/docs/algorithms/GAN-ML-Algorithm.md @@ -0,0 +1,108 @@ +--- +id: generative-adversarial-networks +title: Generative Adversarial Networks (GANs) - An Overview +sidebar_label: Generative Adversarial Networks +sidebar_position: 18 +description: "Generative Adversarial Networks (GANs) are a deep learning model that generate new data samples by training two neural networks in opposition. They are widely used in tasks such as image generation, style transfer, and data augmentation." +tags: [Generative Models, Deep Learning, Image Generation, Data Augmentation, GAN] +--- + +# Generative Adversarial Networks (GANs) - An Overview + +## Overview +**Generative Adversarial Networks (GANs)** are a class of deep learning models designed to generate realistic data samples. Introduced by Ian Goodfellow in 2014, GANs consist of two neural networks—the Generator and the Discriminator—that are trained in opposition to each other to produce high-quality, realistic outputs, such as images, text, or audio. + +## Problem Description +- **Input**: Random noise vector, typically sampled from a uniform or Gaussian distribution. + - The noise vector serves as the seed input for the Generator to create synthetic data samples. +- **Output**: Generated data that resembles real data from the original dataset. + - For instance, GANs can generate realistic images that are visually indistinguishable from real photographs. +- **Challenges**: Training instability, mode collapse, and sensitivity to hyperparameters make GANs challenging to optimize effectively. + +## Solution Approach +**GANs** use two networks—the Generator and Discriminator—to improve each other iteratively, resulting in the generation of realistic samples. + +### Key Steps +1. **Generator Network**: Produces synthetic data by transforming random noise into a structured output resembling real data. +2. **Discriminator Network**: Classifies inputs as real (from the dataset) or fake (from the Generator), acting as an adversary to the Generator. +3. **Adversarial Training**: The Generator and Discriminator are trained in an adversarial process, where the Generator tries to fool the Discriminator, and the Discriminator improves at detecting fake samples. +4. **Loss Optimization**: The GAN training objective is to minimize the Generator's loss (for fooling the Discriminator) while maximizing the Discriminator's accuracy in distinguishing real from generated samples. + +## Code Example (Basic GAN in PyTorch) +The following is a basic example of a GAN implementation in PyTorch for generating synthetic data. + +```python +import torch +import torch.nn as nn + +# Define Generator +class Generator(nn.Module): + def __init__(self, noise_dim, output_dim): + super(Generator, self).__init__() + self.fc = nn.Sequential( + nn.Linear(noise_dim, 128), + nn.ReLU(), + nn.Linear(128, output_dim), + nn.Tanh() + ) + + def forward(self, x): + return self.fc(x) + +# Define Discriminator +class Discriminator(nn.Module): + def __init__(self, input_dim): + super(Discriminator, self).__init__() + self.fc = nn.Sequential( + nn.Linear(input_dim, 128), + nn.ReLU(), + nn.Linear(128, 1), + nn.Sigmoid() + ) + + def forward(self, x): + return self.fc(x) + +# Example usage +noise_dim = 100 +output_dim = 784 # Example for 28x28 images (e.g., MNIST) +gen = Generator(noise_dim, output_dim) +disc = Discriminator(output_dim) + +noise = torch.randn(5, noise_dim) # Generate random noise +generated_data = gen(noise) +disc_output = disc(generated_data) +print(disc_output) +``` +## Complexity Analysis + +### Time Complexity +GANs require intensive computations due to the adversarial training of two networks. + +- **Time Complexity:** O(N * L * D * K^2) + Where: + - **N** = Number of training samples + - **L** = Number of layers in each network + - **D** = Depth (channels) + - **K** = Kernel size in convolutional GAN architectures + +### Space Complexity +The memory requirement grows with the depth and size of both the Generator and Discriminator networks. + +- **Space Complexity:** O(N * L * D * W * H) + Where: + - **N** = Batch size + - **L** = Number of layers + - **D** = Depth of features + - **W** = Width of spatial dimensions + - **H** = Height of spatial dimensions + +## Applications +- **Image Generation:** Generates high-quality synthetic images used in art, gaming, and virtual environments. +- **Style Transfer:** Alters images to match the style of a reference image, used in visual effects and photo editing. +- **Data Augmentation:** Generates new samples to augment limited datasets, especially useful in medical and scientific research. +- **Super-Resolution:** Enhances image resolution, used in applications like satellite imagery and medical imaging. +- **Anomaly Detection:** Identifies unusual patterns by training GANs to recognize deviations, useful in fraud detection and medical diagnostics. + +## Conclusion +GANs represent a groundbreaking approach in generative modeling, enabling machines to create data indistinguishable from real-world data. Despite training challenges, advancements like Wasserstein GANs and StyleGAN have significantly improved the quality and stability of generated outputs. GANs are now integral to fields such as creative arts, data synthesis, and simulation, with their impact continuing to expand across industries. From 0dd110cd0ccc433588ac4469cc4ec890d68bc4f8 Mon Sep 17 00:00:00 2001 From: shravya312 Date: Sun, 10 Nov 2024 20:50:38 +0530 Subject: [PATCH 4/6] modified GAN --- docs/algorithms/GAN-ML-Algorithm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/algorithms/GAN-ML-Algorithm.md b/docs/algorithms/GAN-ML-Algorithm.md index 7c8407e11..108e7d247 100644 --- a/docs/algorithms/GAN-ML-Algorithm.md +++ b/docs/algorithms/GAN-ML-Algorithm.md @@ -1,6 +1,6 @@ --- id: generative-adversarial-networks -title: Generative Adversarial Networks (GANs) - An Overview +title: "Generative Adversarial Networks (GANs) - An Overview" sidebar_label: Generative Adversarial Networks sidebar_position: 18 description: "Generative Adversarial Networks (GANs) are a deep learning model that generate new data samples by training two neural networks in opposition. They are widely used in tasks such as image generation, style transfer, and data augmentation." From b9255b146c04615006a2c110b5e8becb3b1d1819 Mon Sep 17 00:00:00 2001 From: shravya312 Date: Sun, 10 Nov 2024 20:51:54 +0530 Subject: [PATCH 5/6] Added CV ML algorithm --- docs/algorithms/Computer-Vision-ML-Theory.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/algorithms/Computer-Vision-ML-Theory.md b/docs/algorithms/Computer-Vision-ML-Theory.md index 976d6767d..bd575d0cc 100644 --- a/docs/algorithms/Computer-Vision-ML-Theory.md +++ b/docs/algorithms/Computer-Vision-ML-Theory.md @@ -1,6 +1,6 @@ --- id: computer-vision-algorithm -title: Computer Vision (CV) - An Overview +title: "Computer Vision (CV) - An Overview" sidebar_label: Computer Vision Algorithm sidebar_position: 17 description: "Computer Vision (CV) enables machines to interpret and understand visual data from the world. It is widely applied in tasks such as object detection, image classification, and facial recognition." From 4bf14eee6649ecb7500958b97aac8a2652297a0b Mon Sep 17 00:00:00 2001 From: shravya312 Date: Sun, 10 Nov 2024 20:52:44 +0530 Subject: [PATCH 6/6] modified RNN --- docs/algorithms/RNN-ML-algorithm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/algorithms/RNN-ML-algorithm.md b/docs/algorithms/RNN-ML-algorithm.md index fdab1dc0b..fbde45f21 100644 --- a/docs/algorithms/RNN-ML-algorithm.md +++ b/docs/algorithms/RNN-ML-algorithm.md @@ -1,6 +1,6 @@ --- id: rnn-ml-algorithm -title: Recurrent Neural Network (RNN) ML Algorithm +title: "Recurrent Neural Network (RNN) ML Algorithm" sidebar_label: RNN ML Algorithm sidebar_position: 16 description: "Recurrent Neural Networks (RNNs) are a type of neural network designed to recognize patterns in sequences of data, including time-series data, language processing, and other sequence-related tasks."