Question on change-point-section

Hi All,

This is a very basic question. In the stan program example for a change point detection model (https://mc-stan.org/docs/2_21/stan-users-guide/change-point-section.html), I notice that the lp vector is initialized to -log(T),

 log_unif = -log(T); // transformed data block

 lp = rep_vector(log_unif, T); // transformed parameters block

Can someone please explain why it is initialized to this specific value?

Srivatsa

The model assumes a uniform distribution: s \sim uniform(0,T). Hence, p(s)=\frac{1}{T}.
So log(\frac{1}{T})=log(1)-log(T)=-log(T). Et voila :-)

2 Likes

Thank you for the prompt response, @emiruz.

Since s is uniformly distributed and the sampler works on the basis of relative log density I think you can actually drop this term from the model without repercussions.

@emiruz, Thanks for the additonal info, I have a follow up question. I tried to comment out the initialization, I get the following error:

Chain 1: Rejecting initial value:
Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
Chain 1: Stan can’t start sampling from this initial value.

However even when I set the initial value to zero using “log_p = rep_vector(0,N)”, the run goes through fine. Can you please help me understand this phenomenon? How is the log(0) coming by when I do not set any initial value?

If you don’t set an initial value it’s implicitly set to NaN (“not a number”). The error message is a bit misleading, it just means the sample is rejected but in this case the log probability is actually NaN.

1 Like

@nhuurre Thanks for the clarification, I understand what’s happening now.