diff --git a/chainladder/adjustments/berqsherm.py b/chainladder/adjustments/berqsherm.py index 570ccf5e..33d9e81d 100644 --- a/chainladder/adjustments/berqsherm.py +++ b/chainladder/adjustments/berqsherm.py @@ -179,7 +179,7 @@ def fit(self, X, y=None, sample_weight=None): y0 = xp.log(y.values[..., :-1]) y1 = xp.log(y.values[..., 1:]) b = ((x0 * y0 + x1 * y1) / 2 - (x0 + x1) / 2 * (y0 + y1) / 2) / ( - (x0 ** 2 + x1 ** 2) / 2 - ((x0 + x1) / 2) ** 2 + (x0**2 + x1**2) / 2 - ((x0 + x1) / 2) ** 2 ) a = np.exp((y0 + y1) / 2 - b * (x0 + x1) / 2) @@ -206,27 +206,39 @@ def fit(self, X, y=None, sample_weight=None): # Don't allow lookup values beyond the final value. n = min(lookup.shape[-1], lookup.shape[-2]) for j in range(n - 1): - lookup[:, :, j, :] = np.clip(lookup[:, :, j, :], 0, n - j - 2) + lookup[:, :, j, :] = np.clip(lookup[:, :, j, :], 0, n - j - 2) a = ( - xp.concatenate([ - xp.concatenate( - [a[j:j+1, ..., i, lookup[j, 0, i:i+1, :]] for i in range(lookup.shape[-2])], - axis=-2 - ) - for j in range(a.shape[0]) # Process each batch independently - ], axis=0) - * adj_closed_clm.nan_triangle[None, None, ...] + xp.concatenate( + [ + xp.concatenate( + [ + a[j : j + 1, ..., i, lookup[j, 0, i : i + 1, :]] + for i in range(lookup.shape[-2]) + ], + axis=-2, + ) + for j in range(a.shape[0]) # Process each batch independently + ], + axis=0, + ) + * adj_closed_clm.nan_triangle[None, None, ...] ) b = ( - xp.concatenate([ - xp.concatenate( - [b[j:j+1, ..., i, lookup[j, 0, i:i+1, :]] for i in range(lookup.shape[-2])], - axis=-2 - ) - for j in range(b.shape[0]) # Process each batch independently - ], axis=0) - * adj_closed_clm.nan_triangle[None, None, ...] + xp.concatenate( + [ + xp.concatenate( + [ + b[j : j + 1, ..., i, lookup[j, 0, i : i + 1, :]] + for i in range(lookup.shape[-2]) + ], + axis=-2, + ) + for j in range(b.shape[0]) # Process each batch independently + ], + axis=0, + ) + * adj_closed_clm.nan_triangle[None, None, ...] ) # Adjust paids adj_paid_claims = adj_closed_clm * 0 + xp.exp(adj_closed_clm.values * b) * a @@ -251,7 +263,8 @@ def fit(self, X, y=None, sample_weight=None): return self def transform(self, X): - """ If X and self are of different shapes, align self to X, else + """ + If X and self are of different shapes, align self to X, else return self. Parameters diff --git a/pyproject.toml b/pyproject.toml index 695bca68..0004e8bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,7 +113,6 @@ select = ["E2", "E4", "E7", "E9", "F", "B018", "UP034", "N802"] # check can be required without blocking unrelated PRs. Remove entries as # files are cleaned up. [tool.ruff.lint.per-file-ignores] -"chainladder/adjustments/berqsherm.py" = ["E226", "E241", "E261"] "chainladder/adjustments/bootstrap.py" = ["E231", "E721", "E722", "F841"] "chainladder/adjustments/disposal.py" = ["E226", "E227", "E231", "E251", "E252", "E265", "F401"] "chainladder/adjustments/tests/test_berqsherm.py" = ["F841"]