junidude14 commited on
Commit
d415f76
·
verified ·
1 Parent(s): b81ef61

Archive 4 checkpoints (1-4)

Browse files
.gitattributes CHANGED
@@ -80,3 +80,4 @@ paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsem
80
  paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/ye2026_sepsis/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
81
  paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pdf filter=lfs diff=lfs merge=lfs -text
82
  paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pptx filter=lfs diff=lfs merge=lfs -text
 
 
80
  paper-releases/pbisc-diffusion/updates/20261002T022002Z-deck-time-to-apply-scsemi-reps/diffusion/dataset/server_1/model8/plans/paired_finetune_intradataset_20260927/scsemi/work/ye2026_sepsis/fewshot_n5/draw0/scsemi_project/processed_bulkdata.h5ad filter=lfs diff=lfs merge=lfs -text
81
  paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pdf filter=lfs diff=lfs merge=lfs -text
82
  paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/PBISC-Diffusion_paper_summary_20260930.pptx filter=lfs diff=lfs merge=lfs -text
83
+ paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/figures/sec01_slide_a.pdf filter=lfs diff=lfs merge=lfs -text
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/figures/sec01_fig1a_denoiser.pdf ADDED
Binary file (35.4 kB). View file
 
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/figures/sec01_slide_a.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:491e541148abdb06be8fe765d86eaac15cc956f267101004d1e9f698ecd01c6f
3
+ size 567053
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/figures/sec04_metrics_overview.pdf ADDED
Binary file (56 kB). View file
 
paper-releases/pbisc-diffusion/updates/20261002T085943Z-deck-restructure-contrast-metrics-zeroshot-len/diffusion/dataset/server_1/model8/presentations/2026-09-30--paper-summary--r00/tools/sec09_scsemi_representative.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Section 9 slide of the 2026-09-30 paper-summary deck: scSemiProfiler's composition follows its representative.
3
+
4
+ CPU only. Reads plans/paired_finetune_intradataset_20260927/scsemi/analysis/representative_dependence_20261002/
5
+ {per_target.csv, summary.csv, kmeans_proxy.csv} (made by scsemi/tools/representative_dependence.py; rerun that first)
6
+ and draws:
7
+ a composition L1 per cohort: copying the representative's observed composition, scSemiProfiler-5, LoRA-5
8
+ (bar = mean over 5 draws of the per-draw mean, whiskers = SD, dots = draws)
9
+ b Spearman, over test samples, of each method's L1 with the copy error
10
+ The KMeans proxy (upstream's own representative choice, not a rerun) goes to the speaker notes only.
11
+
12
+ Outputs (deck folder; DECK_FIGDIR / DECK_OUTDATA override the folders):
13
+ figures/sec09_scsemi_representative.{png,pdf}
14
+ data/sec09_scsemi_representative.csv every plotted value with its source
15
+ data/sec09_scsemi_representative_slide_text.json title, keywords, footnotes, quoted numbers (synced by
16
+ tools/sync_sec09_text.py through text_source)
17
+ """
18
+ from __future__ import annotations
19
+
20
+ import os
21
+
22
+ os.environ["CUDA_VISIBLE_DEVICES"] = "" # plotting only
23
+
24
+ import json
25
+ import sys
26
+ from pathlib import Path
27
+
28
+ import numpy as np
29
+ import pandas as pd
30
+
31
+ DECK = Path("/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/presentations/"
32
+ "2026-09-30--paper-summary--r00")
33
+ sys.path.insert(0, str(DECK / "tools"))
34
+ import sec09_paired_validation as S9 # noqa: E402 (shared section 9 names and colours; sets the deck rcParams)
35
+ import style # noqa: E402
36
+ import matplotlib.pyplot as plt # noqa: E402
37
+ from matplotlib.patches import Patch # noqa: E402
38
+
39
+ A = S9.T / "scsemi" / "analysis" / "representative_dependence_20261002"
40
+ FIGDIR = Path(os.environ.get("DECK_FIGDIR", str(DECK / "figures")))
41
+ OUTDATA = Path(os.environ.get("DECK_OUTDATA", str(DECK / "data")))
42
+ ORDER, NAME, ROWNAME = S9.ORDER, S9.NAME, S9.ROWNAME
43
+ FS, SUB, EDGE = S9.FS, S9.SUB, S9.EDGE
44
+ ARMS = [("copy", "copy_l1", style.ARM["broadcast"], "Copy the representative's composition"),
45
+ ("scsemi", "scsemi_l1", style.ARM["scsemi"], "scSemiProfiler, 5 donors"),
46
+ ("lora", "lora_l1", style.ARM["lora"], "LoRA, 5 donors")]
47
+
48
+
49
+ def main() -> int:
50
+ per = pd.read_csv(A / "per_target.csv")
51
+ summ = pd.read_csv(A / "summary.csv").set_index("cohort")
52
+ prox = pd.read_csv(A / "kmeans_proxy.csv").set_index("cohort")
53
+ by_draw = per.groupby(["cohort", "draw"])[[c for _, c, _, _ in ARMS]].mean()
54
+ # the plotted pooled means must equal the analysis summary
55
+ for ds in ORDER:
56
+ for _, c, _, _ in ARMS:
57
+ if not np.isclose(per[per.cohort == ds][c].mean(), summ.loc[ds, c]):
58
+ raise SystemExit(f"{ds} {c}: per_target and summary disagree")
59
+ fig, (ax, bx) = plt.subplots(1, 2, figsize=(12.3, 4.6), gridspec_kw={"width_ratios": [2.0, 1.0], "wspace": 0.12})
60
+ h, gap = 0.27, 0.4
61
+ yt, rows = [], []
62
+ for i, ds in enumerate(ORDER):
63
+ y0 = i * (3 * h + gap)
64
+ for k, (key, col, colour, lab) in enumerate(ARMS):
65
+ v = by_draw.loc[ds][col].to_numpy()
66
+ y = y0 + k * h
67
+ ax.barh(y, v.mean(), h * 0.88, color=colour, edgecolor="none")
68
+ ax.errorbar(v.mean(), y, xerr=v.std(ddof=1), fmt="none", ecolor=EDGE, elinewidth=1, capsize=2.5)
69
+ ax.scatter(v, np.full(v.size, y), s=12, facecolor="white", edgecolor=EDGE, linewidth=0.8, zorder=3)
70
+ rows += [dict(panel="a", cohort=ds, series=key, draw=j, value=float(x),
71
+ source=str(A / "per_target.csv")) for j, x in enumerate(v)]
72
+ yt.append(y0 + h)
73
+ p = summ.loc[ds, "scsemi_vs_copy_wilcoxon_p"]
74
+ diff = summ.loc[ds, "scsemi_minus_copy"]
75
+ verdict = "worse" if (p < 0.05 and diff > 0) else ("better" if (p < 0.05 and diff < 0) else "no difference")
76
+ ax.text(0.79, y0 + h, f"scSemi vs copy:\n{verdict}", va="center", ha="left", fontsize=FS - 3, color=SUB,
77
+ linespacing=1.1)
78
+ nt = per.groupby(["cohort", "draw"]).size().groupby(level=0).agg(["min", "max"])
79
+ ax.set_yticks(yt, [f"{ROWNAME[d]}\ntest {nt.loc[d, 'min']}" + (f"–{nt.loc[d, 'max']}" if nt.loc[d, 'max'] != nt.loc[d, 'min'] else "")
80
+ + " per draw" for d in ORDER], fontsize=FS - 2)
81
+ ax.invert_yaxis()
82
+ ax.set_xlim(0, 1.02)
83
+ ax.set_xticks([0, 0.2, 0.4, 0.6])
84
+ ax.set_xlabel("Composition L1 ↓")
85
+ ax.tick_params(axis="y", length=0)
86
+ for i, ds in enumerate(ORDER):
87
+ y0 = i * (3 * h + gap)
88
+ for k, (key, col) in enumerate((("scsemi", "rho_scsemi_copy"), ("lora", "rho_lora_copy"))):
89
+ v = summ.loc[ds, col]
90
+ colour = style.ARM[key]
91
+ bx.barh(y0 + (k + 1) * h, v, h * 0.88, color=colour, edgecolor="none")
92
+ bx.text(v + 0.02, y0 + (k + 1) * h, f"{v:.2f}", va="center", fontsize=FS - 3, color=SUB)
93
+ rows.append(dict(panel="b", cohort=ds, series=key, draw=None, value=float(v), source=str(A / "summary.csv")))
94
+ bx.set_yticks(yt, [""] * len(yt))
95
+ bx.tick_params(axis="y", length=0)
96
+ bx.invert_yaxis()
97
+ bx.set_xlim(0, 1.08)
98
+ bx.set_xlabel("Spearman with the copy error")
99
+ fig.legend(handles=[Patch(color=c, label=l) for _, _, c, l in ARMS], loc="lower center", ncol=3,
100
+ bbox_to_anchor=(0.45, -0.08), fontsize=FS - 2, handlelength=1.2, columnspacing=1.6)
101
+ style.save(fig, "sec09_scsemi_representative", FIGDIR)
102
+ OUTDATA.mkdir(exist_ok=True)
103
+ pd.DataFrame(rows).to_csv(OUTDATA / "sec09_scsemi_representative.csv", index=False)
104
+
105
+ s = summ.loc[list(ORDER)]
106
+ worse = [d for d in ORDER if s.loc[d, "scsemi_vs_copy_wilcoxon_p"] < 0.05 and s.loc[d, "scsemi_minus_copy"] > 0]
107
+ better = [d for d in ORDER if s.loc[d, "scsemi_vs_copy_wilcoxon_p"] < 0.05 and s.loc[d, "scsemi_minus_copy"] < 0]
108
+ lora_below = [d for d in ORDER if s.loc[d, "lora_l1"] < s.loc[d, "copy_l1"]]
109
+ kw = [f"scSemi-5 never beats copying its representative: {len(ORDER) - len(better)}/{len(ORDER)}",
110
+ f"Its error tracks the representative's: rho {s.rho_scsemi_copy.min():.2f}–{s.rho_scsemi_copy.max():.2f}",
111
+ f"LoRA-5 below the copy error in {len(lora_below)}/{len(ORDER)} cohorts"]
112
+ numbers = [{"value": f"{NAME[d]}: copy {s.loc[d, 'copy_l1']:.3f}, scSemi-5 {s.loc[d, 'scsemi_l1']:.3f} "
113
+ f"(Wilcoxon vs copy p {s.loc[d, 'scsemi_vs_copy_wilcoxon_p']:.2g}), LoRA-5 {s.loc[d, 'lora_l1']:.3f}; "
114
+ f"rho scSemi {s.loc[d, 'rho_scsemi_copy']:.2f}, LoRA {s.loc[d, 'rho_lora_copy']:.2f}",
115
+ "source": str(A / "summary.csv")} for d in ORDER]
116
+ proxy = "; ".join(f"{NAME[d]} ({int(prox.loc[d, 'n_representative_samples'])} samples) "
117
+ f"ours {prox.loc[d, 'copy_l1_our_draws']:.2f}, KMeans {prox.loc[d, 'copy_l1_kmeans']:.2f}, "
118
+ f"random samples {prox.loc[d, 'copy_l1_random_samples']:.2f}" for d in ORDER)
119
+ numbers.append({"value": "KMeans proxy, copy error: " + proxy, "source": str(A / "kmeans_proxy.csv")})
120
+ full = ("Same 25 five-donor draws. scSemiProfiler gives every test sample exactly one representative, the nearest "
121
+ "training sample in its bulk PCA (assignment.json), and runs its encoder on that representative's cells. "
122
+ "Copy = composition L1 between the test sample's and its representative's observed cells (same frozen "
123
+ "scANVI labels as the scorer). Bars: mean over draws of the per-draw mean; dots = draws. scSemi vs copy: "
124
+ "paired Wilcoxon over test samples (" + ", ".join(f"{NAME[d]} p {s.loc[d, 'scsemi_vs_copy_wilcoxon_p']:.2g}"
125
+ for d in ORDER) + "). "
126
+ "Upstream's own representative choice (KMeans on the same bulk PCA, the sample nearest each centre; proxy, "
127
+ "not a rerun) gives a lower copy error than our 5-donor draws in Imperial, Giroux and Ji, where our draws hold "
128
+ "all visits of 5 donors and KMeans spreads the same number of samples over as many donors; equal or higher "
129
+ "in ImMicro and sepsis. Copy error: " + proxy + ". "
130
+ "Source: plans/paired_finetune_intradataset_20260927/scsemi/analysis/representative_dependence_20261002/.")
131
+ txt = {"title": "scSemiProfiler copies its representative", "layout": "full",
132
+ "figures": [str(FIGDIR / "sec09_scsemi_representative.png")], "keywords": kw,
133
+ "footnote_short": "Copy = composition of the one training sample scSemiProfiler assigns to each test sample.",
134
+ "footnote": full, "numbers": numbers}
135
+ out = {"section": "09-scsemi-representative", "scripts": [str(Path(__file__).resolve())],
136
+ "generated_from": "tools/sec09_scsemi_representative.py (rerun to refresh; do not edit by hand)",
137
+ "slides": [txt]}
138
+ (OUTDATA / "sec09_scsemi_representative_slide_text.json").write_text(json.dumps(out, indent=1, ensure_ascii=False))
139
+ print("\n".join(kw))
140
+ return 0
141
+
142
+
143
+ if __name__ == "__main__":
144
+ sys.exit(main())