我正在尝试对高度相关的数据进行广义最小二乘拟合。这些数据的协方差矩阵很大,有许多元素接近1。在
# X and Y correspond to my predictor and dependent variables
# C is the covariance matrix of Y
# BF are the best-fit parameters
# BFCM is the covariance matrix of BF
from pylab import *
BF = inv(X.T @ inv(C) @ X) @ (X.T @ inv(C) @ Y)
BFCM = inv(X.T @ inv(C) @ X)
我得到了最佳拟合参数的相关矩阵中的负对角线项(BFCM
),这绝对是错误的。这些负值似乎来自numpy.linalg
使用的有限float
精度。在这种情况下,有没有办法避免这种浮点精度问题?在
谢谢你的建议。在
目前没有回答
相关问题 更多 >
编程相关推荐