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

tfd.Empirical raises an AttributeError with quantile() #1770

Open
yusukemh opened this issue Nov 16, 2023 · 0 comments
Open

tfd.Empirical raises an AttributeError with quantile() #1770

yusukemh opened this issue Nov 16, 2023 · 0 comments

Comments

@yusukemh
Copy link

Hi,
I noticed the quantile() function of tfd.Empirical raises the following error:
AttributeError: 'function' object has no attribute 'percentile'.

import tensorflow_probability as tfp
tfd = tfp.distributions
tfd.Empirical(samples=[1,2,3]).quantile(value=[0.1, 0.5])
>>>...
File [~/.conda/envs/mpp/lib/python3.10/site-packages/tensorflow_probability/python/distributions/empirical.py:231], in Empirical._quantile(self, value, samples, **kwargs)
    228 if samples is None:
    229   samples = tf.convert_to_tensor(self._samples)
--> 231 return quantiles.percentile(
    232     x=samples, q=value * 100, axis=self._samples_axis, **kwargs)

AttributeError: 'function' object has no attribute 'percentile'

Upon looking into the problem, I figured out the following cause:
In tensorflow_probability/python/distributions/empirical.py at def _quantile(),
from tensorflow_probability.python.stats import quantiles results in the variable name quantiles referring to tensorflow_probability.python.stats.quantiles.quantiles, which is a function, resulting in the attribute error.

I manually changed the import statement to from tensorflow_probability.python.stats.quantiles import percentile
and the return at the line 231 to return percentile(...) and the error dissapeared.

Posting this here to confirm this problem is not unique to me.

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

1 participant