I added the following code to the main module:
for name in pyro.get_param_store().get_all_param_names():
print("[%s]: %.3f" % (name, pyro.param(name).data.numpy()))
X = np.linspace(6, 7, num=20)
y = 3 * X + 1
X, y = X.reshape((20, 1)), y.reshape((20, 1))
x_data, y_data = Variable(torch.Tensor(X)), Variable(torch.Tensor(y))
loss = nn.MSELoss()
y_preds = Variable(torch.zeros(20, 1))
for i in range(20):
# guide does not require the data
sampled_reg_model = guide(None)
# run the regression model and add prediction to total
y_preds = y_preds + sampled_reg_model(x_data)
# take the average of the predictions
y_preds = y_preds / 20
print ("Loss: ", loss(y_preds, y_data).data[0])
and I go the error:
epoch avg loss 5.362271118164062
epoch avg loss 5.106288757324219
epoch avg loss 4.880701293945313
epoch avg loss 4.297378845214844
epoch avg loss 4.150056457519531
epoch avg loss 3.7338333129882812
epoch avg loss 3.8261447143554688
epoch avg loss 3.32685546875
epoch avg loss 2.7866165161132814
epoch avg loss 2.593047790527344
[guide_mean_weight]: 0.553
[guide_log_sigma_weight]: -2.794
[guide_mean_bias]: 0.590
[guide_log_sigma_bias]: -2.909
Traceback (most recent call last):
File "C:\sm\BottleRockets\Python\Pyro\bayesian_regression.py", line 157, in <module>
main(args)
File "C:\sm\BottleRockets\Python\Pyro\bayesian_regression.py", line 144, in main
sampled_reg_model = guide(None)
File "C:\sm\BottleRockets\Python\Pyro\bayesian_regression.py", line 75, in guide
w_mu = Variable(torch.randn(1, p).type_as(data.data), requires_grad=True)
AttributeError: 'NoneType' object has no attribute 'data'
Press any key to continue . . .
Any suggestions?
Charles