Skip to content

No free random variables to sample.Β #2

@bwanaaa

Description

@bwanaaa

I'm new to pymc3 and trying to learn how to use it.
I was following allowing with your video here:
https://www.youtube.com/watch?v=rZvro4-nFIk

downloaded your github, and started stepping through the code.
Imports and setup section went fine (I have all the requirements)
Here is the Linear regression output:

print('Running on PyMC3 v{}'.format(pm.__version__))# Set up basic parameters
num_features = 10
num_observed = 1000

--> Running on PyMC3 v3.7

# Choose random values for the actual alpha and betas
alpha_a = random.normal(size=1)

betas_a = random.normal(size = num_features)

# Create fake predictor data
X_train = random.normal(size=(num_observed, num_features))

# Calculate the actual data, but put a bit of noise in
y_a = alpha_a + nsum(betas_a[None,:] * X_train, 1) + random.normal(size=(num_observed))

# Set up the PyMC model
lin_reg_model = pm.Model()
with lin_reg_model:
    
    #Note: You can parametrize your functions by either tau or sigma 
    #where tau = 1/sigma^2
    # This is a change from PyMC2
    alpha = pm.Normal('alpha', mu=0, tau=10.**-2, shape=(1))
    betas = pm.Normal('betas', mu=0, tau=10. ** -2, shape=(1, num_features))
    
    # Simulate the noise
    s = pm.HalfNormal('s', tau=1)
    
    temp = alpha + T.dot(betas, X_train.T)

    y = pm.Normal('y', mu=temp , tau=s ** -2, observed=y_a)

I had no errors in any of the jupyter cells so far. But the next cell was:

lin_reg_model = pm.Model()# Sample from the model
with lin_reg_model:
    step = pm.NUTS()
    nuts_trace = pm.sample(2e3, step)

and it said this:


ValueError                                Traceback (most recent call last)
<ipython-input-13-da803d520ecc> in <module>
      1 lin_reg_model = pm.Model()# Sample from the model
      2 with lin_reg_model:
----> 3     step = pm.NUTS()
      4     nuts_trace = pm.sample(2e3, step)

~/miniconda3/envs/p37cu10pyToTf/lib/python3.7/site-packages/pymc3/step_methods/arraystep.py in __new__(cls, *args, **kwargs)
     53 
     54         if len(vars) == 0:
---> 55             raise ValueError('No free random variables to sample.')
     56 
     57         if not blocked and len(vars) > 1:

ValueError: No free random variables to sample.



help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions