# ContinousTransformations.jl help

**URL:** <https://discourse.julialang.org/t/continoustransformations-jl-help/10062>\
**Category:** General Usage\
**Created:** [March 30, 2018, 1:21am UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062 "2018-03-30T01:21:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 30, 2018, 1:21am UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/1 "2018-03-30T01:21:19Z")

</div>

So I am trying out the awesome `DynamicHMC.jl` package and as such need to wrap my head around using `ContinousTransformations.jl` to make sure my priors are handled correctly.

My current issue is how to combine transformations conveniently. What I want:

For my `P = 10` element long vector of \beta’s the first must be positive, but the rest are unbounded. And the last parameter is a variance so much be positive as well.

Currently I can’t figure out how to do this. I have:  
`θ_transform = TransformationTuple(ArrayTransformation(bridge(ℝ, ℝ), P), bridge(ℝ, ℝ⁺))`

Which is okay, but doesn’t give the first list transform to be non-negative. If I try to splice in one more like the last, it makes parsing the arguments tricky … Any tips?

The full code this is embeded in is at: [https://github.com/gabrielgellner/LearnHMC/blob/master/src/test.jl](https://github.com/gabrielgellner/LearnHMC/blob/master/src/test.jl)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 30, 2018, 6:35am UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/2 "2018-03-30T06:35:57Z")

</div>

If I get the example correctly, you need something like

```julia
using ContinuousTransformations
θ_transform = TransformationTuple(bridge(ℝ, ℝ⁺) # β₁
                                  ArrayTransformation(IDENTITY, 9), # β rest
                                  bridge(ℝ, ℝ⁺), # σ
                                  bridge(ℝ, ℝ⁺)) # ν
function (prob::EcoRegProblem)(θ)
    β₁, βrest, σ, ν = θ
    β = vcat(β₁, βrest)
    ...
end

```

There is no API for combining already transformed elements, as that can be done easily in user code like above.

An API rewrite is due once `v0.7` comes out, as named tuples will make everything super convenient. If you want other features, suggestions are welcome (as issues, preferably).

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 30, 2018, 3:44pm UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/3 "2018-03-30T15:44:23Z")

</div>

Thank you so much. Now I just need to figure out why the sampler is doing so badly! Really like the packages and will file issues as I find them. With the named tuples will it be easier to make combined versions like the above? Though the vcat-ing is easy, it is a bit annoying to have to always do it 🙂

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 30, 2018, 4:20pm UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/4 "2018-03-30T16:20:23Z")

</div>

`NamedTuple`s will just make it easier to extract variables from transformations from \mathbb{R}^n that return a tuple of values, as the user won’t have to remember positions.

Concatenation functionality is not planned, as it is just available in `Base`. ContinuousTransformations.jl helps you with transformations and derivatives, which are not relevant for `vcat`. I should probably add an example though.

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 30, 2018, 4:32pm UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/5 "2018-03-30T16:32:19Z")

</div>

I could clean up one of the linear regression examples I have messed with and do a PR for the examples repo if that is of use / interest.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 30, 2018, 4:53pm UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/6 "2018-03-30T16:53:10Z")

</div>

Can you explain why \beta\_1 \> 0? My concern would be having mass near 0 and transformations not handling that well (actually they don’t allow 0, \mathbb{R} is mapped to open intervals).

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 30, 2018, 5:02pm UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/7 "2018-03-30T17:02:37Z")

</div>

I was just quickly trying to port over this tutorial: [Jupyter Notebook Viewer](http://nbviewer.jupyter.org/github/QuantEcon/QuantEcon.notebooks/blob/master/IntroToStan_basics_workflow.ipynb)

Though I imagine the issues are simply that I didn’t do the correct representation of the model. I can actually see that the “incorrect” model that I am using, actually doesn’t constrain the \beta\_1 so I will fix that up, but will need it for when I do the “correct” model.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 30, 2018, 5:07pm UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/8 "2018-03-30T17:07:38Z")

</div>

I would recommend something from the Bayesian Data Analysis book by Gelman et al, or the Gelman & Hill book. Both are listed in the package docs. Or some model from the Stan examples.

That said, the setup I recommended seems to be an analogue of the Stan solution you linked.

---

<div class="post-metadata">

**Author:** ![gabrielgellner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielgellner/32/75_2.png) [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Post date:** [March 30, 2018, 5:09pm UTC](https://discourse.julialang.org/t/continoustransformations-jl-help/10062/9 "2018-03-30T17:09:09Z")

</div>

Yeah the way you solve it, versus the Stan modelling language is very close, which is nice. This tutorial is linked from the Stan webpage, and it is nice to try and get slightly more complex models working. I have some simple ones running along nicely, but will want to get something uglier like this working to see if I can use this for my true model which is a beast 🙂
