Skip to content

Commit 9682660

Browse files
authored
ENH gradient, raw grad and hessian for Quadratic (#257)
1 parent 7ae11ea commit 9682660

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

skglm/datafits/single_task.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ def gradient_scalar_sparse(self, X_data, X_indptr, X_indices, y, Xw, j):
9292
XjTXw += X_data[i] * Xw[X_indices[i]]
9393
return (XjTXw - self.Xty[j]) / len(Xw)
9494

95+
def gradient(self, X, y, Xw):
96+
return X.T @ (Xw - y) / len(y)
97+
98+
def raw_grad(self, y, Xw):
99+
"""Compute gradient of datafit w.r.t ``Xw``."""
100+
return (Xw - y) / len(y)
101+
102+
def raw_hessian(self, y, Xw):
103+
"""Compute Hessian of datafit w.r.t ``Xw``."""
104+
return np.ones(len(y)) / len(y)
105+
95106
def full_grad_sparse(
96107
self, X_data, X_indptr, X_indices, y, Xw):
97108
n_features = X_indptr.shape[0] - 1

0 commit comments

Comments
 (0)