tensorflow / tensorflow/probability

NotImplementedError: mean is not implemented: Categorical

Open
#685 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

distributions/bijectors good first issue
Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I get the following error

NotImplementedError: mean is not implemented: Categorical

if I execute the following code

import tensorflow_probability as tfp

prob_dist = tfp.distributions.Categorical(probs=[1.0])
print(prob_dist.mean())

I get a similar error, if I attempt to call stddev(). I am using TFP 0.8.0 with TF 2.

The parameters mean and standard deviation are not usually defined for a categorical distribution and this error is due to the fact that tfp.distributions.Categorical inherits from tfp.distributions.Distribution, which defines the mean and stddev methods. PyCharm even suggests the auto-completion of these two methods for the tfp.distributions.Categorical, but this is at least misleading. Maybe tfp.distributions.Categorical should not inherit fromtfp.distributions.Distribution, which should not have those methods in the first place, because not all distributions have a well-defined mean or standard deviation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided TensorFlow Probability snippet with tfp.distributions.Categorical, then read the linked Categorical and Distribution API documentation. Determine whether the inherited mean() and stddev() behavior should be changed or documented differently; done means the categorical distribution's interface no longer misleadingly offers unsupported statistics, with corresponding behavior or documentation agreed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
api, machine-learning
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.