<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/experimental/mcmc/initialization.py#L40-L209) |

Returns an initialization Distribution for starting a Markov chain.

    tfp.experimental.mcmc.init_near_unconstrained_zero(
        model=None,
        constraining_bijector=None,
        event_shapes=None,
        event_shape_tensors=None,
        batch_shapes=None,
        batch_shape_tensors=None,
        dtypes=None,
        shard_axis_names=None
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [TFP Release Notes notebook (0.13.0)](https://www.tensorflow.org/probability/examples/TFP_Release_Notebook_0_13_0) |

This initialization scheme follows Stan: we sample every latent
independently, uniformly from -2 to 2 in its unconstrained space,
and then transform into constrained space to construct an initial
state that can be passed to `sample_chain` or other MCMC drivers.

The argument signature is arranged to let the user pass either a
`JointDistribution` describing their model, if it's in that form, or
the essential information necessary for the sampling, namely a
bijector (from unconstrained to constrained space) and the desired
shape and dtype of each sample (specified in constrained space).

> [!NOTE]
> **Note:** As currently implemented, this function has the limitation that the batch shape of the supplied model is ignored, but that could probably be generalized if needed.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `model` | A `Distribution` (typically a `JointDistribution`) giving the model to be initialized. If supplied, it is queried for its default event space bijector, its event shape, and its dtype. If not supplied, those three elements must be supplied instead. |
| `constraining_bijector` | A (typically multipart) `Bijector` giving the mapping from unconstrained to constrained space. If supplied together with a `model`, acts as an override. A nested structure of `Bijector`s is accepted, and interpreted as applying in parallel to a corresponding structure of state parts (see `JointMap` for details). |
| `event_shapes` | A structure of shapes giving the (unconstrained) event space shape of the desired samples. Must be an acceptable input to `constraining_bijector.inverse_event_shape`. If supplied together with `model`, acts as an override. |
| `event_shape_tensors` | A structure of tensors giving the (unconstrained) event space shape of the desired samples. Must be an acceptable input to `constraining_bijector.inverse_event_shape_tensor`. If supplied together with `model`, acts as an override. Required if any of `event_shapes` are not fully-defined. |
| `batch_shapes` | A structure of shapes giving the batch shape of the desired samples. If supplied together with `model`, acts as an override. If unspecified, we assume scalar batch `[]`. |
| `batch_shape_tensors` | A structure of tensors giving the batch shape of the desired samples. If supplied together with `model`, acts as an override. Required if any of `batch_shapes` are not fully-defined. |
| `dtypes` | A structure of dtypes giving the (unconstrained) dtypes of the desired samples. Must be an acceptable input to `constraining_bijector.inverse_dtype`. If supplied together with `model`, acts as an override. |
| `shard_axis_names` | A structure of `str`s indicating the named axes by which the distribution event is sharded. See [`tfp.experimental.distribute.Sharded`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/distribute/Sharded) for more context. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `init_dist` | A `Distribution` representing the initialization distribution, in constrained space. Samples from this `Distribution` are valid initial states for a Markov chain targeting the model. |

<br />

#### Example

Initialize 100 chains from the unconstrained -2, 2 distribution
for a model expressed as a `JointDistributionCoroutine`:

    @tfp.distributions.JointDistributionCoroutine
    def model():
      ...

    init_dist = tfp.experimental.mcmc.init_near_unconstrained_zero(model)
    states = tfp.mcmc.sample_chain(
      current_state=init_dist.sample(100, seed=[4, 8]),
      ...)