13 if (isfinite(centered)) {
return centered / sigma; }
14 return x / sigma - mu / sigma;
23 z = standardized_normal_value(x, mu, sigma);
26 return store_density_from_log(log_density, out);
35 z = standardized_normal_value(x, mu, sigma);
36 return store_probability_result(
37 0.5 * erfc(-z / sqrt(2.0)), out);
44 if (abs_x <= sqrt_df) {
46 return log1p(ratio * ratio);
50 return 2.0 * log(abs_x) - log(df) +
59 if (abs_x <= sqrt_df) {
62 return 1.0 / (1.0 + ratio_sq);
67 return ratio_sq / (1.0 + ratio_sq);
75 if (student_t_uses_normal_limit(df)) {
76 return store_density_from_log(
79 if (df / 2.0 == 0.0) {
81 log_density = 0.5 * log(df) - log(2.0) -
82 0.5 * student_t_log_kernel(x, df);
83 return store_density_from_log(log_density, out);
90 log_density = -log_beta - 0.5 * log(df) -
91 ((df + 1.0) / 2.0) * student_t_log_kernel(x, df);
93 return store_density_from_log(log_density, out);
101 if (student_t_uses_normal_limit(df)) {
102 return store_probability_result(
103 0.5 * erfc(-x / sqrt(2.0)), out);
105 if (df / 2.0 == 0.0) {
110 t_val = student_t_beta_argument(x, df);
117 log(df) - 2.0 * log(fabs(x));
121 ib = exp(a * log_t - log(a) - log_beta);
123 result = x >= 0.0 ? 1.0 - 0.5 * ib : 0.5 * ib;
124 return store_probability_result(result, out);
138 if (df / 2.0 == 0.0) {
140 return store_density_from_log(
141 log(df) - log(x) - log(2.0) - x / 2.0, out);
148 return store_density_from_log(
149 (k2 - 1.0) * log(x) - x / 2.0 -
150 k2 * log(2.0) - lgamma(k2),
164static int f_beta_density(
169 if (isfinite(scale) && scale > 0.0) {
174 beta_x = 1.0 / (1.0 + ratio);
175 beta_complement = ratio / (1.0 + ratio);
178 beta_x = ratio / (1.0 + ratio);
179 beta_complement = 1.0 / (1.0 + ratio);
181 if (beta_x > 0.0 && beta_complement > 0.0) {
184 beta_x, beta_complement, first_shape, second_shape, &log_kernel);
186 *status = store_density_from_log(log_kernel - log(x), out);
196 lmmc_real_t first_shape, second_shape, total_shape;
207 first_shape = df1 / 2.0;
208 second_shape = df2 / 2.0;
209 total_shape = first_shape + second_shape;
212 if (f_beta_density(x, df1, df2, first_shape, second_shape, out, &status)) {
217 num = first_shape * log(df1 / df2) +
218 (first_shape - 1.0) * log(x);
219 den = total_shape * log1p(df1 * x / df2);
225 return store_density_from_log(num - den - log_beta, out);
237 if (df1 / 2.0 == 0.0) {
239 *out = df2 / (df1 + df2);
248 tail_x, df2 / 2.0, df1 / 2.0, &result);
254 beta_x, df1 / 2.0, df2 / 2.0, &result);
257 return store_probability_result(result, out);
267 if (shape == 1.0) {
return store_density_from_log(-log(scale), out); }
273 if (isfinite(standardized) && standardized > 0.0) {
277 log(standardized) + 0.5 * log(shape) -
279 return store_density_from_log(log_density, out);
283 return store_density_from_log(
284 (shape - 1.0) * log(x) - x / scale -
285 shape * log(scale) - lgamma(shape),
296 standardized = x / scale;
297 if (standardized == 0.0) {
299 shape * (log(x) - log(scale)) - lgamma(shape + 1.0);
300 return store_probability_result(exp(log_probability), out);
311 return store_density_from_log(logarithm - log(x) - log1p(-x), out);
330 return beta_interior_density(x, alpha, beta_param, out);
LMMC binary real type and arithmetic spelling.
double lmmc_real_t
Public and internal LMMC real type.
lmmc_status_t lmmc_log_beta(double a, double b, double *out_log_beta)
稳定计算 log B(a,b) 和 log(x^a complement_x^b / B(a,b))。 独立传入补数以保留微小上尾;负无穷表示有效下溢,失败时输出保持不变。
lmmc_status_t regularized_gamma_lower(lmmc_real_t a, lmmc_real_t x, lmmc_real_t *out)
正则化不完全伽马函数下尾 P(a, x) = gamma(a, x) / Gamma(a)。 使用级数展开或连分数展开。
lmmc_status_t regularized_beta(lmmc_real_t x, lmmc_real_t a, lmmc_real_t b, lmmc_real_t *out)
lmmc_status_t regularized_beta_upper(lmmc_real_t x, lmmc_real_t a, lmmc_real_t b, lmmc_real_t *out)
计算上尾;1 - x 舍入至端点时仍保留 x。
lmmc_real_t lmmc_log_gamma_stirling_error(lmmc_real_t x)
lmmc_real_t lmmc_deviance_part(lmmc_real_t x, lmmc_real_t mean)
lmmc_status_t lmmc_beta_log_kernel(double x, double complement_x, double a, double b, double *out_log_kernel)
#define LMMC_LOG_SQRT_2PI
lmmc_status_t lmmc_dist_beta_pdf(lmmc_real_t x, lmmc_real_t alpha, lmmc_real_t beta, lmmc_real_t *out)
贝塔分布概率密度函数。
lmmc_status_t lmmc_dist_chi2_cdf(lmmc_real_t x, lmmc_real_t df, lmmc_real_t *out)
χ² 分布累积分布函数。
lmmc_status_t lmmc_dist_t_cdf(lmmc_real_t x, lmmc_real_t df, lmmc_real_t *out)
t 分布累积分布函数。
lmmc_status_t lmmc_dist_normal_cdf(lmmc_real_t x, lmmc_real_t mu, lmmc_real_t sigma, lmmc_real_t *out)
正态分布累积分布函数。
lmmc_status_t lmmc_dist_gamma_pdf(lmmc_real_t x, lmmc_real_t shape, lmmc_real_t scale, lmmc_real_t *out)
伽马分布概率密度函数。
lmmc_status_t lmmc_dist_normal_pdf(lmmc_real_t x, lmmc_real_t mu, lmmc_real_t sigma, lmmc_real_t *out)
连续分布函数的公共参数约束。
lmmc_status_t lmmc_dist_beta_cdf(lmmc_real_t x, lmmc_real_t alpha, lmmc_real_t beta, lmmc_real_t *out)
贝塔分布累积分布函数。
lmmc_status_t lmmc_dist_gamma_cdf(lmmc_real_t x, lmmc_real_t shape, lmmc_real_t scale, lmmc_real_t *out)
伽马分布累积分布函数。
lmmc_status_t lmmc_dist_f_cdf(lmmc_real_t x, lmmc_real_t df1, lmmc_real_t df2, lmmc_real_t *out)
F 分布累积分布函数。
lmmc_status_t lmmc_dist_chi2_pdf(lmmc_real_t x, lmmc_real_t df, lmmc_real_t *out)
χ² 分布概率密度函数。
lmmc_status_t lmmc_dist_t_pdf(lmmc_real_t x, lmmc_real_t df, lmmc_real_t *out)
t 分布概率密度函数。
lmmc_status_t lmmc_dist_f_pdf(lmmc_real_t x, lmmc_real_t df1, lmmc_real_t df2, lmmc_real_t *out)
F 分布概率密度函数。
lmmc_status_t
LMMC 库统一返回的状态码.
@ LMMC_STATUS_NUMERICAL_FAILURE
@ LMMC_STATUS_INVALID_ARGUMENT