# Doc about distributions.transforms

**URL:** <https://discourse.pymc.io/t/doc-about-distributions-transforms/3991>\
**Category:** Questions\
**Tags:** doc\
**Created:** [October 20, 2019, 7:23pm UTC](https://discourse.pymc.io/t/doc-about-distributions-transforms/3991 "2019-10-20T19:23:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tboutelier](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/tboutelier/32/1222_2.png) [@tboutelier](https://discourse.pymc.io/u/tboutelier)\
**Post date:** [October 20, 2019, 7:23pm UTC](https://discourse.pymc.io/t/doc-about-distributions-transforms/3991/1 "2019-10-20T19:23:54Z")

</div>

Hi,

I’ve been looking for the doc about pymc3.distributions.transforms.  
There is an example in the [api\_qickstart](https://docs.pymc.io/notebooks/api_quickstart.html) page, but I could not find anything else. Is there something that I missed or does it remain to be done?

I am particularly interested by the transform that can be used to impose an ordered constraint on two variable, as x\_1\<x\_2. I looked at the source code but I recognize that I didn’t understand it!😅

Thanks a lot

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [October 20, 2019, 11:30pm UTC](https://discourse.pymc.io/t/doc-about-distributions-transforms/3991/2 "2019-10-20T23:30:58Z")

</div>

Hi Timothé!  
Usually, you can use a potential to enforce a constraint. In your case, it would go like:

```python
    import theano.tensor as tt

    means = pm.Normal("means", mu=np.array([0.9, 1]), sd=1, shape=2)
    pm.Potential("order_means", tt.switch(means[1] - means[0] < 0, -np.inf, 0))

```

When \mu\_1 \< \mu\_0, the model adds - \infty to the likelihood and will ignore the combinations of parameters that verify this condition. Otherwise, the model lives its life as usual.  
This solution with `pm.Potential` is very flexible, but the ordered constraint is so common that you can also enforce it directly with:

```python
    means = pm.Normal('means', mu=np.array([0.9, 1]), sd=1, shape=2, 
                      transform=pm.distributions.transforms.ordered)

```

These examples come from Osvaldo Martin’s very good [book and notebooks](https://github.com/aloctavodia/BAP/blob/master/code/Chp6/06_mixture_models.ipynb).  
Hope this helps and answers your question 🖖

---

<div class="post-metadata">

**Author:** ![tboutelier](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/tboutelier/32/1222_2.png) [@tboutelier](https://discourse.pymc.io/u/tboutelier)\
**Post date:** [October 21, 2019, 7:29am UTC](https://discourse.pymc.io/t/doc-about-distributions-transforms/3991/3 "2019-10-21T07:29:13Z")

</div>

Thanks for the answer and the link to Osvaldo Martin’s notebook! It helps a lot!  
And what about the documentation about `pymc3.distributions.transforms`?

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [October 21, 2019, 1:35pm UTC](https://discourse.pymc.io/t/doc-about-distributions-transforms/3991/4 "2019-10-21T13:35:24Z")

</div>

I don’t really know about that, but the ressource I gave you should get you started.  
Maybe on the website? Otherwise, I think they would welcome a PR
