# Obtain gradient of function (e.g. multi\_student\_t\_lpdf) within Stan? Estimating approximate density functions

**URL:** <https://discourse.mc-stan.org/t/obtain-gradient-of-function-e-g-multi-student-t-lpdf-within-stan-estimating-approximate-density-functions/12759>\
**Category:** Modeling\
**Created:** [January 22, 2020, 3:10pm UTC](https://discourse.mc-stan.org/t/obtain-gradient-of-function-e-g-multi-student-t-lpdf-within-stan-estimating-approximate-density-functions/12759 "2020-01-22T15:10:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Driver](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/charles_driver/32/6524_2.png) [@Charles\_Driver](https://discourse.mc-stan.org/u/Charles_Driver)\
**Post date:** [January 22, 2020, 3:10pm UTC](https://discourse.mc-stan.org/t/obtain-gradient-of-function-e-g-multi-student-t-lpdf-within-stan-estimating-approximate-density-functions/12759/1 "2020-01-22T15:10:40Z")

</div>

I feel like this has been discussed here before but couldn’t find it. I’m interested in estimating an approximate density function from a few samples of the density and gradient around the mode. I figure leveraging the gradient information should help, though maybe this creates some kind of autodiff breaking recursion? Happy for any random pointers on the topic too, there are probably better ideas around…

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [January 23, 2020, 2:17pm UTC](https://discourse.mc-stan.org/t/obtain-gradient-of-function-e-g-multi-student-t-lpdf-within-stan-estimating-approximate-density-functions/12759/2 "2020-01-23T14:17:30Z")

</div>

Re the title, check this: [https://cran.r-project.org/web/packages/StanHeaders/vignettes/stanmath.html](https://cran.r-project.org/web/packages/StanHeaders/vignettes/stanmath.html)

Can you describe the boundary conditions a little more?

This sounds like some sorta kernel density estimation thing but maybe the solution is simpler or harder depending on what you wanna do.
