probability icon indicating copy to clipboard operation
probability copied to clipboard

tfd.Empirical raises an AttributeError with quantile()

Open yusukemh opened this issue 2 years ago • 0 comments

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.

yusukemh avatar Nov 16 '23 20:11 yusukemh