1 #ifndef STAN_MATH_PRIM_SCAL_PROB_NORMAL_SUFFICIENT_LPDF_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_NORMAL_SUFFICIENT_LPDF_HPP 44 template <
bool propto,
typename T_y,
typename T_s,
typename T_n,
typename T_loc,
47 const T_y& y_bar,
const T_s& s_squared,
const T_n& n_obs,
const T_loc& mu,
48 const T_scale& sigma) {
49 static const char*
function =
"normal_sufficient_lpdf";
57 if (
size_zero(y_bar, s_squared, n_obs, mu, sigma))
61 T_partials_return logp(0.0);
64 check_finite(
function,
"Location parameter sufficient statistic", y_bar);
65 check_finite(
function,
"Scale parameter sufficient statistic", s_squared);
74 y_bar,
"Scale parameter sufficient statistic",
75 s_squared,
"Number of observations", n_obs,
76 "Location parameter", mu,
"Scale parameter", sigma);
90 size_t N =
max_size(y_bar, s_squared, n_obs, mu, sigma);
92 for (
size_t i = 0; i < N; i++) {
93 const T_partials_return y_bar_dbl =
value_of(y_bar_vec[i]);
94 const T_partials_return s_squared_dbl =
value_of(s_squared_vec[i]);
95 const T_partials_return n_obs_dbl = n_obs_vec[i];
96 const T_partials_return mu_dbl =
value_of(mu_vec[i]);
97 const T_partials_return sigma_dbl =
value_of(sigma_vec[i]);
98 const T_partials_return sigma_squared =
pow(sigma_dbl, 2);
104 logp -= n_obs_dbl *
log(sigma_dbl);
106 const T_partials_return cons_expr
107 = (s_squared_dbl + n_obs_dbl *
pow(y_bar_dbl - mu_dbl, 2));
109 logp -= cons_expr / (2 * sigma_squared);
113 const T_partials_return common_derivative
114 = n_obs_dbl * (mu_dbl - y_bar_dbl) / sigma_squared;
116 ops_partials.
edge1_.partials_[i] += common_derivative;
118 ops_partials.
edge3_.partials_[i] -= common_derivative;
121 ops_partials.
edge2_.partials_[i] -= 0.5 / sigma_squared;
123 ops_partials.
edge4_.partials_[i]
124 += cons_expr /
pow(sigma_dbl, 3) - n_obs_dbl / sigma_dbl;
126 return ops_partials.
build(logp);
129 template <
typename T_y,
typename T_s,
typename T_n,
typename T_loc,
133 const T_loc& mu,
const T_scale& sigma) {
134 return normal_sufficient_lpdf<false>(y_bar, s_squared, n_obs, mu, sigma);
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
boost::math::tools::promote_args< double, typename partials_type< typename scalar_type< T >::type >::type, typename partials_return_type< T_pack... >::type >::type type
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
fvar< T > log(const fvar< T > &x)
internal::ops_partials_edge< double, Op4 > edge4_
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
This template builds partial derivatives with respect to a set of operands.
bool size_zero(T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
return_type< T_y, T_s, T_loc, T_scale >::type normal_sufficient_lpdf(const T_y &y_bar, const T_s &s_squared, const T_n &n_obs, const T_loc &mu, const T_scale &sigma)
The log of the normal density for the specified scalar(s) given the specified mean(s) and deviation(s...
size_t max_size(const T1 &x1, const T2 &x2)
T_return_type build(double value)
Build the node to be stored on the autodiff graph.
const double NEG_LOG_SQRT_TWO_PI
internal::ops_partials_edge< double, Op2 > edge2_
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Check if the dimension of x1 is consistent with x2.
internal::ops_partials_edge< double, Op3 > edge3_
internal::ops_partials_edge< double, Op1 > edge1_