# Request for final feedback: User controlled unnormalized (propto) distribution syntax

**URL:** <https://discourse.mc-stan.org/t/request-for-final-feedback-user-controlled-unnormalized-propto-distribution-syntax/16029>\
**Category:** General\
**Created:** [June 18, 2020, 9:49am UTC](https://discourse.mc-stan.org/t/request-for-final-feedback-user-controlled-unnormalized-propto-distribution-syntax/16029 "2020-06-18T09:49:48Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![betanalpha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/betanalpha/32/4_2.png) [@betanalpha](https://discourse.mc-stan.org/u/betanalpha)\
**Post date:** [June 20, 2020, 7:03pm UTC](https://discourse.mc-stan.org/t/request-for-final-feedback-user-controlled-unnormalized-propto-distribution-syntax/16029/12 "2020-06-20T19:03:28Z")

</div>

> [@rok\_cesnovar](#):
>
> > [@](#):
> >
> > transformed parameters block is executed twice. First when the sampler calls the model’s `log_prob()` and there indeed `x` is autodiffable and `ll` has value equal to `target` . But `log_prob` _returns only one value_ , the `target` . Transformed parameters are not saved!
> > 
> > > The second time happens when the sampler has chosen which sample to save and calls `write_array()` . The method reconstructs the transformed parameters by running the code again _but this time everything is double_ . These are the values that get saved in the output.
> 
> That does seem weird, but I also don’t have enough background here.

This is due to how the sampler works.

Each iteration of Hamiltonian Monte Carlo requires many evaluations of the target log density and its gradient, which each require evaluating the transformed parameters block. These evaluations, however, are not saved anywhere but the C++ in order to avoid unnecessary memory overhead.

It’s only after a new iteration has been birthed that the constrained parameters, transformed parameters, and generated quantities are evaluated and passed to writer callbacks from which the interfaces can access the values. Because the output of the transformed parameters is not saved along with each state it has to be run again, but because it is not being used for Hamiltonian Monte Carlo it doesn’t need to be run with vars.

---

_[View the full topic](https://discourse.mc-stan.org/t/request-for-final-feedback-user-controlled-unnormalized-propto-distribution-syntax/16029)._
