# Complex normal distribution

**URL:** <https://discourse.mc-stan.org/t/complex-normal-distribution/8001>\
**Category:** Modeling\
**Created:** [March 10, 2019, 6:59pm UTC](https://discourse.mc-stan.org/t/complex-normal-distribution/8001 "2019-03-10T18:59:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chloe](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Chloe](https://discourse.mc-stan.org/u/Chloe)\
**Post date:** [March 10, 2019, 6:59pm UTC](https://discourse.mc-stan.org/t/complex-normal-distribution/8001/1 "2019-03-10T18:59:58Z")

</div>

Dear All, Please help! I am new to Stan and I am hoping that it will be possible for me to use Stan for modelling complex pairs of eigenvalues. I am a first year PhD student with limited knowledge of Statistics and I am hoping that it is possible to specify complex numbers in Stan. Please could you tell me if I could do this? I have an algorithm that is written in MATLAB using a Gibbs sampler which samples from the complex normal distribution. Please could you tell me if there is any hope of being able to translate this into Stan?

Thank you, Chloe

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [March 10, 2019, 7:33pm UTC](https://discourse.mc-stan.org/t/complex-normal-distribution/8001/2 "2019-03-10T19:33:01Z")

</div>

Not much. The Stan language does not support complex numbers, so the best you could possibly do is have separate vectors for the real and imaginary parts of the complex eigenvalues. But the Stan Math library does not support autodifferentiation of complex eigenvalues. There are (or were) two branches to implement autodifferentiation of complex numbers, one of which works in forward and reverse mode and the other works in reverse mode only and neither are getting merged. So pretty much the only option at this point is to write C++ functions that take matrices (of unknowns), coerce them to `double`, handle the complex eigenvalues, calculate the log-kernel, and attach the gradient with respect to the unknowns analytically using the `precomputed_gradients` function in Stan Math.
