tensorflow / tensorflow/probability

Unexpected behavior from tfd.MarkovChain sample method

Open
#1,355 8 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

Can someone help to explain why the MarkovChain does not generate independent samples after using a bijector in the transition_fn? Thanks!!!

In the codes below, gaussian_walk1 and gaussian_walk2 are expected to be the same, since normal(x,1)=x+normal(0,1). While gaussian_walk1.sample(5) gives expected independent samples, gaussian_walk2.sample(5) gives identical samples.

gaussian_walk1 = tfd.MarkovChain(
 initial_state_prior=tfp.distributions.Deterministic(0.),
 transition_fn=lambda _, x: tfd.Normal(loc=x, scale=1.),
 num_steps=10)

gaussian_walk2 = tfd.MarkovChain(
 initial_state_prior=tfp.distributions.Deterministic(0.),
 transition_fn=lambda _, x: tfd.TransformedDistribution(distribution=tfd.Normal(loc=0.0, scale=1.),bijector=tfp.bijectors.Shift(x)),
 num_steps=10)
gaussian_walk1.sample(5)
<tf.Tensor: shape=(5, 10), dtype=float32, numpy=
array([[ 0.        ,  0.4963878 ,  0.0830816 , -0.77141273, -0.91577226,
         0.23975712,  0.49968088, -2.0648232 , -2.0975184 , -3.7448356 ],
       [ 0.        , -2.2646387 , -0.8099165 , -1.6681502 , -1.4593805 ,
        -1.5122384 , -1.7060741 , -1.7010493 , -0.828577  , -1.4167368 ],
       [ 0.        ,  0.06805495, -0.32092297, -1.0535722 , -2.30161   ,
        -3.9674587 , -4.319279  , -4.5414166 , -3.836207  , -4.32444   ],
       [ 0.        ,  2.509243  ,  3.1126018 ,  3.8786044 ,  5.56534   ,
         6.333398  ,  6.178385  ,  5.152129  ,  4.0463457 ,  4.3648543 ],
       [ 0.        ,  0.3113255 ,  0.9251684 ,  0.81194293,  0.48614424,
         0.05987284, -1.2350528 , -0.2448535 ,  0.2054899 ,  0.6470542 ]],
      dtype=float32)>
gaussian_walk2.sample(5)
<tf.Tensor: shape=(5, 10), dtype=float32, numpy=
array([[ 0.        , -0.655154  , -0.19072625, -0.9975474 , -0.86116153,
        -1.215732  , -1.2559065 , -1.4174258 ,  0.42590857, -0.99431324],
       [ 0.        , -0.655154  , -0.19072625, -0.9975474 , -0.86116153,
        -1.215732  , -1.2559065 , -1.4174258 ,  0.42590857, -0.99431324],
       [ 0.        , -0.655154  , -0.19072625, -0.9975474 , -0.86116153,
        -1.215732  , -1.2559065 , -1.4174258 ,  0.42590857, -0.99431324],
       [ 0.        , -0.655154  , -0.19072625, -0.9975474 , -0.86116153,
        -1.215732  , -1.2559065 , -1.4174258 ,  0.42590857, -0.99431324],
       [ 0.        , -0.655154  , -0.19072625, -0.9975474 , -0.86116153,
        -1.215732  , -1.2559065 , -1.4174258 ,  0.42590857, -0.99431324]],
      dtype=float32)>

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

No source files or tests are named. Reproduce the two snippets, then trace MarkovChain.sample together with TransformedDistribution and the Shift bijector to compare their sampling paths. Done means the cause of the identical samples is established and documented, with a focused regression test or fix if the behavior is confirmed as a defect.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.