Sherman-Morrison update for a single example
(self, x, y, w)
| 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""" |