1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CAUCHY_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CAUCHY_HPP__
32 template <
bool propto,
33 typename T_y,
typename T_loc,
typename T_scale,
35 typename return_type<T_y,T_loc,T_scale>::type
36 cauchy_log(
const T_y& y,
const T_loc& mu,
const T_scale& sigma,
38 static const char*
function =
"stan::prob::cauchy_log(%1%)";
57 if (!
check_not_nan(
function, y,
"Random variable", &logp, Policy()))
70 "Random variable",
"Location parameter",
"Scale parameter",
90 for (
size_t i = 0; i <
length(sigma); i++) {
91 const double sigma_dbl =
value_of(sigma_vec[i]);
92 inv_sigma[i] = 1.0 / sigma_dbl;
93 sigma_squared[i] = sigma_dbl * sigma_dbl;
95 log_sigma[i] =
log(sigma_dbl);
101 for (
size_t n = 0; n < N; n++) {
103 const double y_dbl =
value_of(y_vec[n]);
104 const double mu_dbl =
value_of(mu_vec[n]);
107 const double y_minus_mu
109 const double y_minus_mu_squared
110 = y_minus_mu * y_minus_mu;
111 const double y_minus_mu_over_sigma
112 = y_minus_mu * inv_sigma[n];
113 const double y_minus_mu_over_sigma_squared
114 = y_minus_mu_over_sigma * y_minus_mu_over_sigma;
120 logp -= log_sigma[n];
122 logp -=
log1p(y_minus_mu_over_sigma_squared);
126 operands_and_partials.
d_x1[n] -= 2 * y_minus_mu / (sigma_squared[n] + y_minus_mu_squared);
128 operands_and_partials.
d_x2[n] += 2 * y_minus_mu / (sigma_squared[n] + y_minus_mu_squared);
130 operands_and_partials.
d_x3[n] += (y_minus_mu_squared - sigma_squared[n]) * inv_sigma[n] / (sigma_squared[n] + y_minus_mu_squared);
132 return operands_and_partials.
to_var(logp);
136 template <
bool propto,
137 typename T_y,
typename T_loc,
typename T_scale>
140 cauchy_log(
const T_y& y,
const T_loc& mu,
const T_scale& sigma) {
144 template <
typename T_y,
typename T_loc,
typename T_scale,
148 cauchy_log(
const T_y& y,
const T_loc& mu,
const T_scale& sigma,
150 return cauchy_log<false>(y,mu,sigma,Policy());
153 template <
typename T_y,
typename T_loc,
typename T_scale>
156 cauchy_log(
const T_y& y,
const T_loc& mu,
const T_scale& sigma) {
176 template <
typename T_y,
typename T_loc,
typename T_scale,
179 cauchy_cdf(
const T_y& y,
const T_loc& mu,
const T_scale& sigma,
181 static const char*
function =
"stan::prob::cauchy_cdf(%1%)";
186 using boost::math::tools::promote_args;
188 typename promote_args<T_y,T_loc,T_scale>::type lp(0.0);
189 if(!
check_not_nan(
function, y,
"Random variable", &lp, Policy()))
204 return atan2(y-mu, sigma) /
pi() + 0.5;
207 template <
typename T_y,
typename T_loc,
typename T_scale>
209 cauchy_cdf(
const T_y& y,
const T_loc& mu,
const T_scale& sigma) {