Stan  1.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
exponential.hpp
Go to the documentation of this file.
1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__EXPONENTIAL_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__EXPONENTIAL_HPP__
3 
4 #include <stan/agrad.hpp>
7 #include <stan/meta/traits.hpp>
9 #include <stan/prob/traits.hpp>
10 
11 namespace stan {
12 
13  namespace prob {
14 
41  template <bool propto,
42  typename T_y, typename T_inv_scale,
43  class Policy>
44  typename return_type<T_y,T_inv_scale>::type
45  exponential_log(const T_y& y, const T_inv_scale& beta,
46  const Policy&) {
47  static const char* function = "stan::prob::exponential_log(%1%)";
48 
49  // check if any vectors are zero length
50  if (!(stan::length(y)
51  && stan::length(beta)))
52  return 0.0;
53 
58 
59  typename return_type<T_y,T_inv_scale>::type logp(0.0);
60  if(!check_not_nan(function, y, "Random variable", &logp, Policy()))
61  return logp;
62  if(!check_finite(function, beta, "Inverse scale parameter", &logp, Policy()))
63  return logp;
64  if(!check_positive(function, beta, "Inverse scale parameter", &logp, Policy()))
65  return logp;
66 
67  if (!(check_consistent_sizes(function,
68  y,beta,
69  "Random variable","Inverse scale parameter",
70  &logp, Policy())))
71  return logp;
72 
73 
74  // set up template expressions wrapping scalars into vector views
75  VectorView<const T_y> y_vec(y);
76  VectorView<const T_inv_scale> beta_vec(beta);
77  size_t N = max_size(y, beta);
78 
79  for (size_t n = 0; n < N; n++) {
81  logp += log(beta_vec[n]);
83  logp -= beta_vec[n] * y_vec[n];
84  }
85  return logp;
86  }
87 
88  template <bool propto,
89  typename T_y, typename T_inv_scale>
90  inline
92  exponential_log(const T_y& y, const T_inv_scale& beta) {
93  return exponential_log<propto>(y,beta,stan::math::default_policy());
94  }
95 
96  template <typename T_y, typename T_inv_scale,
97  class Policy>
98  inline
100  exponential_log(const T_y& y, const T_inv_scale& beta, const Policy&) {
101  return exponential_log<false>(y,beta,Policy());
102  }
103 
104  template <typename T_y, typename T_inv_scale>
105  inline
107  exponential_log(const T_y& y, const T_inv_scale& beta) {
108  return exponential_log<false>(y,beta,stan::math::default_policy());
109  }
110 
111 
112 
126  template <typename T_y,
127  typename T_inv_scale,
128  class Policy>
129  typename boost::math::tools::promote_args<T_y,T_inv_scale>::type
130  exponential_cdf(const T_y& y,
131  const T_inv_scale& beta,
132  const Policy&) {
133 
134  static const char* function = "stan::prob::exponential_cdf(%1%)";
135 
139  using boost::math::tools::promote_args;
140 
141  typename promote_args<T_y,T_inv_scale>::type lp;
142  if(!check_not_nan(function, y, "Random variable", &lp, Policy()))
143  return lp;
144  if(!check_finite(function, beta, "Inverse scale parameter", &lp, Policy()))
145  return lp;
146  if(!check_positive(function, beta, "Inverse scale parameter", &lp, Policy()))
147  return lp;
148 
149  if (y < 0)
150  return 1.0;
151 
152  return 1.0 - exp(-beta * y);
153  }
154 
155  template <typename T_y,
156  typename T_inv_scale>
157  inline
158  typename boost::math::tools::promote_args<T_y,T_inv_scale>::type
159  exponential_cdf(const T_y& y,
160  const T_inv_scale& beta) {
162  }
163 
164 
165 
166  }
167 }
168 
169 #endif

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