HTML generated from Jupyter notebook: linear-regression-pytorch-3.ipynb

Linear Regression using PyTorch

In [1]:
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
In [2]:
N = 10 # number of data points
m = .7
c = 0
x = np.linspace(0,2*np.pi,N)
y = m*x + c + np.random.normal(0,.3,x.shape)
plt.figure()
plt.plot(x,y,'o')
plt.xlabel('x')
plt.ylabel('y')
plt.title('2D data (#data = %d)' % N)
plt.show()
In [3]:
import torch

Dataset

In [4]:
from torch.utils.data import Dataset
class MyDataset(Dataset):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
    def __len__(self):
        return len(self.x)
    
    def __getitem__(self, idx):
        sample = {
            'feature': torch.tensor([1,self.x[idx]]), 
            'label': torch.tensor([self.y[idx]])}
        return sample
In [5]:
dataset = MyDataset(x, y)
for i in range(len(dataset)):
    sample = dataset[i]
    print(i, sample['feature'], sample['label'])
0 tensor([1., 0.]) tensor([0.1019])
1 tensor([1.0000, 0.6981]) tensor([0.3657])
2 tensor([1.0000, 1.3963]) tensor([0.7600])
3 tensor([1.0000, 2.0944]) tensor([1.5153])
4 tensor([1.0000, 2.7925]) tensor([2.3835])
5 tensor([1.0000, 3.4907]) tensor([3.0468])
6 tensor([1.0000, 4.1888]) tensor([2.5200])
7 tensor([1.0000, 4.8869]) tensor([3.6476])
8 tensor([1.0000, 5.5851]) tensor([3.9853])
9 tensor([1.0000, 6.2832]) tensor([4.6717])

Dataloader

In [6]:
from torch.utils.data import DataLoader

dataset = MyDataset(x, y)
batch_size = 4
shuffle = True
num_workers = 4
dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers)
In [7]:
import pprint as pp
for i_batch, samples in enumerate(dataloader):
    print('\nbatch# = %s' % i_batch)
    print('samples: ')
    pp.pprint(samples)
batch# = 0
samples: 
{'feature': tensor([[1.0000, 2.0944],
        [1.0000, 6.2832],
        [1.0000, 1.3963],
        [1.0000, 4.1888]]),
 'label': tensor([[1.5153],
        [4.6717],
        [0.7600],
        [2.5200]])}

batch# = 1
samples: 
{'feature': tensor([[1.0000, 5.5851],
        [1.0000, 2.7925],
        [1.0000, 0.0000],
        [1.0000, 3.4907]]),
 'label': tensor([[3.9853],
        [2.3835],
        [0.1019],
        [3.0468]])}

batch# = 2
samples: 
{'feature': tensor([[1.0000, 4.8869],
        [1.0000, 0.6981]]),
 'label': tensor([[3.6476],
        [0.3657]])}

Model

In [8]:
import torch.nn as nn
from torch.nn.parameter import Parameter
class MyModel(nn.Module):
    def __init__(self, input_dim, output_dim):
        super(MyModel, self).__init__()
        
        self.weight = Parameter(torch.Tensor(output_dim, input_dim))
        self.bias = Parameter(torch.Tensor(output_dim, 1))
        
        stdv = 1.
        self.weight.data.uniform_(-stdv, stdv)
        self.bias.data.uniform_(-stdv, stdv)
        
    def forward(self, x):
        weight_and_bias = torch.cat((self.weight, self.bias), 1)
        #print(weight_and_bias)
        #print(weight_and_bias.t().shape)
        #print(x.shape)
        #print(self.weight.size())
        
        out = x.matmul(weight_and_bias.t())
        return out

Setting a model for our problem

In [9]:
input_dim = 1
output_dim = 1

model = MyModel(input_dim, output_dim)

#model(torch.rand([5,2]))

Cost function

Often called loss or error

In [10]:
#cost = nn.MSELoss()
In [11]:
import torch.nn as nn
class MyLoss(nn.Module):
    def __init__(self):
        super(MyLoss, self).__init__()
        
    def forward(self, predictions, targets):
        print(predictions)
        print(targets)
        
        diff = torch.sub(predictions, targets)
        diff2 = torch.pow(diff, 2)
        err = torch.sum(diff2)
        return err
In [12]:
cost = MyLoss()

Minimizing the cost function

In other words training (or learning from data)

In [13]:
num_epochs = 100  # How many times the entire training data is seen?
l_rate = 0.01
optimiser = torch.optim.SGD(model.parameters(), lr = l_rate) 

dataset = MyDataset(x, y)
batch_size = 4
shuffle = True
num_workers = 4
training_sample_generator = DataLoader(dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers)

for epoch in range(num_epochs):
    if epoch % 10 == 0:
        print('Epoch = %s' % epoch)
    for batch_i, samples in enumerate(training_sample_generator):
        predictions = model(samples['feature'])
        error = cost(predictions, samples['label'])
        if epoch % 10 == 0:
            print('\tBatch = %s, Error = %s' % (batch_i, error.item()))
        
        # Before the backward pass, use the optimizer object to zero all of the
        # gradients for the variables it will update (which are the learnable
        # weights of the model). This is because by default, gradients are
        # accumulated in buffers( i.e, not overwritten) whenever .backward()
        # is called. Checkout docs of torch.autograd.backward for more details.
        optimiser.zero_grad()
        
        # Backward pass: compute gradient of the loss with respect to model
        # parameters
        error.backward()
        
        # Calling the step function on an Optimizer makes an update to its
        # parameters
        optimiser.step()
Epoch = 0
tensor([[2.1582],
        [1.2339],
        [1.0491],
        [1.7885]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [1.5153],
        [0.7600],
        [2.5200]])
	Batch = 0, Error = 4.036039352416992
tensor([[0.7303],
        [1.1031],
        [3.3394],
        [2.2212]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.3657],
        [3.6476],
        [2.3835]])
	Batch = 1, Error = 1.0599795579910278
tensor([[4.2485],
        [2.6769]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468]])
	Batch = 2, Error = 0.316006064414978
tensor([[2.9686],
        [1.1764],
        [4.3127],
        [3.8647]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.3657],
        [3.9853],
        [3.6476]])
tensor([[3.1245],
        [2.3173],
        [4.3354],
        [0.7028]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [2.3835],
        [4.6717],
        [0.1019]])
tensor([[1.4874],
        [1.8878]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [1.5153]])
tensor([[2.1658],
        [4.0423],
        [2.5411],
        [3.6670]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [4.6717],
        [3.0468],
        [3.9853]])
tensor([[4.1174],
        [2.1635],
        [1.1866],
        [3.6289]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [1.5153],
        [0.3657],
        [2.5200]])
tensor([[0.6372],
        [1.3664]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.7600]])
tensor([[1.3199],
        [0.9671],
        [3.0838],
        [1.6727]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.3657],
        [3.6476],
        [1.5153]])
tensor([[2.8184],
        [2.4486],
        [0.5992],
        [3.9281]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.0468],
        [0.1019],
        [4.6717]])
tensor([[4.1847],
        [2.3974]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [2.3835]])
tensor([[2.7595],
        [0.6059],
        [1.0366],
        [4.4824]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.1019],
        [0.3657],
        [4.6717]])
tensor([[1.9563],
        [4.2303],
        [3.7755],
        [1.5015]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [3.9853],
        [3.6476],
        [0.7600]])
tensor([[2.1593],
        [2.9585]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [2.5200]])
tensor([[0.5565],
        [3.2355],
        [3.6182],
        [2.4701]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.6476],
        [3.9853],
        [3.0468]])
tensor([[3.3800],
        [1.0421],
        [1.5097],
        [1.9773]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.3657],
        [0.7600],
        [1.5153]])
tensor([[2.0498],
        [3.9626]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [4.6717]])
tensor([[0.9982],
        [2.3716],
        [1.9138],
        [1.4560]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [2.3835],
        [1.5153],
        [0.7600]])
tensor([[4.3478],
        [3.4941],
        [3.0673],
        [2.6404]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.6476],
        [2.5200],
        [3.0468]])
tensor([[4.1412],
        [0.5129]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.1019]])
tensor([[0.5016],
        [0.9429],
        [3.1499],
        [2.7085]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.3657],
        [2.5200],
        [3.0468]])
tensor([[1.3070],
        [2.1378],
        [1.7224],
        [3.3840]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [2.3835],
        [1.5153],
        [3.6476]])
tensor([[3.8813],
        [4.3075]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [4.6717]])
tensor([[4.2112],
        [2.8122],
        [4.6775],
        [1.8796]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.0468],
        [4.6717],
        [1.5153]])
tensor([[1.3714],
        [0.4734],
        [2.2693],
        [3.1673]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.1019],
        [2.3835],
        [2.5200]])
tensor([[0.8468],
        [3.2687]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.6476]])
tensor([[1.2907],
        [2.5652],
        [0.8659],
        [1.7155]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.0468],
        [0.3657],
        [1.5153]])
tensor([[0.4261],
        [4.2710],
        [2.9894],
        [3.4166]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [4.6717],
        [2.5200],
        [3.6476]])
tensor([[4.0283],
        [2.2256]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [2.3835]])
Epoch = 10
tensor([[3.5996],
        [2.2391],
        [1.3321],
        [4.5066]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [2.3835],
        [0.7600],
        [4.6717]])
	Batch = 0, Error = 0.37773826718330383
tensor([[0.4208],
        [0.8866],
        [1.8181],
        [4.1467]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.3657],
        [1.5153],
        [3.9853]])
	Batch = 1, Error = 0.4907659888267517
tensor([[2.5909],
        [3.0301]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [2.5200]])
	Batch = 2, Error = 0.46807536482810974
tensor([[1.2569],
        [3.4149],
        [0.3937],
        [2.9833]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.6476],
        [0.1019],
        [2.5200]])
tensor([[4.0696],
        [0.7840],
        [1.6054],
        [2.0161]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657],
        [1.5153],
        [2.3835]])
tensor([[2.7382],
        [4.1516]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.9853]])
tensor([[3.2246],
        [4.1711],
        [1.3318],
        [0.8586]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.9853],
        [0.7600],
        [0.3657]])
tensor([[3.1572],
        [0.3463],
        [1.9525],
        [1.5510]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [0.1019],
        [2.3835],
        [1.5153]])
tensor([[2.6130],
        [4.4162]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [4.6717]])
tensor([[0.8672],
        [0.3729],
        [1.3616],
        [4.8220]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.1019],
        [0.7600],
        [4.6717]])
tensor([[2.6651],
        [3.5942],
        [4.0588],
        [3.1297]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.6476],
        [3.9853],
        [2.5200]])
tensor([[2.1191],
        [1.6737]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [1.5153]])
tensor([[3.0461],
        [2.1439],
        [1.6928],
        [3.4972]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [2.3835],
        [1.5153],
        [3.6476]])
tensor([[2.5070],
        [0.7680],
        [4.2459],
        [0.3333]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.3657],
        [4.6717],
        [0.1019]])
tensor([[1.3289],
        [4.2958]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.9853]])
tensor([[3.0774],
        [3.5366],
        [1.2407],
        [1.6999]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.6476],
        [0.7600],
        [1.5153]])
tensor([[4.0746],
        [0.7195],
        [3.6552],
        [1.9776]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657],
        [3.9853],
        [2.3835]])
tensor([[0.3197],
        [2.8692]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.0468]])
tensor([[0.3189],
        [3.4302],
        [1.8746],
        [1.3560]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [2.5200],
        [1.5153],
        [0.7600]])
tensor([[2.4932],
        [3.8228],
        [4.2660],
        [2.0500]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.9853],
        [4.6717],
        [2.3835]])
tensor([[4.0265],
        [0.8378]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [0.3657]])
tensor([[4.2973],
        [2.7943],
        [0.2893],
        [3.7963]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.0468],
        [0.1019],
        [3.6476]])
tensor([[1.2391],
        [4.5909],
        [1.7179],
        [3.1544]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [4.6717],
        [1.5153],
        [2.5200]])
tensor([[0.6903],
        [1.9909]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [2.3835]])
tensor([[2.9323],
        [3.8237],
        [1.1495],
        [0.2581]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.9853],
        [0.7600],
        [0.1019]])
tensor([[1.9486],
        [0.6687],
        [1.5220],
        [3.2284]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [0.3657],
        [1.5153],
        [3.6476]])
tensor([[4.4742],
        [2.5981]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468]])
tensor([[1.7906],
        [1.2824],
        [2.8070],
        [3.8235]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [0.7600],
        [3.0468],
        [3.6476]])
tensor([[4.6583],
        [0.7409],
        [0.2513],
        [2.2099]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657],
        [0.1019],
        [2.3835]])
tensor([[3.2083],
        [4.1962]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.9853]])
Epoch = 20
tensor([[2.8501],
        [1.5383],
        [1.9756],
        [4.1619]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [1.5153],
        [2.3835],
        [4.6717]])
	Batch = 0, Error = 0.5358420014381409
tensor([[0.7157],
        [0.2378],
        [1.1937],
        [4.0611]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.1019],
        [0.7600],
        [3.9853]])
	Batch = 1, Error = 0.33479544520378113
tensor([[3.4389],
        [2.5186]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.0468]])
	Batch = 2, Error = 0.32255789637565613
tensor([[3.7335],
        [2.7333],
        [0.2327],
        [4.2336]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.0468],
        [0.1019],
        [3.9853]])
tensor([[1.7002],
        [1.2100],
        [2.1903],
        [0.7198]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [0.7600],
        [2.3835],
        [0.3657]])
tensor([[4.5344],
        [3.0942]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.5200]])
tensor([[3.4148],
        [4.3319],
        [1.1221],
        [0.6635]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [4.6717],
        [0.7600],
        [0.3657]])
tensor([[0.2032],
        [3.1690],
        [4.1575],
        [2.6747]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [2.5200],
        [3.9853],
        [3.0468]])
tensor([[1.5754],
        [2.0364]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.3835]])
tensor([[0.6708],
        [3.5077],
        [3.0349],
        [1.1436]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.6476],
        [2.5200],
        [0.7600]])
tensor([[1.9439],
        [3.7111],
        [1.5021],
        [2.3857]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.9853],
        [1.5153],
        [3.0468]])
tensor([[0.2045],
        [4.8209]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [4.6717]])
tensor([[1.6990],
        [4.6981],
        [0.6993],
        [4.1982]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [4.6717],
        [0.3657],
        [3.9853]])
tensor([[3.0182],
        [3.4905],
        [0.1843],
        [2.0736]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.6476],
        [0.1019],
        [2.3835]])
tensor([[1.1140],
        [2.5119]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.0468]])
tensor([[2.6114],
        [3.0965],
        [0.6708],
        [0.1856]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [2.5200],
        [0.3657],
        [0.1019]])
tensor([[2.0538],
        [3.4628],
        [4.4021],
        [1.5841]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.6476],
        [4.6717],
        [1.5153]])
tensor([[4.3236],
        [1.2229]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.7600]])
tensor([[2.0988],
        [0.6547],
        [1.1361],
        [4.0244]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [0.3657],
        [0.7600],
        [3.9853]])
tensor([[1.6028],
        [3.0407],
        [4.4785],
        [0.1649]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.5200],
        [4.6717],
        [0.1019]])
tensor([[3.3980],
        [2.4715]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.0468]])
tensor([[4.2383],
        [2.7134],
        [2.2051],
        [1.1885]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.0468],
        [2.3835],
        [0.7600]])
tensor([[0.6719],
        [0.1685],
        [1.6788],
        [4.6994]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.1019],
        [1.5153],
        [4.6717]])
tensor([[3.6099],
        [3.1167]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [2.5200]])
tensor([[0.1460],
        [2.4506],
        [2.9115],
        [1.9897]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.0468],
        [2.5200],
        [2.3835]])
tensor([[3.5341],
        [1.1220],
        [1.6044],
        [4.0166]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [0.7600],
        [1.5153],
        [3.9853]])
tensor([[4.4524],
        [0.6278]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657]])
tensor([[4.1070],
        [0.6436],
        [4.6017],
        [2.1279]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.3657],
        [4.6717],
        [2.3835]])
tensor([[1.6434],
        [0.1474],
        [3.1394],
        [1.1447]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [0.1019],
        [2.5200],
        [0.7600]])
tensor([[3.2822],
        [2.3798]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.0468]])
Epoch = 30
tensor([[0.1445],
        [4.2136],
        [1.6704],
        [0.6531]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.9853],
        [1.5153],
        [0.3657]])
	Batch = 0, Error = 0.16057457029819489
tensor([[3.5147],
        [2.0642],
        [1.0972],
        [2.5477]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [2.3835],
        [0.7600],
        [3.0468]])
	Batch = 1, Error = 0.48238328099250793
tensor([[4.8474],
        [3.2791]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.5200]])
	Batch = 2, Error = 0.6071034669876099
tensor([[3.3645],
        [1.5127],
        [4.2904],
        [1.0497]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [1.5153],
        [4.6717],
        [0.7600]])
tensor([[2.6821],
        [4.2126],
        [3.1923],
        [0.6415]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.9853],
        [2.5200],
        [0.3657]])
tensor([[1.9879],
        [0.1151]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [0.1019]])
tensor([[2.0573],
        [1.5737],
        [1.0900],
        [0.1228]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [1.5153],
        [0.7600],
        [0.1019]])
tensor([[4.0267],
        [0.6093],
        [3.5385],
        [3.0503]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.3657],
        [3.6476],
        [2.5200]])
tensor([[4.2382],
        [2.4021]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468]])
tensor([[3.2994],
        [3.8279],
        [0.1286],
        [4.8849]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.6476],
        [0.1019],
        [4.6717]])
tensor([[1.4602],
        [3.7197],
        [2.3640],
        [1.9121]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [3.9853],
        [3.0468],
        [2.3835]])
tensor([[1.1858],
        [0.6599]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.3657]])
tensor([[1.1491],
        [3.7226],
        [1.6638],
        [4.2373]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.6476],
        [1.5153],
        [3.9853]])
tensor([[4.4045],
        [0.1024],
        [2.0144],
        [2.9704]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.1019],
        [2.3835],
        [2.5200]])
tensor([[2.5536],
        [0.5956]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.3657]])
tensor([[3.1792],
        [0.1114],
        [4.7131],
        [2.1566]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.1019],
        [4.6717],
        [2.3835]])
tensor([[2.4916],
        [3.4475],
        [1.5356],
        [1.0576]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.6476],
        [1.5153],
        [0.7600]])
tensor([[4.2088],
        [0.6227]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.3657]])
tensor([[3.0550],
        [0.1008],
        [0.5932],
        [2.0703]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.1019],
        [0.3657],
        [2.3835]])
tensor([[3.3893],
        [1.5051],
        [1.0340],
        [3.8604]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [1.5153],
        [0.7600],
        [3.9853]])
tensor([[2.5612],
        [4.5348]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [4.6717]])
tensor([[3.8102],
        [4.3393],
        [1.6939],
        [1.1649]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.9853],
        [1.5153],
        [0.7600]])
tensor([[2.9483],
        [1.9937],
        [0.0847],
        [2.4710]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [2.3835],
        [0.1019],
        [3.0468]])
tensor([[4.5550],
        [0.5913]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657]])
tensor([[3.1147],
        [2.1077],
        [0.5971],
        [1.6042]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [2.3835],
        [0.3657],
        [1.5153]])
tensor([[3.8779],
        [3.4032],
        [4.3525],
        [0.0808]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.6476],
        [4.6717],
        [0.1019]])
tensor([[2.7331],
        [1.1501]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.7600]])
tensor([[0.6285],
        [1.6993],
        [3.3054],
        [0.0932]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [1.5153],
        [2.5200],
        [0.1019]])
tensor([[2.4762],
        [3.4392],
        [3.9207],
        [1.0317]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.6476],
        [3.9853],
        [0.7600]])
tensor([[4.7897],
        [2.1732]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.3835]])
Epoch = 40
tensor([[2.6876],
        [3.7299],
        [0.6031],
        [1.6454]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.6476],
        [0.3657],
        [1.5153]])
	Batch = 0, Error = 0.20905181765556335
tensor([[0.0802],
        [1.1340],
        [4.2954],
        [4.8223]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.7600],
        [3.9853],
        [4.6717]])
	Batch = 1, Error = 0.2591085433959961
tensor([[1.9928],
        [2.9573]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [2.5200]])
	Batch = 2, Error = 0.34384119510650635
tensor([[0.5349],
        [0.0630],
        [3.8381],
        [3.3662]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.1019],
        [3.9853],
        [3.6476]])
tensor([[2.0726],
        [4.5773],
        [2.5736],
        [3.0745]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [4.6717],
        [3.0468],
        [2.5200]])
tensor([[1.0994],
        [1.6113]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [1.5153]])
tensor([[1.5743],
        [0.5693],
        [0.0667],
        [1.0718]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [0.3657],
        [0.1019],
        [0.7600]])
tensor([[3.0125],
        [3.9980],
        [2.5197],
        [3.5052]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.9853],
        [3.0468],
        [3.6476]])
tensor([[2.0527],
        [4.5446]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [4.6717]])
tensor([[1.6357],
        [2.6805],
        [3.2029],
        [2.1581]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [3.0468],
        [2.5200],
        [2.3835]])
tensor([[1.0754],
        [0.0641],
        [3.6034],
        [4.1090]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.1019],
        [3.6476],
        [3.9853]])
tensor([[0.5498],
        [4.4925]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [4.6717]])
tensor([[1.0704],
        [0.5637],
        [1.5772],
        [2.5907]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.3657],
        [1.5153],
        [3.0468]])
tensor([[0.0546],
        [3.1698],
        [3.6890],
        [4.7274]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [2.5200],
        [3.6476],
        [4.6717]])
tensor([[1.9346],
        [3.8285]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.9853]])
tensor([[3.5753],
        [1.0592],
        [2.0656],
        [2.5688]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [0.7600],
        [2.3835],
        [3.0468]])
tensor([[0.0641],
        [0.6021],
        [4.3682],
        [3.2922]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.3657],
        [3.9853],
        [2.5200]])
tensor([[1.4191],
        [4.1832]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [4.6717]])
tensor([[4.6059],
        [3.0869],
        [1.5678],
        [1.0615]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.5200],
        [1.5153],
        [0.7600]])
tensor([[0.0316],
        [3.8041],
        [0.5032],
        [1.9179]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.9853],
        [0.3657],
        [2.3835]])
tensor([[3.5608],
        [2.5558]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.0468]])
tensor([[0.0548],
        [2.7166],
        [4.3137],
        [3.7813]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.0468],
        [3.9853],
        [3.6476]])
tensor([[1.5943],
        [3.1355],
        [2.1080],
        [4.6766]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.5200],
        [2.3835],
        [4.6717]])
tensor([[1.0161],
        [0.5303]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.3657]])
tensor([[2.9110],
        [1.4736],
        [3.3902],
        [4.3484]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [1.5153],
        [3.6476],
        [4.6717]])
tensor([[0.5442],
        [2.5579],
        [4.0682],
        [1.0477]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.0468],
        [3.9853],
        [0.7600]])
tensor([[2.0934],
        [0.0396]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [0.1019]])
tensor([[2.6704],
        [0.0467],
        [3.7199],
        [0.5714]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.1019],
        [3.6476],
        [0.3657]])
tensor([[2.1944],
        [1.6582],
        [4.3390],
        [1.1221]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [1.5153],
        [3.9853],
        [0.7600]])
tensor([[4.5788],
        [3.0646]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.5200]])
Epoch = 50
tensor([[1.4704],
        [1.9514],
        [4.3565],
        [0.9894]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.3835],
        [4.6717],
        [0.7600]])
	Batch = 0, Error = 0.34073713421821594
tensor([[4.2175],
        [2.6504],
        [0.5609],
        [3.1728]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.0468],
        [0.3657],
        [2.5200]])
	Batch = 1, Error = 0.6752656102180481
tensor([[0.0249],
        [3.4094]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.6476]])
	Batch = 2, Error = 0.06266370415687561
tensor([[0.0312],
        [1.5305],
        [2.0302],
        [3.5295]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [1.5153],
        [2.3835],
        [3.6476]])
tensor([[1.0840],
        [3.1686],
        [4.7320],
        [4.2109]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [2.5200],
        [4.6717],
        [3.9853]])
tensor([[0.4706],
        [2.2866]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.0468]])
tensor([[0.0297],
        [1.4998],
        [2.4799],
        [3.9500]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [1.5153],
        [3.0468],
        [3.9853]])
tensor([[3.6896],
        [2.1270],
        [0.5644],
        [4.7314]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [2.3835],
        [0.3657],
        [4.6717]])
tensor([[3.1677],
        [1.0843]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.7600]])
tensor([[4.3129],
        [2.4064],
        [1.9297],
        [2.8830]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468],
        [2.3835],
        [2.5200]])
tensor([[1.1166],
        [4.3313],
        [0.0450],
        [1.6523]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.9853],
        [0.1019],
        [1.5153]])
tensor([[0.5272],
        [3.5143]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.6476]])
tensor([[1.0395],
        [1.5449],
        [4.5771],
        [0.5341]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [1.5153],
        [4.6717],
        [0.3657]])
tensor([[2.0440],
        [3.5611],
        [3.0554],
        [0.0211]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.6476],
        [2.5200],
        [0.1019]])
tensor([[2.4882],
        [3.9689]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.9853]])
tensor([[3.1643],
        [2.1202],
        [2.6423],
        [1.0761]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [2.3835],
        [3.0468],
        [0.7600]])
tensor([[0.0262],
        [1.5507],
        [3.5835],
        [0.5344]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [1.5153],
        [3.6476],
        [0.3657]])
tensor([[4.6138],
        [4.1039]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.9853]])
tensor([[0.5294],
        [1.5408],
        [2.0465],
        [0.0237]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [1.5153],
        [2.3835],
        [0.1019]])
tensor([[2.6107],
        [4.6768],
        [1.0612],
        [4.1603]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [4.6717],
        [0.7600],
        [3.9853]])
tensor([[3.6519],
        [3.1341]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [2.5200]])
tensor([[3.8677],
        [3.3861],
        [1.4597],
        [0.4965]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.6476],
        [1.5153],
        [0.3657]])
tensor([[4.6017],
        [2.0569],
        [2.5658],
        [1.0389]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.3835],
        [3.0468],
        [0.7600]])
tensor([[3.3081],
        [0.0330]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.1019]])
tensor([[2.5174],
        [2.0176],
        [3.5169],
        [0.0186]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [2.3835],
        [3.6476],
        [0.1019]])
tensor([[4.9795],
        [0.5895],
        [1.6870],
        [4.4307]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657],
        [1.5153],
        [3.9853]])
tensor([[2.8967],
        [0.9774]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.7600]])
tensor([[3.6343],
        [3.1807],
        [2.2736],
        [1.8201]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.6476],
        [3.0468],
        [2.3835]])
tensor([[3.4836],
        [1.7663],
        [0.0490],
        [1.1939]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [1.5153],
        [0.1019],
        [0.7600]])
tensor([[4.5196],
        [0.5174]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657]])
Epoch = 60
tensor([[0.0171],
        [3.6021],
        [2.0657],
        [0.5293]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.6476],
        [2.3835],
        [0.3657]])
	Batch = 0, Error = 0.1369948536157608
tensor([[1.0749],
        [4.2312],
        [1.6009],
        [4.7572]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.9853],
        [1.5153],
        [4.6717]])
	Batch = 1, Error = 0.17421618103981018
tensor([[2.9526],
        [2.4618]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.0468]])
	Batch = 2, Error = 0.5293147563934326
tensor([[2.9749],
        [2.4809],
        [0.0112],
        [0.9991]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.0468],
        [0.1019],
        [0.7600]])
tensor([[1.9715],
        [0.5007],
        [4.4228],
        [1.4812]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [0.3657],
        [4.6717],
        [1.5153]])
tensor([[3.7166],
        [4.2444]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.9853]])
tensor([[3.5357],
        [1.5239],
        [4.0386],
        [3.0327]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [1.5153],
        [3.9853],
        [2.5200]])
tensor([[0.4820],
        [4.2915],
        [0.0058],
        [2.3868]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [4.6717],
        [0.1019],
        [3.0468]])
tensor([[1.1074],
        [2.1886]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [2.3835]])
tensor([[2.7302],
        [0.0232],
        [1.1060],
        [2.1888]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.1019],
        [0.7600],
        [2.3835]])
tensor([[3.9318],
        [1.7011],
        [3.3742],
        [0.5858]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [1.5153],
        [2.5200],
        [0.3657]])
tensor([[3.8432],
        [4.3239]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [4.6717]])
tensor([[4.7081],
        [2.6187],
        [0.0070],
        [4.1858]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468],
        [0.1019],
        [3.9853]])
tensor([[3.1591],
        [2.1103],
        [0.5371],
        [1.5859]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [2.3835],
        [0.3657],
        [1.5153]])
tensor([[0.9884],
        [3.4581]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.6476]])
tensor([[ 4.5215],
        [ 2.5118],
        [ 1.0046],
        [-0.0002]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468],
        [0.7600],
        [0.1019]])
tensor([[4.3058],
        [0.5475],
        [3.7689],
        [2.1582]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.3657],
        [3.6476],
        [2.3835]])
tensor([[1.5346],
        [3.0665]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.5200]])
tensor([[ 1.4257],
        [ 1.9038],
        [ 3.8162],
        [-0.0086]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.3835],
        [3.9853],
        [0.1019]])
tensor([[3.5967],
        [3.0841],
        [2.5714],
        [4.6219]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [2.5200],
        [3.0468],
        [4.6717]])
tensor([[0.5192],
        [1.0299]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.7600]])
tensor([[1.5118],
        [4.5351],
        [4.0312],
        [3.5273]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [4.6717],
        [3.9853],
        [3.6476]])
tensor([[3.1281],
        [1.0456],
        [0.5250],
        [2.0868]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.7600],
        [0.3657],
        [2.3835]])
tensor([[ 2.4367],
        [-0.0107]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.1019]])
tensor([[2.5999],
        [2.0806],
        [4.1575],
        [1.0422]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [2.3835],
        [3.9853],
        [0.7600]])
tensor([[0.0096],
        [1.6113],
        [3.2130],
        [3.7469]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [1.5153],
        [2.5200],
        [3.6476]])
tensor([[4.3477],
        [0.4775]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657]])
tensor([[ 0.5091],
        [ 2.5535],
        [-0.0020],
        [ 1.5313]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.0468],
        [0.1019],
        [1.5153]])
tensor([[2.1399],
        [3.7397],
        [3.2065],
        [4.2730]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.6476],
        [2.5200],
        [3.9853]])
tensor([[0.9381],
        [4.2555]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [4.6717]])
Epoch = 70
tensor([[4.0507],
        [1.5159],
        [1.0089],
        [4.5577]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [1.5153],
        [0.7600],
        [4.6717]])
	Batch = 0, Error = 0.07924719899892807
tensor([[ 2.0190],
        [ 2.5260],
        [-0.0090],
        [ 0.4980]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.0468],
        [0.1019],
        [0.3657]])
	Batch = 1, Error = 0.4338834285736084
tensor([[3.2801],
        [3.8254]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.6476]])
	Batch = 2, Error = 0.6094035506248474
tensor([[3.8992],
        [1.9444],
        [1.4557],
        [2.4331]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [2.3835],
        [1.5153],
        [3.0468]])
tensor([[4.9113],
        [1.1019],
        [3.8229],
        [3.2787]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.7600],
        [3.6476],
        [2.5200]])
tensor([[ 0.4434],
        [-0.0168]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.1019]])
tensor([[ 0.9029],
        [-0.0160],
        [ 1.3623],
        [ 1.8217]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.1019],
        [1.5153],
        [2.3835]])
tensor([[2.8959],
        [0.4808],
        [3.8619],
        [2.4129]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.3657],
        [3.9853],
        [3.0468]])
tensor([[3.5061],
        [4.5070]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [4.6717]])
tensor([[2.1074],
        [2.6319],
        [4.7301],
        [3.6810]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.0468],
        [4.6717],
        [3.6476]])
tensor([[0.5694],
        [0.0212],
        [1.6656],
        [1.1175]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.1019],
        [1.5153],
        [0.7600]])
tensor([[3.2173],
        [4.2868]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [3.9853]])
tensor([[1.8706],
        [1.4001],
        [3.2820],
        [0.9296]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [1.5153],
        [3.6476],
        [0.7600]])
tensor([[2.5826],
        [4.1290],
        [3.0981],
        [0.0051]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.9853],
        [2.5200],
        [0.1019]])
tensor([[0.4950],
        [4.4398]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [4.6717]])
tensor([[2.5649],
        [3.0771],
        [1.0283],
        [1.5405]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [2.5200],
        [0.7600],
        [1.5153]])
tensor([[ 3.4764],
        [-0.0034],
        [ 1.9851],
        [ 0.4937]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [0.1019],
        [2.3835],
        [0.3657]])
tensor([[4.7153],
        [4.1922]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.9853]])
tensor([[2.0150],
        [3.5244],
        [3.0213],
        [0.5056]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [3.6476],
        [2.5200],
        [0.3657]])
tensor([[ 4.4565],
        [ 2.4756],
        [-0.0005],
        [ 1.4852]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468],
        [0.1019],
        [1.5153]])
tensor([[1.1035],
        [4.3605]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.9853]])
tensor([[0.5104],
        [4.0585],
        [4.5654],
        [3.5516]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.9853],
        [4.6717],
        [3.6476]])
tensor([[2.5814],
        [1.0345],
        [3.0970],
        [1.5501]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.7600],
        [2.5200],
        [1.5153]])
tensor([[-0.0052],
        [ 1.9876]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [2.3835]])
tensor([[4.6276],
        [3.6003],
        [3.0867],
        [0.0049]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.6476],
        [2.5200],
        [0.1019]])
tensor([[0.4849],
        [1.4601],
        [2.4353],
        [3.8980]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [1.5153],
        [3.0468],
        [3.9853]])
tensor([[1.0593],
        [2.1086]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [2.3835]])
tensor([[3.7163],
        [2.6572],
        [4.7754],
        [1.0686]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [3.0468],
        [4.6717],
        [0.7600]])
tensor([[0.5364],
        [2.1226],
        [3.1801],
        [0.0077]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [2.3835],
        [2.5200],
        [0.1019]])
tensor([[1.4941],
        [3.9873]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [3.9853]])
Epoch = 80
tensor([[ 2.9932],
        [-0.0015],
        [ 3.4923],
        [ 4.4905]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [0.1019],
        [3.6476],
        [4.6717]])
	Batch = 0, Error = 0.29155468940734863
tensor([[1.4917],
        [1.9896],
        [3.9813],
        [0.4958]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.3835],
        [3.9853],
        [0.3657]])
	Batch = 1, Error = 0.1726582795381546
tensor([[2.5688],
        [1.0298]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.7600]])
	Batch = 2, Error = 0.3012203872203827
tensor([[2.6632],
        [1.6011],
        [3.1942],
        [3.7253]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [1.5153],
        [2.5200],
        [3.6476]])
tensor([[1.0038],
        [0.5013],
        [2.0088],
        [4.0189]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [0.3657],
        [2.3835],
        [3.9853]])
tensor([[ 4.5739],
        [-0.0020]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.1019]])
tensor([[2.5871],
        [3.1041],
        [2.0701],
        [0.5191]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [2.5200],
        [2.3835],
        [0.3657]])
tensor([[1.0347],
        [1.5507],
        [0.0028],
        [4.6466]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [1.5153],
        [0.1019],
        [4.6717]])
tensor([[4.0934],
        [3.5816]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.6476]])
tensor([[2.0297],
        [0.5061],
        [4.5690],
        [1.0140]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [0.3657],
        [4.6717],
        [0.7600]])
tensor([[-0.0005],
        [ 3.1456],
        [ 2.6212],
        [ 4.1943]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [2.5200],
        [3.0468],
        [3.9853]])
tensor([[1.4700],
        [3.4388]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [3.6476]])
tensor([[4.5685],
        [2.0295],
        [3.5529],
        [1.5218]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.3835],
        [3.6476],
        [1.5153]])
tensor([[0.0093],
        [4.3047],
        [2.6939],
        [3.2308]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.9853],
        [3.0468],
        [2.5200]])
tensor([[0.4853],
        [0.9729]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [0.7600]])
tensor([[-0.0090],
        [ 3.3673],
        [ 4.3319],
        [ 2.4026]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [3.6476],
        [4.6717],
        [3.0468]])
tensor([[3.3945],
        [2.2691],
        [1.7065],
        [1.1438]], grad_fn=<MmBackward>)
tensor([[2.5200],
        [2.3835],
        [1.5153],
        [0.7600]])
tensor([[4.0150],
        [0.4947]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.3657]])
tensor([[1.9859],
        [4.4826],
        [2.4853],
        [2.9846]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [4.6717],
        [3.0468],
        [2.5200]])
tensor([[1.0655],
        [1.5971],
        [3.7236],
        [4.2553]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [1.5153],
        [3.6476],
        [3.9853]])
tensor([[-0.0124],
        [ 0.4846]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.3657]])
tensor([[2.4669],
        [3.9545],
        [1.9710],
        [0.9793]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.9853],
        [2.3835],
        [0.7600]])
tensor([[0.0036],
        [0.5419],
        [3.2337],
        [1.6187]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.3657],
        [2.5200],
        [1.5153]])
tensor([[3.4288],
        [4.4125]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [4.6717]])
tensor([[ 4.7611],
        [-0.0047],
        [ 3.1725],
        [ 1.0543]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.1019],
        [2.5200],
        [0.7600]])
tensor([[3.7990],
        [2.3657],
        [1.8879],
        [1.4101]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.0468],
        [2.3835],
        [1.5153]])
tensor([[0.5540],
        [3.8415]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.6476]])
tensor([[2.6627],
        [1.0641],
        [0.5312],
        [1.5970]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.7600],
        [0.3657],
        [1.5153]])
tensor([[ 4.3283],
        [ 2.1616],
        [-0.0050],
        [ 3.7866]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [2.3835],
        [0.1019],
        [3.6476]])
tensor([[4.6187],
        [3.0764]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [2.5200]])
Epoch = 90
tensor([[ 2.4129],
        [ 2.8990],
        [ 0.9543],
        [-0.0181]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [2.5200],
        [0.7600],
        [0.1019]])
	Batch = 0, Error = 0.5977063179016113
tensor([[1.9500],
        [0.4767],
        [4.4057],
        [1.4589]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [0.3657],
        [4.6717],
        [1.5153]])
	Batch = 1, Error = 0.27414506673812866
tensor([[4.2539],
        [3.7220]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [3.6476]])
	Batch = 2, Error = 0.07766690850257874
tensor([[4.0389],
        [1.0034],
        [3.5330],
        [0.4975]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.7600],
        [3.6476],
        [0.3657]])
tensor([[ 4.5171],
        [ 2.5029],
        [ 3.0065],
        [-0.0147]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.0468],
        [2.5200],
        [0.1019]])
tensor([[2.0525],
        [1.5373]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [1.5153]])
tensor([[1.5803],
        [4.2174],
        [2.1077],
        [3.1625]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [3.9853],
        [2.3835],
        [2.5200]])
tensor([[-0.0152],
        [ 0.9459],
        [ 2.3877],
        [ 4.3101]], grad_fn=<MmBackward>)
tensor([[0.1019],
        [0.7600],
        [3.0468],
        [4.6717]])
tensor([[3.7895],
        [0.5446]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [0.3657]])
tensor([[4.7619],
        [0.5268],
        [4.2325],
        [1.5856]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [0.3657],
        [3.9853],
        [1.5153]])
tensor([[ 1.9803],
        [ 2.9775],
        [ 0.9832],
        [-0.0140]], grad_fn=<MmBackward>)
tensor([[2.3835],
        [2.5200],
        [0.7600],
        [0.1019]])
tensor([[2.3987],
        [3.3651]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.6476]])
tensor([[0.5354],
        [4.8079],
        [1.0695],
        [0.0014]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [4.6717],
        [0.7600],
        [0.1019]])
tensor([[4.1065],
        [2.0488],
        [1.5344],
        [3.0776]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [2.3835],
        [1.5153],
        [2.5200]])
tensor([[2.4081],
        [3.3778]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [3.6476]])
tensor([[1.6052],
        [2.1396],
        [4.2771],
        [3.2084]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.3835],
        [3.9853],
        [2.5200]])
tensor([[ 0.4637],
        [ 4.2898],
        [-0.0145],
        [ 2.3768]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [4.6717],
        [0.1019],
        [3.0468]])
tensor([[3.8112],
        [1.0938]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [0.7600]])
tensor([[3.6775],
        [2.1001],
        [2.6259],
        [1.0485]], grad_fn=<MmBackward>)
tensor([[3.6476],
        [2.3835],
        [3.0468],
        [0.7600]])
tensor([[0.5543],
        [1.6537],
        [0.0046],
        [3.3028]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [1.5153],
        [0.1019],
        [2.5200]])
tensor([[4.4666],
        [3.9686]], grad_fn=<MmBackward>)
tensor([[4.6717],
        [3.9853]])
tensor([[0.5062],
        [3.0928],
        [1.5408],
        [2.0581]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [2.5200],
        [1.5153],
        [2.3835]])
tensor([[0.9694],
        [4.4301],
        [3.9357],
        [3.4413]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [4.6717],
        [3.9853],
        [3.6476]])
tensor([[ 2.6336],
        [-0.0137]], grad_fn=<MmBackward>)
tensor([[3.0468],
        [0.1019]])
tensor([[ 0.5465],
        [ 2.7449],
        [ 2.1953],
        [-0.0031]], grad_fn=<MmBackward>)
tensor([[0.3657],
        [3.0468],
        [2.3835],
        [0.1019]])
tensor([[1.7148],
        [5.1342],
        [3.9944],
        [3.4245]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [4.6717],
        [3.6476],
        [2.5200]])
tensor([[3.5423],
        [0.8608]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [0.7600]])
tensor([[0.9328],
        [2.3713],
        [0.4533],
        [2.8508]], grad_fn=<MmBackward>)
tensor([[0.7600],
        [3.0468],
        [0.3657],
        [2.5200]])
tensor([[ 1.4420],
        [ 1.9309],
        [-0.0245],
        [ 3.3975]], grad_fn=<MmBackward>)
tensor([[1.5153],
        [2.3835],
        [0.1019],
        [3.6476]])
tensor([[4.1992],
        [4.7250]], grad_fn=<MmBackward>)
tensor([[3.9853],
        [4.6717]])

Lets see how well the model has learnt the data

In [14]:
#from torch.autograd.variable import Variable

x_for_plotting = np.linspace(0, 2*np.pi, 1000)
design_matrix = torch.tensor(np.vstack([np.ones(x_for_plotting.shape), x_for_plotting]).T, dtype=torch.float32)
#print('Design matrix:\n', design_matrix)
print('Design matrix shape:', design_matrix.shape)

y_for_plotting = model.forward(design_matrix)
print('y_for_plotting shape:', y_for_plotting.shape)
Design matrix shape: torch.Size([1000, 2])
y_for_plotting shape: torch.Size([1000, 1])
In [15]:
plt.figure()
plt.plot(x,y,'o')
plt.plot(x_for_plotting, y_for_plotting.data.numpy(), 'r-')
plt.xlabel('x')
plt.ylabel('y')
plt.title('2D data (#data = %d)' % N)
plt.show()