Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
normal.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__PROB__UNIVARIATE__CONTINUOUS__NORMAL_HPP
2 #define STAN__AGRAD__FWD__PROB__UNIVARIATE__CONTINUOUS__NORMAL_HPP
3 
4 #include <boost/random/normal_distribution.hpp>
5 #include <boost/random/variate_generator.hpp>
6 #include <boost/utility/enable_if.hpp>
8 #include <stan/math.hpp>
10 #include <stan/meta/traits.hpp>
11 #include <stan/prob/constants.hpp>
12 #include <stan/prob/traits.hpp>
13 
14 namespace stan {
15 
16  namespace prob {
17 
18  template <bool propto,
19  typename T_y, typename T_loc, typename T_scale>
20  typename boost::enable_if_c<contains_fvar<T_y,T_loc,T_scale>::value,
22  normal_log(const T_y& y, const T_loc& mu, const T_scale& sigma) {
23  // static const char* function = "stan::prob::normal_log(%1%)";
24  // FIXME: add input checks
25 
26  using std::log;
30 
31  // check if no variables are involved and prop-to
33  return 0.0;
34 
35  typename return_type<T_y,T_loc,T_scale>::type logp(0);
36 
37  // log probability
39  logp += NEG_LOG_SQRT_TWO_PI;
40 
42  logp -= log(sigma);
43 
45  typename return_type<T_y,T_loc,T_scale>::type z = (y - mu) / sigma;
46  logp -= 0.5 * z * z;
47  }
48 
49  return logp;
50  }
51 
52  }
53 
54 }
55 
56 #endif
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type
Definition: traits.hpp:406
Metaprogram to determine if a type has a base scalar type that can be assigned to type double...
Definition: traits.hpp:57
double value_of(const T x)
Return the value of the specified scalar argument converted to a double value.
Definition: value_of.hpp:24
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Definition: traits.hpp:35
boost::enable_if_c< contains_fvar< T_y, T_loc, T_scale >::value, typename return_type< T_y, T_loc, T_scale >::type >::type normal_log(const T_y &y, const T_loc &mu, const T_scale &sigma)
Definition: normal.hpp:22
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15

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