Skip to content

Commit 397ae7e

Browse files
fishidahoclaude
andauthored
Test BiCV under normalize_slices; upgrade dependencies (#560)
* Test BiCV under `normalize_slices` and state its outcome in `pf2` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Upgrade dependencies and raise floors to the versions tested Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Require parafac2 1.9.0, with the `normalize_slices` fix Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d6e48e8 commit 397ae7e

4 files changed

Lines changed: 1206 additions & 826 deletions

File tree

‎pyproject.toml‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ license = "MIT"
77
requires-python = ">= 3.13"
88

99
dependencies = [
10-
"numpy>=2.2",
11-
"scipy>=1.16",
12-
"scikit-learn>=1.6",
10+
"numpy>=2.5",
11+
"scipy>=1.18",
12+
"scikit-learn>=1.9",
1313
"pandas>=3.0.0",
14-
"pyarrow>=19.0",
14+
"pyarrow>=25.0",
1515
"tensorly>=0.9.0",
16-
"parafac2>=1.8.0",
16+
"parafac2>=1.9.0",
1717
"anndata>=0.13",
1818
"pacmap>=0.9",
19-
"tqdm>=4.66.1",
19+
"tqdm>=4.70",
2020
"vsparse>=0.4.0",
21-
"hdf5plugin>=7.0.0",
22-
"matplotlib>=3.8",
21+
"hdf5plugin>=7.1",
22+
"matplotlib>=3.11",
2323
"seaborn>=0.13.2",
2424
"tlviz>=0.1.1",
2525
]
@@ -51,26 +51,26 @@ analysis = [
5151
"scanpy>=1.12",
5252
"tlviz>=0.1.1",
5353
"doubletdetection>=4.3",
54-
"statsmodels>=0.14.1",
55-
"hdf5plugin>=7.0.0",
54+
"statsmodels>=0.15",
55+
"hdf5plugin>=7.1",
5656
]
5757
benchmarking = [
5858
"scanorama>=1.7.4",
59-
"harmonypy>=0.0.10",
59+
"harmonypy>=2.0",
6060
"scib>=1.1.5",
6161
]
6262
docs = [
6363
{ include-group = "analysis" },
6464
"mkdocs>=1.6",
65-
"mkdocs-material>=9.5",
66-
"mkdocstrings[python]>=0.28",
65+
"mkdocs-material>=9.7",
66+
"mkdocstrings[python]>=1.0",
6767
]
6868
dev = [
6969
{ include-group = "analysis" },
70-
"pytest>=9.0",
71-
"pytest-cov>=7.0",
72-
"hypothesis>=6.140",
73-
"ty",
70+
"pytest>=9.1",
71+
"pytest-cov>=7.1",
72+
"hypothesis>=6.168",
73+
"ty>=0.0.83",
7474
"ruff>=0.16",
7575
]
7676

‎scrise/factorization.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ def pf2(
263263
max_iter : int, optional (default: 100)
264264
Maximum number of iterations for the optimization algorithm.
265265
normalize_slices : bool, optional (default: False)
266-
If True, normalizes per-condition slices by their Frobenius norm during
267-
factor updates to prevent conditions with large cell counts from dominating.
266+
If True, weights each condition by the inverse of its Frobenius norm,
267+
so conditions count equally regardless of cell count. Factors and R2X
268+
stay in data units, comparable to an unweighted fit.
268269
backend : str | None, optional (default: None)
269270
Compute backend to run matrix products on: one of ``'mlx'``, ``'cupy'``,
270271
or ``'cpu'``. If None, the first available accelerator is auto-detected

‎scrise/tests/test_rank_selection.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,27 @@ def test_exactly_low_rank_data_scores_near_one_at_its_own_rank():
777777
assert trial["BiCV R2X"] > 0.95
778778

779779

780+
@pytest.mark.parametrize("compress", [None, "auto"])
781+
def test_normalize_slices_scores_near_one_on_exactly_low_rank_data(compress):
782+
"""Slice weighting changes which residuals count, not what the model can
783+
represent, so exactly low-rank data must still fit and predict ~1."""
784+
adata = _exact_low_rank(rank_true=4)
785+
trial = _bicv_trial(
786+
adata,
787+
[4],
788+
0.5,
789+
0.5,
790+
seed=0,
791+
tolerance=1e-8,
792+
max_iter=300,
793+
compress=compress,
794+
parafac2_kwarg={"normalize_slices": True},
795+
)[0]
796+
797+
assert trial["Train Block R2X"] > 0.99
798+
assert trial["BiCV R2X"] > 0.95
799+
800+
780801
@pytest.mark.parametrize("frac", [0.2, 0.35, 0.5, 0.7])
781802
def test_score_barely_moves_with_the_held_out_fraction(frac):
782803
"""`held_out_cell_frac` sets how much is held out, not what the score is.

0 commit comments

Comments
 (0)