Skip to content

g-nitin/nn-sin-approximation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Network Approximation of sin(x)

Description

This repository contains Python code for a neural network that approximates the sin(x) function.

The code demonstrates how to:

  • Load and prepare PyTorch tensors for data.
  • Split data into training and testing sets.
  • Create a data loader for batch processing.
  • Define and train a neural network model.
  • Evaluate the model's performance on test data.
  • Make predictions using the trained model.
  • Plot the actual sin(x) function and the model's predictions for visualization.

Model summary (generated by torchsummary)

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Linear-1                  [-1, 500]           1,000
            Linear-2                 [-1, 1000]         501,000
            Linear-3                    [-1, 1]           1,001
================================================================
Total params: 503,001
Trainable params: 503,001
Non-trainable params: 0
----------------------------------------------------------------

Requirements

  • Python 3.x
  • PyTorch
  • scikit-learn
  • Matplotlib
  • torchsummary (optional)

For exact versions, check requirements.txt.

Instructions

git clone https://github.com/g-nitin/nn-sin-approximation.git
cd nn-sin-approximation
pip install -r requirements.txt

python3 main.py

Directory Structure

  • sin_network.py contains the network to approximate sin and functions to train and evaluate it.
  • utilities.py contains helper functions to plot the predictions.
  • main.py contains the main function.
  • The plots subfolder contains different plots created by various training sizes.
  • The models subfolder contains the various models based on the training size.

Results

result.png
Actual v. Predicted sin(x)

About

Approximates sin(x) with neural network

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages