Weibull Regression with Covariates Sampling Error


This is the first time I am trying out a Bayesian model, so please bear with me.

I am trying to perform Weibull Regression with some covariates.

I have Standardised the dataset and I am trying out the following model:

n_dim = training_data_norm.shape[1]
X_ = shared(training_data_norm)
with pm.Model() as model:

    # Priors for unknown model parameters
    k = pm.Gamma('k', alpha=10, beta=100)
    beta = pm.Normal('beta', mu=0, sd=0.001, shape=n_dim)
    #η = beta.dot(X_.T)
    # Expected value of lambda parameter
    lambda_obs = pm.Deterministic('beta_', \
         tt.nnet.relu(beta.dot(X_.T), alpha=0.001))

    # Likelihood (sampling distribution) of observations
    runningtime_obs = pm.Weibull('runningtime_obs', alpha=k, \
         beta=lambda_obs, observed=y_train) 

While sampling, using the following code:

with model:
    start = find_MAP()
    trace = pm.sample(500, start=start)

I am getting the following error:

Bad initial energy, check any log probabilities that are inf or -inf, nan or very small:
runningtime_obs   -inf
SamplingError: Bad initial energy

Could anyone help me out in figuring the source of error.

Thanks for your question. Bad initial energy error can have several causes. We have an FAQ about this that should help you.
PyMCheers :vulcan_salute:

Thanks for your reply.

Sorry, I should have checked FAQ first.

I suspected the ‘tt.nnet.relu’ was resulting in -inf.

Changed it to tt.log( 1+ exp(beta.dot(X_T)). It was working fine.

I have another question regarding the range of the target variable. The current max value is very high.

Standardising it results in some negative values, which are not acceptable for Weibull distribution. Any recommendations on that?


Glad the FAQ could help :slight_smile:
I’m not familiar with the Weibull distribution, but there are a lot of ways to rescale your data besides the classical standardization. For instance, I think you could rescale your data on an interval, like [0, 1], and that way the sampler won’t have a hard time with the huge scale of the data.

Thanks @AlexAndorra for your prompt replies.

Sure, I will try out rescaling and see if I get any better results.

1 Like