Coverage for ParTIpy/weights.py: 30%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-16 10:22 +0100

1import numpy as np 

2 

3 

4def compute_bisquare_weights(R: np.ndarray) -> np.ndarray: 

5 """ 

6 Compute the weights using the residuals per data point 

7 :param R: residual vector, with shape (n_samples, n_features) 

8 """ 

9 R_scaled_l1_norm = np.abs(R).sum(axis=1) 

10 c = 6 * np.median(R_scaled_l1_norm) + 1e-9 

11 R_scaled_l1_norm /= c 

12 W = np.zeros_like(R_scaled_l1_norm) 

13 W[R_scaled_l1_norm < 1] = (1 - (R_scaled_l1_norm[R_scaled_l1_norm < 1]) ** 2) ** 2 

14 return W 

15 

16 

17# TODO 

18def compute_huber_weights(R: np.ndarray) -> np.ndarray: 

19 """ 

20 Compute the weights using the residuals per data point 

21 :param R: residual vector, with shape (n_samples, n_features) 

22 """ 

23 raise NotImplementedError()