# Specify the grid on X,Z parameter space.
n_int = 5 # choose number of intervals for grid on theta.
X = np.linspace(-80, 100, n_int)
Z = X
X_grid, Z_grid = np.meshgrid(X, Z)
# prior probabilities on the X and Z values.
muX = 10
sigmaX = 20
muZ = 10
sigmaZ = 20
# Correlation between X and Z
rho = 0.6
# compute vector of means for likelihood
meanZgivenX = muZ + rho * sigmaZ*(X_grid - muX)/sigmaX
varZgivenX = (1 - rho**2) * sigmaZ**2
sigmaZgivenX = np.sqrt(varZgivenX)
# compute likelihood
pZgivenX = norm.pdf(X_grid, meanZgivenX, sigmaZgivenX)
预期结果-不是特定值,而是5x5形状的图案。
0.0020 0.0000 0.0000 0.0000 0.0000
0.0213 0.0132 0.0005 0.0000 0.0000
0.0001 0.0060 0.0249 0.0060 0.0001
0.0000 0.0000 0.0005 0.0132 0.0213
0.0000 0.0000 0.0000 0.0000 0.0020
实际结果。
[[0.00716329 0.04781825 0.09003692 0.04781825 0.00716329]
[0.00716329 0.04781825 0.09003692 0.04781825 0.00716329]
[0.00716329 0.04781825 0.09003692 0.04781825 0.00716329]
[0.00716329 0.04781825 0.09003692 0.04781825 0.00716329]
[0.00716329 0.04781825 0.09003692 0.04781825 0.00716329]]
答案 0 :(得分:0)
我想我自己解决了这个问题。我在上一条语句中使用了X_grid,但应该使用Z_grid。 感谢所有看着我的问题的人。