Files
Baysian_Canonical_Identific…/kalmanFilter.py
T
2025-11-02 20:47:28 +08:00

29 lines
844 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import beta
# 定义 Beta 分布的参数
alpha = 2
beta_param = 2 # 注意这里变量名不能与模块名beta重复,所以用beta_param
# 生成 x 值,Beta 分布的定义域是 [0, 1]
# 我们生成一系列在 0 到 1 之间的点
x = np.linspace(0.01, 0.99, 500) # 避免在0和1处logpdf可能趋向负无穷导致绘图问题,稍微避开边界
# 计算每个 x 值的 logpdf
log_pdf_values = beta.logpdf(x, alpha, beta_param)
# 绘图
plt.figure(figsize=(10, 6))
plt.plot(x, log_pdf_values, label=f'logPDF of Beta(α={alpha}, β={beta_param})')
# 添加标题和标签
plt.title(f'Log-Probability Density Function (logPDF) of Beta(α={alpha}, β={beta_param})')
plt.xlabel('x')
plt.ylabel('log(PDF)')
plt.grid(True)
plt.legend()
# 显示图形
plt.show()