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

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

Comments

@romankarlstetter
Copy link

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:

https://github.com/pymc-devs/pymc3/blob/37466665efec5907c918f59a68edb6b11bea2b9e/pymc3/distributions/continuous.py#L2866

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
Copy link
Member

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
Copy link
Author

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
Copy link
Contributor

rpgoldman 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
Copy link
Author

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).

@fonnesbeck fonnesbeck closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2022
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

4 participants