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

Problem combining GaussianRandomWalk and Weibull distribution #3584

Open
romankarlstetter opened this issue Aug 13, 2019 · 4 comments

Comments

@romankarlstetter
Copy link

commented Aug 13, 2019

Hi,

I have data that I want to model using a Weibull distribution. I want to model it such that the beta parameter changes "over time" (data is a time series). I'm trying to model that using a Gaussian random walk, see here:

with pm.Model() as model:
    sd_beta = pm.HalfCauchy('sd_beta', 100)
    mu_beta = pm.Normal('mu_beta', 0, 1)
    beta = pm.GaussianRandomWalk('beta', 
                                 mu=mu_beta,
                                 sd=sd_beta,
                                shape=len(d),
                                )
    y_obs = pm.Weibull('y_obs',
                alpha=2, #Rayleigh distribution
                beta=beta,
                observed=d)

Unfortunately, this does not really work, I get the following error

TypeError: 'float' object is not subscriptable

This is because of the following check in the Weibull distribution, I guess:

assert_negative_support(beta, 'beta', 'Weibull')

I don't really understand what's happening here. Why is that check there and what is it used for?
Is is even possible to do what I'm trying to do or is there a conceptual problem with my model?

Thanks in advance,
Roman

@aloctavodia

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

The beta parameter of the Weibull distribution has to be positive. But you are setting it to a GaussianRandomWalk that will provide values over the real line. Thus, is you may want to transform the values of the GaussianRandomWalk distribution to ensure you are getting positive values, assuming this makes sense for your model.

As this is not a bug I will close this issue and I invite you to post this question in our discourse.

@romankarlstetter

This comment has been minimized.

Copy link
Author

commented Aug 13, 2019

As this is not a bug I will close this issue and I invite you to post this question in our discourse.

Ok, thanks for the feedback, I'll bring up the topic there.

One suggestion: if easily possible (given this information is available at that point), the error message in this case might be improved to something like
"The beta parameter of the Weibull distribution ('y_obs') has to be positive, which is not guaranteed in this case."

@rpgoldman

This comment has been minimized.

Copy link
Contributor

commented Aug 13, 2019

assert_negative_support seems like a very odd name for this function, because doesn't it actually require that the support of the random variable in question must be strictly positive? Or does it require only non-negative support (i.e., is zero acceptable)? Could we rename this? It could be done without any ramifications, since it's only used in continuous.py. A docstring would be nice, too.

WRT @romankarlstetter 's request for a better error message, it looks like that's there already. Did I miss someone adding this? Or is there something wrong that causes this to be missed (see following)?

Finally, why is this only a warning, instead of an AssertionError? Something bad is going to happen here, so shouldn't we just abort at this point? Is the original question happening because there's an exception after the warning?

@rpgoldman rpgoldman reopened this Aug 13, 2019

@romankarlstetter

This comment has been minimized.

Copy link
Author

commented Aug 14, 2019

WRT @romankarlstetter 's request for a better error message, it looks like that's there already. Did I miss someone adding this? Or is there something wrong that causes this to be missed (see following)?

In assert_negative_support(), logp() of var.distribution is called, in this case an instance of GaussianRandomWalk. An there, the float parameter of assert_negative_support() is trying to be indexed like an array, which apparently does not work and throws an error before the actual error can be issued (as warning).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.