From 98ea2ed5946fb1fac619f68003312b83446884ae Mon Sep 17 00:00:00 2001 From: Gavin Chan Date: Fri, 22 Sep 2023 08:02:42 +0100 Subject: [PATCH] fix: use engine linalg in WLS --- src/fpm_risk_model/regressor/wls.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fpm_risk_model/regressor/wls.py b/src/fpm_risk_model/regressor/wls.py index 08ebb9d..5200abd 100644 --- a/src/fpm_risk_model/regressor/wls.py +++ b/src/fpm_risk_model/regressor/wls.py @@ -2,7 +2,10 @@ from typing import Optional from numpy import ndarray -from numpy.linalg import pinv + +from ..engine import LinAlgEngine + +linalg = LinAlgEngine() @dataclass @@ -85,14 +88,14 @@ def _close_fit(X: ndarray, y: ndarray, weights: Optional[ndarray] = None): if len(weights.shape) == 1 and weights.shape[0] == y.shape[0]: weights = weights**0.5 X_t_w = X.T * weights * weights.T - beta = pinv(X_t_w @ X) @ X_t_w @ y + beta = linalg.pinv(X_t_w @ X) @ X_t_w @ y else: raise ValueError( f"Dimension of y {y.shape} does not align with weights " f"{weights.shape}" ) else: - beta = pinv(X.T @ X) @ X.T @ y + beta = linalg.pinv(X.T @ X) @ X.T @ y alpha = y - X @ beta return RegressionResult(alpha=alpha, beta=beta)