model. It would be possible to generate just the constrained
function call. In fact, we could factor the code generation
that way, which we've also been talking about. But we need to
get rid of the derivative w.r.t. the transform as well as
> On Dec 7, 2016, at 11:28 PM, Daniel Lee <
bea...@alum.mit.edu> wrote:
>
> If you needed it, we can get that in C++ without much effort, I think. We can devise some way to get that out. grad_log_prob() wasn't designed for that purpose, so it wouldn't be appropriate to retrofit it for that functionality. It's really a matter of specifying what you want out from some input.
>
> On Dec 7, 2016, at 10:44 PM, Jiqiang Guo <
guo...@gmail.com> wrote:
>
>> No, I don't think you can get the derivative with respect to the parameter on the constrained space. adjust_transform is used only for whether the Jacobian adjustment is done or not for the log-posterior. (Ben, right?)
>>
>> Jiqiang
>>
>> On Wed, Dec 7, 2016 at 10:39 PM, Andrew Gelman <
gel...@stat.columbia.edu> wrote:
>> Thanks.
>>
>>> On Dec 7, 2016, at 10:27 PM, Ben Goodrich <
goodri...@gmail.com> wrote:
>>>
>>> On Wednesday, December 7, 2016 at 9:49:23 PM UTC-5, Andrew Gelman wrote:
>>> Suppose I have a stanfit object called "fit" and 3000 simulation draws (which I can get using extract(fit)). I want the gradient for each of these simulation draws. I'm confused trying to figure out how to do this using grad_log_prob. It seems like I have to extract the simulations, pull them out one at a time, then put them back into lists. There must be an easier way, no?
>>>
>>> No, due to the fact that the compiled Stan function can only input a vector of (unconstrained) parameters.
>>>
>>> Also it seems that grad_log_prob gives me the gradient on the unconstrained space. How to I get the gradients on the original (constrained) space?
>>>
>>> There is an adjust_transform argument that is TRUE by default which indicates that the gradient calculation should be with respect to the constrained parameters. So, all together it would be
>>>
>>> pars <- as.matrix(posterior)
>>> skel <- get_inits(posterior)[[1]]
>>> grad <- t(apply(pars, MARGIN = 1, FUN = function(theta) {
>>> grad_log_prob(posterior, upars = unconstrain_pars(posterior, relist(theta, skel)))
>>> }))
>>> colnames(grad) <- colnames(pars)
>>>
>>> Ben
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.