Constant loss through epochs
I code this neural network to make a gaussian regression but I don't understand why my loss doesn't change through epochs. I set the learning rate to 1 to see the loss decreases but it does not. I chose to take 2000 poitns to train my Neural network. I watched several algorithms on this website and I don't really understand why my algorithm do not achieve what I expect.
I have already imported all libraries needed.
Thank you for your help

def f(x):
    return x * np.sin(x) # function to predict


m =2000 
X_bis = np.zeros((1,m),dtype = float)
X_bis=np.random.random(m)*10

        ## Create my training,validation and test set

X_train = X_bis[0:600]
X_val = X_bis[600:800]
X_test = X_bis[800:]

y_train = f(X_train) 
y_val = f(X_val)
y_test = f(X_test)
    
mean_X_train = np.mean(X_train)
std_X_train = np.std(X_train)

mean_y_train = np.mean(y_train)
std_y_train =np.std(y_train)


class MyDataset(data.Dataset):

    def __init__(self, data_feature, data_target):
        self.data_feature = data_feature
        self.data_target = data_target
       
    def __len__(self):
        return len(self.data_feature)
    
    def __getitem__(self, index):
        X_train_normalized = (self.data_feature[index] - mean_X_train) / std_X_train
        y_train_normalized = (self.data_target[index] - mean_y_train) / std_y_train
        return torch.from_numpy(np.array(X_train_normalized,ndmin=1)).float(), torch.from_numpy(np.array(y_train_normalized, ndmin = 1)).float()
                    
  
training_set  = MyDataset(X_train,y_train) 
train_loading = torch.utils.data.DataLoader(training_set, batch_size= 100)
    
val_set = MyDataset(X_val, y_val)  
val_loading = torch.utils.data.DataLoader(val_set, batch_size= 10)
    
test_set  = MyDataset(X_test,y_test) 
test_loading = torch.utils.data.DataLoader(test_set, batch_size= 100)


class Net(nn.Module):
  def __init__(self):
    super(Net, self).__init__()
    self.FC1 = nn.Linear(1,10)
    self.FC2 = nn.Linear(10, 1)
  def forward(self, x):
    x = F.relu(self.FC1(x)) 
    x = self.FC2(x)
    return x

model = Net()

criterion = nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(),
lr=1, weight_decay= 0.01, momentum = 0.9)



def train(net, train_loader, optimizer, epoch):
    net.train()
    total_loss=0
    for idx,(data, target) in enumerate(train_loader, 0):
        outputs = net(data)
        loss = criterion(outputs,target)
        total_loss +=loss.cpu().item()
        optimizer.step()
    print('Epoch:', epoch , 'average training loss ', total_loss/ len(train_loader))


def test(net,test_loader):
    net.eval()
    total_loss = 0
    for idx,(data, target) in enumerate(test_loader,0):
        outputs = net(data)
        outputs = outputs * std_X_train + mean_X_train
        target = target * std_y_train + mean_y_train
        loss = criterion(outputs,target)
        total_loss += sqrt(loss.cpu().item())
    print('average testing loss', total_loss/len(test_loader))
    
        
for epoch in range(50): 
    train(model,train_loading,optimizer,epoch)
    test(model,val_loading)    

'''
   


I'm wondering why you don't have loss.backward() after the line that you compute the loss (i.e., loss = criterion(outputs,target)) in your training snippet. This will help backpropagating and ultimately updating the parameters of your network upon optimizer.step(). Also, try using lower learning rates as lr=1 normally is too much in training such networks. Try using learning rates in between 0.001-0.01 to see if your network is learning the mapping between input X and target Y.
