Stan Math Library  2.20.0
reverse mode automatic differentiation
std_normal_lpdf.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_STD_NORMAL_LPDF_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_STD_NORMAL_LPDF_HPP
3 
9 
10 namespace stan {
11 namespace math {
12 
25 template <bool propto, typename T_y>
26 typename return_type<T_y>::type std_normal_lpdf(const T_y& y) {
27  static const char* function = "std_normal_lpdf";
28  typedef typename stan::partials_return_type<T_y>::type T_partials_return;
29 
30  if (size_zero(y))
31  return 0.0;
32 
33  check_not_nan(function, "Random variable", y);
34 
36  return 0.0;
37 
38  operands_and_partials<T_y> ops_partials(y);
39  scalar_seq_view<T_y> y_vec(y);
40  T_partials_return logp(0.0);
41  for (size_t n = 0; n < length(y); n++) {
42  const T_partials_return y_val = value_of(y_vec[n]);
43  logp += y_val * y_val;
45  ops_partials.edge1_.partials_[n] -= y_val;
46  }
47  logp *= -0.5;
49  logp += NEG_LOG_SQRT_TWO_PI * length(y);
50  return ops_partials.build(logp);
51 }
52 
53 template <typename T_y>
54 inline typename return_type<T_y>::type std_normal_lpdf(const T_y& y) {
55  return std_normal_lpdf<false>(y);
56 }
57 
58 } // namespace math
59 } // namespace stan
60 #endif
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.
Definition: value_of.hpp:17
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
Definition: conjunction.hpp:14
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.
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Definition: length.hpp:16
bool size_zero(T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
Definition: size_zero.hpp:18
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
Definition: return_type.hpp:36
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
return_type< T_y >::type std_normal_lpdf(const T_y &y)
The log of the normal density for the specified scalar(s) given a location of 0 and a scale of 1...
T_return_type build(double value)
Build the node to be stored on the autodiff graph.
const double NEG_LOG_SQRT_TWO_PI
Definition: constants.hpp:156
internal::ops_partials_edge< double, Op1 > edge1_

     [ Stan Home Page ] © 2011–2018, Stan Development Team.