tensorflow / tensorflow/probability
Why do you allow the creation of a normal distribution with nan as the mean when validate_args=True?
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
If you execute the following code
from tensorflow_probability import distributions as tfd
tfd.Normal(loc=0, scale=float("nan"), validate_args=True)
we get the following error
tensorflow.python.framework.errors_impl.InvalidArgumentError: Expected 'tf.Tensor(False, shape=(), dtype=bool)' to be true. Summarized data: b'Argument
scalemust be positive.'
b'Condition x > 0 did not hold element-wise:'
b'x (shape=() dtype=float32) = 'nan
Maybe this error message could be improved, given that NaN is not greater, smaller or equal to zero (in Python).
float("nan") > 0
False
float("nan") < 0
False
float("nan") == 0
False
Furthermore, the following program does not produce any error
from tensorflow_probability import distributions as tfd
tfd.Normal(loc=float("nan"), scale=1, validate_args=True)
which means that we can create a normal distribution with NaN as the mean, but this should probably not be allowed (especially when validate_args=True, which is the case), or is there any reason why this was done?
Maybe these issues also occur with other distributions. I haven't checked it.
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 by reproducing the two tfd.Normal examples with validate_args=True and compare the validation behavior for loc and scale. Then inspect Normal's argument-validation entry point and related distribution validations to determine the intended NaN handling. Done means the behavior and error reporting are consistent with the agreed validation policy, with regression coverage for the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100