Coverage for bmm_multitask_learning/coalescent/utils.py: 0%
22 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-13 13:33 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-13 13:33 +0000
1import numpy as np
2from sklearn.linear_model import LinearRegression
5class grad_optimizer:
6 def __init__(self, max_steps, coeff, grad_func, ):
7 self.max_steps = max_steps
8 self.coeff = coeff
9 self.grad_func = grad_func
11 def run(self, x0):
12 x = x0
13 for i in range(1, self.max_steps + 1):
14 grad = self.grad_func(x)
15 grad = grad / np.linalg.norm(grad)
16 x_new = x + self.coeff * grad
17 if np.linalg.norm(x_new - x) < 1e-6:
18 break
19 x = x_new
20 return x
23class MyModel(LinearRegression):
24 def __init__(self, weights):
25 self.weights = weights
27 def predict(self, X):
28 return np.dot(X, self.weights.T)