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.1 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.

real get_lp()
Return the current value of the log probability accumulator; deprecated; - use target() instead.

Both target and the deprecated get_lp act like other functions ending in _lp, meaning that they may only may only be used in the model block.


  1. This function used to be called get_lp(), but that name has been deprecated; using it will print a warning. The function get_lp() will be removed in a future release.