Target

bokeh lights

Is there any way to achieve the effect of target*=real a?
This will be useful in simulated tempering and some general post-processing, where we want to reshape the posterior by some power transformation.

Would this work

target += target() * a - target()

edit. typo in the docs target()() –> target()

Thanks. But target()() does not seem to be recognized.

I think that is a typo in the docs and its just target().

Great, thanks! This is exactly what I want.

OK it turns out I have not fully solved my problem. I am now using a geometric bridge between two models: For two densities p_1(theta) and p_2(theta), I want to sample from a density that is proportional to p_1^lambda(theta) p_2^{(1-lambda)}(theta). Using the saved target(), I can do this by:

parameters{
real lambda;
real theta;
}

model {
real log_q;//lp of the first model;
theta~foo; // model 1
log_q=target();
target+=-target();
real log_p;//lp of the alternative model
theta~foo2; // model 2
log_p=target();
 target+=target()*(lambda)-target() + (1-lambda)*log_q;
lambda~foo3
}

The sampling is fine. But for some post process, I want to access my local variable log_q and log_p defined in the model block. For one time use, I could put them into transformed parameters, to compute and store log_p=foo1_lpdf(theta).

But I want an automated procedure that applied to a general model where the density is hard to compute in the transformed parameters.

In other words, in most cases, local variables in model block can be easily moved back to transformed parameters, expect when these variables depends on target().

In this structure, (before hacking into stan language), is there any easy way I can rewrite my code to

  1. save local variable in model block ; or
  2. compute transformed parameters in model block; or
  3. save intermediate states of target()?

which are three equivalent description my question.

Thanks.

Latest posts