Stan Math Library: stan/math/prim/scal/prob/neg_binomial_2_ccdf_log.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

neg_binomial_2_ccdf_log.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CCDF_LOG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CCDF_LOG_HPP
3
4 #include <stan/math/prim/scal/err/check_consistent_sizes.hpp>
5 #include <stan/math/prim/scal/err/check_not_nan.hpp>
6 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
7 #include <stan/math/prim/scal/fun/grad_reg_inc_beta.hpp>
8 #include <stan/math/prim/scal/meta/length.hpp>
9 #include <stan/math/prim/scal/prob/neg_binomial_ccdf_log.hpp>
10
11 namespace stan {
12 namespace math {
13
14 // Temporary neg_binomial_2_ccdf implementation that
15 // transforms the input parameters and calls neg_binomial_ccdf
16 template <typename T_n, typename T_location, typename T_precision>
17 typename return_type<T_location, T_precision>::type
18 neg_binomial_2_ccdf_log(const T_n& n,
19 const T_location& mu,
20 const T_precision& phi) {
21 using stan::math::check_positive_finite;
22 using stan::math::check_not_nan;
23 using stan::math::check_consistent_sizes;
24
25 // check if any vectors are zero length
26 if (!(stan::length(n)
27 && stan::length(mu)
28 && stan::length(phi)))
29 return 0.0;
30
31 static const char* function("stan::math::neg_binomial_2_cdf");
32 check_positive_finite(function, "Location parameter", mu);
33 check_positive_finite(function, "Precision parameter", phi);
34 check_not_nan(function, "Random variable", n);
35 check_consistent_sizes(function,
36 "Random variable", n,
37 "Location parameter", mu,
38 "Precision Parameter", phi);
39
40 VectorView<const T_location> mu_vec(mu);
41 VectorView<const T_precision> phi_vec(phi);
42
43 size_t size_beta = max_size(mu, phi);
44
45 VectorBuilder<true, typename return_type<T_location, T_precision>::type,
46 T_location, T_precision> beta_vec(size_beta);
47 for (size_t i = 0; i < size_beta; ++i)
48 beta_vec[i] = phi_vec[i] / mu_vec[i];
49
50 return neg_binomial_ccdf_log(n, phi, beta_vec.data());
51 }
52 }
53 }
54 #endif
check_not_nan.hpp
stan::math::check_not_nan
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
Definition: check_not_nan.hpp:63
check_positive_finite.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::neg_binomial_2_ccdf_log
return_type< T_location, T_precision >::type neg_binomial_2_ccdf_log(const T_n &n, const T_location &mu, const T_precision &phi)
Definition: neg_binomial_2_ccdf_log.hpp:18
stan::length
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
neg_binomial_ccdf_log.hpp
stan::math::neg_binomial_ccdf_log
return_type< T_shape, T_inv_scale >::type neg_binomial_ccdf_log(const T_n &n, const T_shape &alpha, const T_inv_scale &beta)
Definition: neg_binomial_ccdf_log.hpp:34
stan::max_size
size_t max_size(const T1 &x1, const T2 &x2)
Definition: max_size.hpp:9
length.hpp
grad_reg_inc_beta.hpp
stan::VectorBuilder
VectorBuilder allocates type T1 values to be used as intermediate values.
Definition: VectorBuilder.hpp:28
stan::math::check_consistent_sizes
bool check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Return true if the dimension of x1 is consistent with x2.
Definition: check_consistent_sizes.hpp:31
stan::VectorBuilder::data
VectorBuilderHelper< T1, used, contains_vector< T2, T3, T4, T5, T6, T7 >::value >::type data()
Definition: VectorBuilder.hpp:42
stan::VectorView
VectorView is a template expression that is constructed with a container or scalar, which it then allows to be used as an array using operator[].
Definition: VectorView.hpp:48
check_consistent_sizes.hpp
stan::math::check_positive_finite
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.
Definition: check_positive_finite.hpp:28

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