tensorflow / tensorflow/probability
tfd.Empirical raises an AttributeError with quantile()
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in tensorflow_probability/python/distributions/empirical.py at _quantile() and inspect the import from tensorflow_probability.python.stats. Reproduce the failure with the provided tfd.Empirical(samples=[1,2,3]).quantile(value=[0.1, 0.5]) example; done means the call returns quantiles without the AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100