MCPcopy
hub / github.com/ddbourgin/numpy-ml / _update1D

Method _update1D

numpy_ml/linear_models/linear_regression.py:142–154  ·  view source on GitHub ↗

Sherman-Morrison update for a single example

(self, x, y, w)

Source from the content-addressed store, hash-verified

140 return self
141
142 def _update1D(self, x, y, w):
143 """Sherman-Morrison update for a single example"""
144 beta, S_inv = self.beta, self.sigma_inv
145
146 # convert x to a design vector if we're fitting an intercept
147 if self.fit_intercept:
148 x = np.c_[np.diag(w), x]
149
150 # update the inverse of the covariance matrix via Sherman-Morrison
151 S_inv -= (S_inv @ x.T @ x @ S_inv) / (1 + x @ S_inv @ x.T)
152
153 # update the model coefficients
154 beta += S_inv @ x.T @ (y - x @ beta)
155
156 def _update2D(self, X, y, W):
157 """Woodbury update for multiple examples"""

Callers 1

updateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected