Bayesian Linear Regression output definition

• What tutorial are you running? Bayesian Linear Regression (Part 1)

I am reading the Bayesian Linear Regression tutorial (Part 1) and trying to understand the data and the problem formulation before running the code, but one thing is bugging me. The description says:

`> We would like to predict log GDP per capita of a nation as a function of two features from the dataset - whether the nation is in Africa, and its Terrain Ruggedness Index. Let’s define our regression model. We’ll use PyTorch’s nn.Module for this. Our input X is a matrix of size N×2 and our output y is a vector of size 2×1`

The text just talks about predicting log GDP, and this is a regression problem. I’d expect just a single output. So, for each output, predictions would be Nx1. What is that 2 doing there? The code itself indicates one output node, but it irked me that I didn’t understand the description, so hoping to get clarification here.

Is it just a typo?

Thanks
Alex

Furthermore, running the tutorial code (using Pyro 0.3.4 / PyTorch 1.1.0) results in an error:

``````loc = torch.zeros(1, 1)
scale = torch.ones(1, 1)
# define a unit normal prior
prior = Normal(loc, scale)
# overload the parameters in the regression module with samples from the prior
lifted_module = pyro.random_module("regression_module", nn, prior)
# sample a nn from the prior
sampled_reg_model = lifted_module()
``````

This results in:

``````---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-6-16f3d4cc1dc8> in <module>
4 prior = Normal(loc, scale)
5 # overload the parameters in the regression module with samples from the prior
----> 6 lifted_module = pyro.random_module("regression_module", nn, prior)
7 # sample a nn from the prior
8 sampled_reg_model = lifted_module()

~/anaconda3/envs/pytorch/lib/python3.7/site-packages/pyro/primitives.py in random_module(name, nn_module, prior, *args, **kwargs)
308     :returns: a callable which returns a sampled module
309     """
--> 310     assert hasattr(nn_module, "parameters"), "Module is not a NN module."
311     # register params in param store
312     lifted_fn = poutine.lift(module, prior=prior)

AssertionError: Module is not a NN module.
``````

I’m starting to think these tutorials might not be as reliable as I had originally hoped.

Alex

Hi, thanks for pointing these out.

for each output, predictions would be Nx1. What is that 2 doing there?

You are correct, this is a typo and should read Nx1. Feel free to submit a PR fixing this!

Furthermore, running the tutorial code (using Pyro 0.3.4 / PyTorch 1.1.0) results in an error

The snippet you tried to run is intended to briefly introduce the idea of `random_module` without lots of tensor shape boilerplate, which is why it’s not in a runnable cell of its own. The runnable version for the tutorial’s model is just below, in the “Model” section.

1 Like

Excellent! Thank you for the clarification