3.4 Log probability function
The basic purpose of a Stan program is to compute a log probability
function and its derivatives. The log probability function in a Stan
model outputs the log density on the unconstrained scale. A log
probability accumulator starts at zero and is then incremented in
various ways by a Stan program. The variables are first transformed
from unconstrained to constrained, and the log Jacobian determinant
added to the log probability accumulator. Then the model block is
executed on the constrained parameters, with each sampling statement
(~
) and log probability increment statement (increment_log_prob
)
adding to the accumulator. At the end of the model block execution,
the value of the log probability accumulator is the log probability
value returned by the Stan program.
Stan provides a special built-in function target()
that takes no
arguments and returns the current value of the log probability
accumulator. This function is primarily useful for debugging
purposes, where for instance, it may be used with a print statement to
display the log probability accumulator at various stages of execution
to see where it becomes ill defined.
real
target
()
Return the current value of the log probability accumulator.
Available since 2.10
target
acts like a function ending in _lp
, meaning that it may only may only
be used in the model block.