bayesian_info_criterion_lsq#
- astropy.stats.bayesian_info_criterion_lsq(ssr, n_params, n_samples)[源代码]#
假设观测值来自高斯分布,计算贝叶斯信息准则(BIC)。
在这种情况下,BIC表示为
\[\mathrm{BIC}=n\ln\左(\dfrac{\mathrm{SSR}}{n}\右)+k\ln(n)\]在哪儿 \(n\) 是样本量, \(k\) 是可用参数的数目,并且 \(\mathrm{{SSR}}\) 表示模型和数据之间残差平方和。
这是适用的,例如,当一个模型的参数估计使用最小二乘统计。看到了吗 [1] 和 [2].
- 参数:
- 返回:
- bic :
float
Python :浮点
- bic :
工具书类
[1]维基百科。贝叶斯信息准则。<https://en.wikipedia.org/wiki/Bayesian_information_标准>
[2]原始实验室。比较两个拟合函数。<https://www.originlab.com/doc/Origin-Help/PostFit-CompareFitFunc>
[3]实例
考虑一下Astropy建模网页中提供的简单的1-D拟合示例 [3]. 在那里,两个模型(盒和高斯)被拟合到一个源通量使用最小二乘统计。然而,配件本身并不能说明哪个模型更能代表这个假设的来源。因此,我们将向BIC申请,以决定是否有利于一个模型。
>>> import numpy as np >>> from astropy.modeling import models, fitting >>> from astropy.stats.info_theory import bayesian_info_criterion_lsq >>> # Generate fake data >>> np.random.seed(0) >>> x = np.linspace(-5., 5., 200) >>> y = 3 * np.exp(-0.5 * (x - 1.3)**2 / 0.8**2) >>> y += np.random.normal(0., 0.2, x.shape) >>> # Fit the data using a Box model. >>> # Bounds are not really needed but included here to demonstrate usage. >>> t_init = models.Trapezoid1D(amplitude=1., x_0=0., width=1., slope=0.5, ... bounds={"x_0": (-5., 5.)}) >>> fit_t = fitting.LevMarLSQFitter() >>> t = fit_t(t_init, x, y) >>> # Fit the data using a Gaussian >>> g_init = models.Gaussian1D(amplitude=1., mean=0, stddev=1.) >>> fit_g = fitting.LevMarLSQFitter() >>> g = fit_g(g_init, x, y) >>> # Compute the mean squared errors >>> ssr_t = np.sum((t(x) - y)*(t(x) - y)) >>> ssr_g = np.sum((g(x) - y)*(g(x) - y)) >>> # Compute the bics >>> bic_t = bayesian_info_criterion_lsq(ssr_t, 4, x.shape[0]) >>> bic_g = bayesian_info_criterion_lsq(ssr_g, 3, x.shape[0]) >>> bic_t - bic_g 30.644474706065466
因此,有一个非常有力的证据表明高斯模型比盒子模型具有更好的数据表示。很明显,这是意料之中的,因为真实的模型是高斯的。