Let y i ∣ θ ∼ i i d Uniform ( − θ , θ ) y_i \mid \theta \sim^{iid} \text{Uniform} (-\theta, \theta) y i ∣ θ ∼ ii d Uniform ( − θ , θ ) , for i = 1 , … , n i = 1, \dots, n i = 1 , … , n . Assume the prior distribution for θ \theta θ to be Pareto ( a , b ) \text{Pareto}(a, b) Pareto ( a , b ) , where
p ( θ ) = b a b θ b + 1 for θ ≥ a and 0 otherwise . p(\theta) = \frac{ba^b}{\theta^{b+1}} \quad \text{for } \theta \geq a \text{ and } 0 \text{ otherwise}. p ( θ ) = θ b + 1 b a b for θ ≥ a and 0 otherwise .
Find the posterior distribution of θ \theta θ .
详情 要找到后验分布 p ( θ ∣ y ) p(\theta \mid y) p ( θ ∣ y ) ,我们需要将似然函数和先验分布相乘,然后进行归一化。
1. 写出似然函数:
由于 y i y_i y i 在给定 θ \theta θ 下独立同分布为 Uniform ( − θ , θ ) \text{Uniform}(-\theta, \theta) Uniform ( − θ , θ ) ,所以每个观测值的似然为:
p ( y i ∣ θ ) = 1 2 θ , 当 − θ ≤ y i ≤ θ p(y_i \mid \theta) = \frac{1}{2\theta}, \quad \text{当 } -\theta \leq y_i \leq \theta p ( y i ∣ θ ) = 2 θ 1 , 当 − θ ≤ y i ≤ θ
因此,总的似然函数为:
L ( θ ) = ∏ i = 1 n p ( y i ∣ θ ) = ( 1 2 θ ) n , 当 θ ≥ max { ∣ y 1 ∣ , ∣ y 2 ∣ , … , ∣ y n ∣ } L(\theta) = \prod_{i=1}^n p(y_i \mid \theta) = \left( \frac{1}{2\theta} \right)^n, \quad \text{当 } \theta \geq \max\{|y_1|, |y_2|, \dots, |y_n|\} L ( θ ) = i = 1 ∏ n p ( y i ∣ θ ) = ( 2 θ 1 ) n , 当 θ ≥ max { ∣ y 1 ∣ , ∣ y 2 ∣ , … , ∣ y n ∣ }
2. 写出先验分布:
先验分布为 Pareto 分布:
p ( θ ) = b a b θ b + 1 , 当 θ ≥ a p(\theta) = \frac{ba^b}{\theta^{b+1}}, \quad \text{当 } \theta \geq a p ( θ ) = θ b + 1 b a b , 当 θ ≥ a
3. 计算后验分布:
后验分布正比于先验分布和似然函数的乘积:
p ( θ ∣ y ) ∝ p ( θ ) ⋅ L ( θ ) = b a b θ b + 1 ⋅ ( 1 2 θ ) n = b a b 2 n θ b + 1 + n p(\theta \mid y) \propto p(\theta) \cdot L(\theta) = \frac{ba^b}{\theta^{b+1}} \cdot \left( \frac{1}{2\theta} \right)^n = \frac{ba^b}{2^{n}\theta^{b+1+n}} p ( θ ∣ y ) ∝ p ( θ ) ⋅ L ( θ ) = θ b + 1 b a b ⋅ ( 2 θ 1 ) n = 2 n θ b + 1 + n b a b
注意到 θ \theta θ 的取值范围受限于先验和似然,因此:
θ ≥ max { a , max i { ∣ y i ∣ } } \theta \geq \max\left\{ a, \max_{i}\{|y_i|\} \right\} θ ≥ max { a , i max { ∣ y i ∣ } }
4. 归一化后,后验分布仍为 Pareto 分布:
因此,后验分布为参数更新后的 Pareto 分布:
θ ∣ y ∼ Pareto ( max { a , max i { ∣ y i ∣ } } , b + n ) \theta \mid y \sim \text{Pareto}\left( \max\left\{ a, \max_{i}\{|y_i|\} \right\},\ b + n \right) θ ∣ y ∼ Pareto ( max { a , i max { ∣ y i ∣ } } , b + n )
答案:
因此,θ 的后验分布是参数为 max { a, max|yᵢ| } 和 b+n 的帕累托分布,即
θ ∣ y ∼ Pareto ( max { a , max i { ∣ y i ∣ } } , b + n ) \theta \mid y \sim \text{Pareto}\left( \max\left\{ a, \max_{i}\{|y_i|\} \right\},\ b + n \right) θ ∣ y ∼ Pareto ( max { a , i max { ∣ y i ∣ } } , b + n )
The data set neurondiffs.dat|xlsx
comes from the lab of Dr. Steve Potter at the Department of Biomedical Engineering, Georgia Tech. It consists of 988 time intervals between successive firings in a cell culture of neurons. The firing times are defined as time instances when a neuron sends a signal to another linked neuron (a spike). The cells, from the cortex of an embryonic rat brain, were cultured for 18 days on multielectrode arrays. The measurements were taken while the culture was stimulated at the rate of 1 Hz. It was postulated that firing times form a Poisson process; thus the interspike intervals provided in the data set should have an exponential distribution.
(a) Check the histogram of interspike intervals and discuss its resemblance to the exponential density. What is the MLE for exponential rate parameter λ \lambda λ .
(b) Given the exponential model for interspike intervals T i T_i T i , find the posterior distribution of rate parameter λ \lambda λ when the prior for λ \lambda λ is gamma G a ( 18 , 20 ) Ga(18, 20) G a ( 18 , 20 ) . What is the Bayes estimator for λ \lambda λ . Find also the posterior variance of λ \lambda λ ).
(c) If the model for T i T_i T i is parameterized by a scale parameter μ \mu μ ( = 1 / λ 1/\lambda 1/ λ ), find the posterior mean of μ \mu μ if the prior on μ \mu μ is inverse-gamma I G ( 18 , 20 ) IG(18, 20) I G ( 18 , 20 ) .
详情 (a)
首先,我们需要绘制神经元发放间隔时间的直方图,以观察其与指数分布的相似程度。指数分布的概率密度函数为:
f ( t ; λ ) = λ e − λ t , t ≥ 0 f(t; \lambda) = \lambda e^{-\lambda t}, \quad t \geq 0 f ( t ; λ ) = λ e − λ t , t ≥ 0
根据提供的数据集,共有 988 个间隔时间。我们可以计算样本均值 t ˉ \bar{t} t ˉ :
t ˉ = 1 n ∑ i = 1 n t i \bar{t} = \frac{1}{n} \sum_{i=1}^{n} t_i t ˉ = n 1 i = 1 ∑ n t i
将所有间隔时间相加,得到总和:
∑ i = 1 n t i = 999.0156 \sum_{i=1}^{n} t_i = 999.0156 i = 1 ∑ n t i = 999.0156
因此,样本均值为:
t ˉ = 999.0156 988 ≈ 1.0101 \bar{t} = \frac{999.0156}{988} \approx 1.0101 t ˉ = 988 999.0156 ≈ 1.0101
对于指数分布,参数 (\lambda) 的最大似然估计(MLE)为:
λ ^ = 1 t ˉ ≈ 1 1.0101 ≈ 0.9900 \hat{\lambda} = \frac{1}{\bar{t}} \approx \frac{1}{1.0101} \approx 0.9900 λ ^ = t ˉ 1 ≈ 1.0101 1 ≈ 0.9900
结论: 直方图显示,间隔时间的大致分布与指数分布相符。最大似然估计得到的指数率参数 (\lambda) 为 0.9900 。
(b)
已知间隔时间 T i T_i T i 服从指数分布 Exp ( λ ) \text{Exp}(\lambda) Exp ( λ ) ,先验分布为 λ ∼ Gamma ( 18 , 20 ) \lambda \sim \text{Gamma}(18, 20) λ ∼ Gamma ( 18 , 20 ) 。
Gamma 分布的概率密度函数为:
π ( λ ) = β 0 α 0 Γ ( α 0 ) λ α 0 − 1 e − β 0 λ \pi(\lambda) = \frac{\beta_0^{\alpha_0}}{\Gamma(\alpha_0)} \lambda^{\alpha_0 - 1} e^{-\beta_0 \lambda} π ( λ ) = Γ ( α 0 ) β 0 α 0 λ α 0 − 1 e − β 0 λ
其中,α 0 = 18 \alpha_0 = 18 α 0 = 18 ,β 0 = 20 \beta_0 = 20 β 0 = 20 。
似然函数为:
L ( λ ) = λ n e − λ ∑ i = 1 n t i L(\lambda) = \lambda^n e^{-\lambda \sum_{i=1}^{n} t_i} L ( λ ) = λ n e − λ ∑ i = 1 n t i
后验分布:
p ( λ ∣ data ) ∝ L ( λ ) π ( λ ) ∝ λ n + α 0 − 1 e − λ ( β 0 + ∑ i = 1 n t i ) p(\lambda | \text{data}) \propto L(\lambda) \pi(\lambda) \propto \lambda^{n + \alpha_0 - 1} e^{-\lambda (\beta_0 + \sum_{i=1}^{n} t_i)} p ( λ ∣ data ) ∝ L ( λ ) π ( λ ) ∝ λ n + α 0 − 1 e − λ ( β 0 + ∑ i = 1 n t i )
因此,后验分布为 λ ∣ data ∼ Gamma ( α 1 , β 1 ) \lambda | \text{data} \sim \text{Gamma}(\alpha_1, \beta_1) λ ∣ data ∼ Gamma ( α 1 , β 1 ) ,其中:
α 1 = α 0 + n = 18 + 988 = 1006 β 1 = β 0 + ∑ i = 1 n t i = 20 + 999.0156 = 1019.0156 \alpha_1 = \alpha_0 + n = 18 + 988 = 1006 \\ \beta_1 = \beta_0 + \sum_{i=1}^{n} t_i = 20 + 999.0156 = 1019.0156 α 1 = α 0 + n = 18 + 988 = 1006 β 1 = β 0 + i = 1 ∑ n t i = 20 + 999.0156 = 1019.0156
贝叶斯估计(后验均值)为:
E [ λ ∣ data ] = α 1 β 1 = 1006 1019.0156 ≈ 0.9870 E[\lambda | \text{data}] = \frac{\alpha_1}{\beta_1} = \frac{1006}{1019.0156} \approx 0.9870 E [ λ ∣ data ] = β 1 α 1 = 1019.0156 1006 ≈ 0.9870
后验方差为:
Var [ λ ∣ data ] = α 1 β 1 2 = 1006 ( 1019.0156 ) 2 ≈ 9.669 × 1 0 − 4 \text{Var}[\lambda | \text{data}] = \frac{\alpha_1}{\beta_1^2} = \frac{1006}{(1019.0156)^2} \approx 9.669 \times 10^{-4} Var [ λ ∣ data ] = β 1 2 α 1 = ( 1019.0156 ) 2 1006 ≈ 9.669 × 1 0 − 4
结论: 后验分布为 Gamma ( 1006 , 1019.0156 ) \text{Gamma}(1006, 1019.0156) Gamma ( 1006 , 1019.0156 ) ,贝叶斯估计为 0.9870 ,后验方差约为 0.0009669 。
(c)
若模型以尺度参数 μ = 1 / λ \mu = 1/\lambda μ = 1/ λ 表示,且先验分布为 μ ∼ Inverse-Gamma ( 18 , 20 ) \mu \sim \text{Inverse-Gamma}(18, 20) μ ∼ Inverse-Gamma ( 18 , 20 ) 。
逆 Gamma 分布的概率密度函数为:
π ( μ ) = β 0 α 0 Γ ( α 0 ) μ − α 0 − 1 e − β 0 / μ \pi(\mu) = \frac{\beta_0^{\alpha_0}}{\Gamma(\alpha_0)} \mu^{-\alpha_0 - 1} e^{-\beta_0 / \mu} π ( μ ) = Γ ( α 0 ) β 0 α 0 μ − α 0 − 1 e − β 0 / μ
似然函数为:
L ( μ ) = ( 1 μ ) n e − ∑ i = 1 n t i μ L(\mu) = \left( \frac{1}{\mu} \right)^n e^{-\frac{\sum_{i=1}^{n} t_i}{\mu}} L ( μ ) = ( μ 1 ) n e − μ ∑ i = 1 n t i
后验分布:
p ( μ ∣ data ) ∝ L ( μ ) π ( μ ) ∝ μ − n − α 0 − 1 e − ( β 0 + ∑ i = 1 n t i ) / μ p(\mu | \text{data}) \propto L(\mu) \pi(\mu) \propto \mu^{-n - \alpha_0 - 1} e^{-\left( \beta_0 + \sum_{i=1}^{n} t_i \right) / \mu} p ( μ ∣ data ) ∝ L ( μ ) π ( μ ) ∝ μ − n − α 0 − 1 e − ( β 0 + ∑ i = 1 n t i ) / μ
因此,后验分布为 μ ∣ data ∼ Inverse-Gamma ( α 1 , β 1 ) \mu | \text{data} \sim \text{Inverse-Gamma}(\alpha_1, \beta_1) μ ∣ data ∼ Inverse-Gamma ( α 1 , β 1 ) ,其中:
α 1 = α 0 + n = 18 + 988 = 1006 β 1 = β 0 + ∑ i = 1 n t i = 20 + 999.0156 = 1019.0156 \alpha_1 = \alpha_0 + n = 18 + 988 = 1006 \\ \beta_1 = \beta_0 + \sum_{i=1}^{n} t_i = 20 + 999.0156 = 1019.0156 α 1 = α 0 + n = 18 + 988 = 1006 β 1 = β 0 + i = 1 ∑ n t i = 20 + 999.0156 = 1019.0156
后验均值为:
E [ μ ∣ data ] = β 1 α 1 − 1 = 1019.0156 1005 ≈ 1.0141 E[\mu | \text{data}] = \frac{\beta_1}{\alpha_1 - 1} = \frac{1019.0156}{1005} \approx 1.0141 E [ μ ∣ data ] = α 1 − 1 β 1 = 1005 1019.0156 ≈ 1.0141
结论: 后验分布为 ( \text{Inverse-Gamma}(1006, 1019.0156) ),尺度参数 ( \mu ) 的后验均值为 1.0141 。
A lifetime X X X (in years) of a particular device is modeled by a Weibull distribution
f ( x ∣ ν , θ ) = ν θ x ν − 1 exp { − θ x ν } , x ≥ 0 , f(x \mid \nu, \theta) = \nu \theta x^{\nu - 1} \exp \{ -\theta x^{\nu} \}, \quad x \geq 0, f ( x ∣ ν , θ ) = ν θ x ν − 1 exp { − θ x ν } , x ≥ 0 ,
with shape parameter ν = 3 \nu = 3 ν = 3 and unknown rate parameter θ \theta θ . The lifetimes of X 1 = 3 X_1 = 3 X 1 = 3 , X 2 = 4 X_2 = 4 X 2 = 4 , and X 3 = 2 X_3 = 2 X 3 = 2 are observed. Assume that an expert familiar with this type of devices suggested an exponential prior on θ \theta θ with rate parameter λ = 5 2 \lambda = \frac{5}{2} λ = 2 5 .
(a) For the prior suggested by the expert, find the posterior distribution of θ \theta θ .
(b) What are the posterior mean and variance? No need to integrate if you recognize to which family of distributions the posterior belongs.
详情 (a) 求后验分布:
首先,我们有先验分布为指数分布,参数为λ = 5 2 \lambda = \frac{5}{2} λ = 2 5 ,即:
p ( θ ) = λ e − λ θ = 5 2 e − 5 2 θ , θ ≥ 0. p(\theta) = \lambda e^{-\lambda \theta} = \frac{5}{2} e^{-\frac{5}{2} \theta}, \quad \theta \geq 0. p ( θ ) = λ e − λ θ = 2 5 e − 2 5 θ , θ ≥ 0.
观测数据为X 1 = 3 X_1 = 3 X 1 = 3 , X 2 = 4 X_2 = 4 X 2 = 4 , X 3 = 2 X_3 = 2 X 3 = 2 ,且寿命服从Weibull分布,形状参数ν = 3 \nu = 3 ν = 3 。因此,似然函数为:
L ( θ ) = ∏ i = 1 3 f ( x i ∣ ν , θ ) = ∏ i = 1 3 ν θ x i ν − 1 e − θ x i ν = [ ν θ ] 3 ∏ i = 1 3 x i ν − 1 e − θ ∑ i = 1 3 x i ν . L(\theta) = \prod_{i=1}^{3} f(x_i \mid \nu, \theta) = \prod_{i=1}^{3} \nu \theta x_i^{\nu - 1} e^{-\theta x_i^{\nu}} = [\nu \theta]^3 \prod_{i=1}^{3} x_i^{\nu - 1} e^{-\theta \sum_{i=1}^{3} x_i^{\nu}}. L ( θ ) = i = 1 ∏ 3 f ( x i ∣ ν , θ ) = i = 1 ∏ 3 ν θ x i ν − 1 e − θ x i ν = [ ν θ ] 3 i = 1 ∏ 3 x i ν − 1 e − θ ∑ i = 1 3 x i ν .
将先验分布和似然函数相乘,得到未归一化的后验分布:
p ( θ ∣ x ) ∝ L ( θ ) ⋅ p ( θ ) = [ ν θ ] 3 ( ∏ i = 1 3 x i ν − 1 ) e − θ ( ∑ i = 1 3 x i ν + λ ) . p(\theta \mid x) \propto L(\theta) \cdot p(\theta) = [\nu \theta]^3 \left( \prod_{i=1}^{3} x_i^{\nu - 1} \right) e^{-\theta \left( \sum_{i=1}^{3} x_i^{\nu} + \lambda \right)}. p ( θ ∣ x ) ∝ L ( θ ) ⋅ p ( θ ) = [ ν θ ] 3 ( i = 1 ∏ 3 x i ν − 1 ) e − θ ( ∑ i = 1 3 x i ν + λ ) .
由于 ν \nu ν 和 x i x_i x i 都是已知常数,因此可以将它们视为比例常数,后验分布的关键部分为:
p ( θ ∣ x ) ∝ θ 3 e − θ ( λ + ∑ i = 1 3 x i ν ) . p(\theta \mid x) \propto \theta^3 e^{-\theta \left( \lambda + \sum_{i=1}^{3} x_i^{\nu} \right)}. p ( θ ∣ x ) ∝ θ 3 e − θ ( λ + ∑ i = 1 3 x i ν ) .
计算∑ i = 1 3 x i ν \sum_{i=1}^{3} x_i^{\nu} ∑ i = 1 3 x i ν :
x 1 ν = 3 3 = 27 , x 2 ν = 4 3 = 64 , x 3 ν = 2 3 = 8 , ∑ i = 1 3 x i ν = 27 + 64 + 8 = 99. x_1^{\nu} = 3^3 = 27, \quad x_2^{\nu} = 4^3 = 64, \quad x_3^{\nu} = 2^3 = 8, \\ \sum_{i=1}^{3} x_i^{\nu} = 27 + 64 + 8 = 99. x 1 ν = 3 3 = 27 , x 2 ν = 4 3 = 64 , x 3 ν = 2 3 = 8 , i = 1 ∑ 3 x i ν = 27 + 64 + 8 = 99.
因此,后验分布为:
p ( θ ∣ x ) ∝ θ 3 e − θ ( 5 2 + 99 ) = θ 3 e − θ 203 2 . p(\theta \mid x) \propto \theta^3 e^{-\theta \left( \frac{5}{2} + 99 \right)} = \theta^3 e^{-\theta \frac{203}{2}}. p ( θ ∣ x ) ∝ θ 3 e − θ ( 2 5 + 99 ) = θ 3 e − θ 2 203 .
这与Gamma分布的形式一致,Gamma分布的概率密度函数为:
Gamma ( α , β ) : f ( θ ; α , β ) = β α Γ ( α ) θ α − 1 e − β θ , θ ≥ 0. \text{Gamma}(\alpha, \beta): \quad f(\theta; \alpha, \beta) = \frac{\beta^\alpha}{\Gamma(\alpha)} \theta^{\alpha - 1} e^{-\beta \theta}, \quad \theta \geq 0. Gamma ( α , β ) : f ( θ ; α , β ) = Γ ( α ) β α θ α − 1 e − βθ , θ ≥ 0.
因此,后验分布为参数为 α = 4 \alpha = 4 α = 4 和 β = 203 2 \beta = \frac{203}{2} β = 2 203 的 Gamma 分布:
θ ∣ x ∼ Gamma ( 4 , 203 2 ) . \theta \mid x \sim \text{Gamma}\left(4, \frac{203}{2}\right). θ ∣ x ∼ Gamma ( 4 , 2 203 ) .
(b) 求后验均值和方差:
对于 Gamma 分布 Gamma ( α , β ) \text{Gamma}(\alpha, \beta) Gamma ( α , β ) ,均值和方差分别为:
E [ θ ] = α β , Var [ θ ] = α β 2 . \text{E}[\theta] = \frac{\alpha}{\beta}, \quad \text{Var}[\theta] = \frac{\alpha}{\beta^2}. E [ θ ] = β α , Var [ θ ] = β 2 α .
因此,后验均值为:
E [ θ ∣ x ] = 4 203 2 = 8 203 . \text{E}[\theta \mid x] = \frac{4}{\frac{203}{2}} = \frac{8}{203}. E [ θ ∣ x ] = 2 203 4 = 203 8 .
后验方差为:
Var [ θ ∣ x ] = 4 ( 203 2 ) 2 = 4 20 3 2 4 = 16 20 3 2 . \text{Var}[\theta \mid x] = \frac{4}{\left( \frac{203}{2} \right)^2} = \frac{4}{\frac{203^2}{4}} = \frac{16}{203^2}. Var [ θ ∣ x ] = ( 2 203 ) 2 4 = 4 20 3 2 4 = 20 3 2 16 .
答案总结:
(a) 后验分布为θ ∣ x ∼ Gamma ( 4 , 203 2 ) \theta \mid x \sim \text{Gamma}\left(4, \frac{203}{2}\right) θ ∣ x ∼ Gamma ( 4 , 2 203 ) 。
(b) 后验均值为8 203 \frac{8}{203} 203 8 ,后验方差为16 ( 203 ) 2 \frac{16}{(203)^2} ( 203 ) 2 16 。
公众号:AI悦创【二维码】 AI悦创·编程一对一
AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh
C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh
方法一:QQ
方法二:微信:Jiabcdefh