提高numpy.linalg操作的精度

时间:2018-03-17 11:24:28

标签: python numpy least-squares

我试图对高度相关的数据进行广义最小二乘拟合。这些数据的协方差矩阵很大,许多元素接近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)的相关矩阵中得到负对角项,这绝对是错误的。这些负值似乎来自float使用的有限numpy.linalg精度。在这种情况下,有没有办法避免这种浮点精度问题?

感谢您的任何建议。

0 个答案:

没有答案