Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theano datatype issue in model6.9 week04 #4

Open
Rabeez opened this issue Dec 1, 2020 · 1 comment
Open

Theano datatype issue in model6.9 week04 #4

Rabeez opened this issue Dec 1, 2020 · 1 comment

Comments

@Rabeez
Copy link

Rabeez commented Dec 1, 2020

I was getting a TypeError on this line even though you had casted the column to an Int64 already.

" #married = pm.Data('married', d['married'].values)\n",

For some reason casting to Int64 does not make a numpy typed series and causes Theano to freak out. Just changing this cast to astype('int') here solves the issue.

"d['married'] = d['married'].astype('Int64')"

I'll submit a PR later unless you get to this first 😄

@rlindholm
Copy link

rlindholm commented Dec 12, 2020

I'm still experiencing trouble after that change @Rabeez the error message changed though:

ValueError: Cannot broadcast provided shapes (0,), (), () given size: ()

Code from the previous cell with the change as recommended above


d = d.loc[d.age > 17,]
d['age'] = ( d['age'] - 18 ) / ( 65 - 18 )
d['married'] = d['married'].astype('int')

Model 6.9 cell code:


#married = theano.shared(d.married)

with pm.Model() as model_69:
    # Data
    age = pm.Data('age', d['age'].values)
    married = pm.Data('married', d['married'].values)
    happiness = pm.Data('happiness', d['happiness'].values)
    
    # Priors
    a = pm.Normal('a', mu=0, sd=1, shape=2)
    bA = pm.Normal('bA', mu=0, sd=2)
    sigma = pm.Exponential('sigma', lam=1)
    
    # Regression
    mu = a[married] + bA * age
    happy_hat = pm.Normal('happy_hat', mu=mu, sd=sigma, observed=happiness)
    
    # Prior sampling, trace definition and posterior sampling
    prior = pm.sample_prior_predictive(samples = 30)
    posterior_69 = pm.sample()
    posterior_pred_69 = pm.sample_posterior_predictive(posterior_69)

Running pymc3 3.10, tried reverting back to 3.7 for the purposes of working my way through this textbook, but I was running into tons of issues with theano. Any advice?

EDIT:
It appears that this may be a result of an interaction with age though as the very first line of the stack mentions this:
WARNING (theano.tensor.opt): Cannot construct a scalar test value from a test value with no size: age

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants