/** * The normalized incomplete beta function of a, b, and x. * * Used to compute the cumulative density function for the beta * distribution. * * @param a Shape parameter a <= 0; a and b can't both be 0 * @param b Shape parameter b <= 0 * @param x Random variate. 0 <= x <= 1 * @throws if constraints are violated or if any argument is NaN * * @return The normalized incomplete beta function. */ inline double ibeta(double a, double b, double x) { check_not_nan("ibeta", "a", a); check_not_nan("ibeta", "b", b); check_not_nan("ibeta", "x", x); return boost::math::ibeta(a, b, x); }
inline void check_pos_definite(const char* function, const char* name, const Eigen::Matrix<T_y, -1, -1>& y) { check_symmetric(function, name, y); check_positive_size(function, name, "rows", y.rows()); if (y.rows() == 1 && !(y(0, 0) > CONSTRAINT_TOLERANCE)) domain_error(function, name, "is not positive definite.", ""); Eigen::LDLT<Eigen::MatrixXd> cholesky = value_of_rec(y).ldlt(); if (cholesky.info() != Eigen::Success || !cholesky.isPositive() || (cholesky.vectorD().array() <= 0.0).any()) domain_error(function, name, "is not positive definite.", ""); check_not_nan(function, name, y); }
inline std::vector<T> sort_desc(std::vector<T> xs) { check_not_nan("sort_asc", "container argument", xs); std::sort(xs.begin(), xs.end(), std::greater<T>()); return xs; }
typename return_type<T_y, T_loc, T_covar>::type multi_normal_cholesky_log(const T_y& y, const T_loc& mu, const T_covar& L) { static const char* function("multi_normal_cholesky_log"); typedef typename scalar_type<T_covar>::type T_covar_elem; typedef typename return_type<T_y, T_loc, T_covar>::type lp_type; lp_type lp(0.0); VectorViewMvt<const T_y> y_vec(y); VectorViewMvt<const T_loc> mu_vec(mu); size_t size_vec = max_size_mvt(y, mu); int size_y = y_vec[0].size(); int size_mu = mu_vec[0].size(); if (size_vec > 1) { int size_y_old = size_y; int size_y_new; for (size_t i = 1, size_ = length_mvt(y); i < size_; i++) { int size_y_new = y_vec[i].size(); check_size_match(function, "Size of one of the vectors of " "the random variable", size_y_new, "Size of another vector of the " "random variable", size_y_old); size_y_old = size_y_new; } int size_mu_old = size_mu; int size_mu_new; for (size_t i = 1, size_ = length_mvt(mu); i < size_; i++) { int size_mu_new = mu_vec[i].size(); check_size_match(function, "Size of one of the vectors of " "the location variable", size_mu_new, "Size of another vector of the " "location variable", size_mu_old); size_mu_old = size_mu_new; } (void) size_y_old; (void) size_y_new; (void) size_mu_old; (void) size_mu_new; } check_size_match(function, "Size of random variable", size_y, "size of location parameter", size_mu); check_size_match(function, "Size of random variable", size_y, "rows of covariance parameter", L.rows()); check_size_match(function, "Size of random variable", size_y, "columns of covariance parameter", L.cols()); for (size_t i = 0; i < size_vec; i++) { check_finite(function, "Location parameter", mu_vec[i]); check_not_nan(function, "Random variable", y_vec[i]); } if (size_y == 0) return lp; if (include_summand<propto>::value) lp += NEG_LOG_SQRT_TWO_PI * size_y * size_vec; if (include_summand<propto, T_covar_elem>::value) lp -= L.diagonal().array().log().sum() * size_vec; if (include_summand<propto, T_y, T_loc, T_covar_elem>::value) { lp_type sum_lp_vec(0.0); for (size_t i = 0; i < size_vec; i++) { Eigen::Matrix<typename return_type<T_y, T_loc>::type, Eigen::Dynamic, 1> y_minus_mu(size_y); for (int j = 0; j < size_y; j++) y_minus_mu(j) = y_vec[i](j)-mu_vec[i](j); Eigen::Matrix<typename return_type<T_y, T_loc, T_covar>::type, Eigen::Dynamic, 1> half(mdivide_left_tri_low(L, y_minus_mu)); // FIXME: this code does not compile. revert after fixing subtract() // Eigen::Matrix<typename // boost::math::tools::promote_args<T_covar, // typename value_type<T_loc>::type, // typename value_type<T_y>::type>::type>::type, // Eigen::Dynamic, 1> // half(mdivide_left_tri_low(L, subtract(y, mu))); sum_lp_vec += dot_self(half); } lp -= 0.5*sum_lp_vec; } return lp; }
inline bool check_not_nan(const char* function, const T_y& y, const char* name, T_result* result = 0) { return check_not_nan(function,y,name,result,default_policy()); }
inline T2 modified_bessel_first_kind(int v, const T2 z) { check_not_nan("modified_bessel_first_kind", "z", z); return boost::math::cyl_bessel_i(v, z); }