Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] add low-rank fitting #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mgwr/gwr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import copy
from typing import Optional
import numpy as np
import numpy.linalg as la
from scipy import linalg as la
from scipy.stats import t
from scipy.special import factorial
from itertools import combinations as combo
from spglm.family import Gaussian, Binomial, Poisson
from spglm.glm import GLM, GLMResults
from spglm.iwls import iwls, _compute_betas_gwr
from spglm.iwls import iwls, _compute_betas_gwr, _low_rank_hat
from spglm.utils import cache_readonly
from .diagnostics import get_AIC, get_AICc, get_BIC, corr
from .kernels import *
Expand Down Expand Up @@ -257,7 +257,11 @@ def _local_fit(self, i):
wi = self._build_wi(i, self.bw).reshape(-1, 1) #local spatial weights

if isinstance(self.family, Gaussian):
betas, inv_xtx_xt = _compute_betas_gwr(self.y, self.X, wi)
betas, rank = _compute_betas_gwr(self.y, self.X, wi)
if rank < self.X.shape[1]:
inv_xtx_xt = _low_rank_hat(self.X)
else:
inv_xtx_xt = la.solve(self.X.T @ self.X, self.X)
predy = np.dot(self.X[i], betas)[0]
resid = self.y[i] - predy
influ = np.dot(self.X[i], inv_xtx_xt[:, i])
Expand Down
Loading