提高精度努比·利纳格操作

2024-06-16 13:37:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试对高度相关的数据进行广义最小二乘拟合。这些数据的协方差矩阵很大,有许多元素接近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精度。在这种情况下,有没有办法避免这种浮点精度问题?在

谢谢你的建议。在


Tags: andofthe数据元素高度is精度