Cant get new estimates different than guide values

Hi,

I’m new to numpyro and trying to build a Bayesian Hierarchical Regression model. The issue I’m having is that what ever I use as the mean of the normal distribution in the guide is what the model returns. I’ve tried all different scales and values in the model and can’t recover what I know to be the “correct” estimate.

Here’s the code from the guide:

intercept = numpyro.sample(‘intercept’, dist.Normal(loc = numpyro.param(“loc_intercept”, 5.) , scale = numpyro.param(“scale_intercept”, 1, constraint=dist.constraints.positive)))

Here’s the code from the model:

intercept = numpyro.sample(‘intercept’, dist.Normal(10., 2.))

Any help would be greatly appreciated.

Thanks,

Hi @scottd, could you paste a little more of your example? Somewhere in your model there should be an observation statement like

numpyro.sample("obs", dist.Normal(intercept + slope @ x, scale),
               obs=y)

where slope and scale are latent variables and (x,y) are training data.

Hi,

here’s the full code

def individual_constrained_model(dat,lower_bound_constraints, upper_bound_constraints, prior_coefs, sigma_guides,interceptDat, volume_sales_obs=None):

##total intercept
intercept = numpyro.sample('intercept', dist.Normal(10., 2.))


##parameters for global store intercept distribution
unique_rcns = np.unique(dat['retailAccountNumber'])
n_rcns = len(unique_rcns)

unique_clusters = np.unique(dat['cluster'])
n_clusters = len(unique_clusters)

with numpyro.plate("plate_clusters", n_clusters):
    Beta_NetPrice_ln = numpyro.sample('Beta_NetPrice_ln', dist.Uniform(low = np.array(lower_bound_constraints['NetPrice_ln']), high = np.array(upper_bound_constraints['NetPrice_ln'])))
    
observed_sigma = numpyro.sample("observed_sigma", dist.HalfNormal(1.))

##dependent variable equation as a function of independent variables 
volume_sales_est = intercept + Beta_NetPrice_ln[np.array(dat['cluster'])] * np.array(dat['NetPrice_ln']) 

with numpyro.plate("data", len( np.array(dat['retailAccountNumber']))):
    numpyro.sample("obs", dist.Normal(volume_sales_est, observed_sigma), obs=volume_sales_obs)

def individual_constrained_guide(dat,lower_bound_constraints, upper_bound_constraints, prior_coefs,sigma_guides,interceptDat,
volume_sales_obs=None):
##total intercept
intercept = numpyro.sample(‘intercept’, dist.Normal(loc = numpyro.param(“loc_intercept”, 5.) , scale = numpyro.param(“scale_intercept”, 2, constraint=dist.constraints.positive)))

  ##parameters for global store intercept distribution
unique_rcns = np.unique(dat['retailAccountNumber'])
n_rcns = len(unique_rcns)


unique_clusters = np.unique(dat['cluster'])
n_clusters = len(unique_clusters)

##parameters for individual cluster distributions
with numpyro.plate("plate_clusters", n_clusters):
  Beta_NetPrice_ln = numpyro.sample('Beta_NetPrice_ln', 
              dist.Normal(loc = numpyro.param('loc_Beta_NetPrice_ln',np.array([-1.]*n_clusters)), 
              scale = numpyro.param('scale_Beta_NetPrice_ln' ,np.array(sigma_guides['NetPrice_ln']*2))))

thanks for the quick response