I find your problem interesting so I wrote my own solution for this, and it’s working fine. Check it out here:

  

      github.com
  

  
    llNeeleshll/PyTorch_Projects/blob/main/perceptron_pytorch_sine_function.ipynb 24


    {
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import numpy as np\r\n",
    "import torch\r\n",
    "import torch.nn as nn\r\n",
    "from torch.nn.modules.container import Sequential\r\n",
    "import matplotlib.pyplot as plt\r\n",
    "from sklearn.model_selection import train_test_split\r\n",
    "from torch.autograd import Variable"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,



  This file has been truncated. show original