tensorflow / tensorflow/probability

Why are two apparently equal distributions not equal?

Open
#717 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Consider the following program

import tensorflow_probability as tfp

d = tfp.distributions.Normal(loc=[0], scale=[1])
d2 = tfp.distributions.Normal(loc=[0, 1], scale=[[0, 4],
                                                 [1, 3]])

assert d2[1, 0].loc == d.loc and d2[1, 0].scale == d.scale
print("d2[1, 0] == d?", d2[1, 0] == d)

which outputs

d2[1, 0] == d? False

Why this behavior? I haven't looked at the implementation, but I suppose you haven't overridden __eq__ and similar methods of the Normal class. If that's the case, you may want to do that, or is there any particular reason why you haven't done it?

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

Start by running the Python example with tensorflow_probability.distributions.Normal and inspect how Normal instances compare. Determine whether distributions with equivalent loc and scale should compare equal, and define the expected equality behavior before making a change; the issue is done when the behavior is documented and covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.