iaode 0.2.6__tar.gz → 0.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {iaode-0.2.6/iaode.egg-info → iaode-0.2.8}/PKG-INFO +1 -1
- {iaode-0.2.6 → iaode-0.2.8}/iaode/__init__.py +1 -1
- {iaode-0.2.6 → iaode-0.2.8}/iaode/agent.py +95 -62
- {iaode-0.2.6 → iaode-0.2.8/iaode.egg-info}/PKG-INFO +1 -1
- {iaode-0.2.6 → iaode-0.2.8}/pyproject.toml +1 -1
- {iaode-0.2.6 → iaode-0.2.8}/LICENSE +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/MANIFEST.in +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/README.md +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/BEN.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/DRE.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/LSE.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/annotation.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/datasets.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/environment.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/mixin.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/model.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/module.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode/utils.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode.egg-info/SOURCES.txt +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode.egg-info/dependency_links.txt +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode.egg-info/requires.txt +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/iaode.egg-info/top_level.txt +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/requirements.txt +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/setup.cfg +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/setup.py +0 -0
- {iaode-0.2.6 → iaode-0.2.8}/tests/test_smoke.py +0 -0
|
@@ -5,7 +5,7 @@ import scanpy as sc # type: ignore
|
|
|
5
5
|
from anndata import AnnData # type: ignore
|
|
6
6
|
import numpy as np
|
|
7
7
|
import torch
|
|
8
|
-
import tqdm
|
|
8
|
+
from tqdm.auto import tqdm # type: ignore
|
|
9
9
|
import time
|
|
10
10
|
from typing import Literal, Optional
|
|
11
11
|
from scipy.stats import norm # type: ignore
|
|
@@ -183,80 +183,113 @@ class agent(Env):
|
|
|
183
183
|
val_every: int = 5,
|
|
184
184
|
early_stop: bool = True,
|
|
185
185
|
):
|
|
186
|
-
"""Train model with early stopping."""
|
|
186
|
+
"""Train model with early stopping and clean progress tracking."""
|
|
187
187
|
|
|
188
|
-
# Initialize resource tracking
|
|
189
188
|
use_cuda = torch.cuda.is_available()
|
|
190
189
|
if use_cuda:
|
|
191
190
|
torch.cuda.reset_peak_memory_stats()
|
|
192
191
|
start_time = time.time()
|
|
193
192
|
|
|
194
|
-
#
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
193
|
+
# Prepare header & separator (but do NOT print yet)
|
|
194
|
+
header = (
|
|
195
|
+
f"{'Epoch':<6} | "
|
|
196
|
+
f"{'Train Loss':<10} | "
|
|
197
|
+
f"{'Val Loss':<10} | "
|
|
198
|
+
f"{'ARI':<6} {'NMI':<6} {'ASW':<6} | "
|
|
199
|
+
f"{'CAL':<6} {'DAV':<6} {'COR':<6} | "
|
|
200
|
+
f"{'Patience':<9}"
|
|
201
|
+
)
|
|
202
|
+
sep_line = "-" * len(header)
|
|
203
|
+
|
|
204
|
+
# Single unified progress bar
|
|
205
|
+
with tqdm(total=epochs, desc="Training", unit="epoch", dynamic_ncols=True) as pbar:
|
|
206
|
+
# Print header via pbar.write so that header & rows stay together
|
|
207
|
+
pbar.write(sep_line)
|
|
208
|
+
pbar.write(header)
|
|
209
|
+
pbar.write(sep_line)
|
|
210
|
+
|
|
211
|
+
for epoch in range(epochs):
|
|
212
|
+
|
|
213
|
+
# 1. Training step
|
|
214
|
+
train_loss = self.train_epoch()
|
|
215
|
+
|
|
216
|
+
# 2. Validation step
|
|
217
|
+
if (epoch + 1) % val_every == 0 or epoch == 0:
|
|
218
|
+
val_loss, val_score = self.validate()
|
|
219
|
+
val_loss = float(val_loss)
|
|
220
|
+
|
|
221
|
+
# val_score indices:
|
|
222
|
+
# 0: ARI, 1: NMI, 2: ASW, 3: CAL, 4: DAV, 5: COR
|
|
223
|
+
ari, nmi, asw, cal, dav, cor = val_score[:6]
|
|
224
|
+
|
|
225
|
+
if early_stop:
|
|
226
|
+
should_stop, _ = self.check_early_stopping(val_loss, patience)
|
|
227
|
+
pat_status = f"{self.patience_counter}/{patience}"
|
|
228
|
+
else:
|
|
229
|
+
should_stop = False
|
|
230
|
+
pat_status = "N/A"
|
|
231
|
+
|
|
232
|
+
# Log line with all 6 metrics
|
|
233
|
+
log_msg = (
|
|
234
|
+
f"{epoch+1:<6} | "
|
|
235
|
+
f"{train_loss:<10.4f} | "
|
|
236
|
+
f"{val_loss:<10.4f} | "
|
|
237
|
+
f"{ari:<6.3f} {nmi:<6.3f} {asw:<6.3f} | "
|
|
238
|
+
f"{cal:<6.3f} {dav:<6.3f} {cor:<6.3f} | "
|
|
239
|
+
f"{pat_status:<9}"
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
# This will appear just above the bar, under the header
|
|
243
|
+
pbar.write(log_msg)
|
|
244
|
+
|
|
245
|
+
# Compact info on the moving bar itself
|
|
246
|
+
postfix = {
|
|
247
|
+
"trn": f"{train_loss:.3f}",
|
|
248
|
+
"val": f"{val_loss:.3f}",
|
|
249
|
+
}
|
|
250
|
+
if early_stop:
|
|
251
|
+
postfix["best"] = f"{self.best_val_loss:.3f}"
|
|
252
|
+
pbar.set_postfix(postfix)
|
|
253
|
+
|
|
254
|
+
if should_stop and early_stop:
|
|
255
|
+
self.actual_epochs = epoch + 1
|
|
256
|
+
pbar.write(f"\n>>> Early stopping triggered at epoch {epoch + 1}")
|
|
257
|
+
break
|
|
258
|
+
|
|
259
|
+
# Update the bar each epoch
|
|
260
|
+
pbar.update(1)
|
|
261
|
+
else:
|
|
262
|
+
self.actual_epochs = epochs
|
|
244
263
|
|
|
245
264
|
# Record resource usage
|
|
246
265
|
self.train_time = time.time() - start_time
|
|
247
266
|
self.peak_memory_gb = torch.cuda.max_memory_allocated() / 1e9 if use_cuda else 0.0
|
|
248
267
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
print(f"{'='*70}")
|
|
252
|
-
print(f" Epochs: {self.actual_epochs}/{epochs}")
|
|
253
|
-
print(f" Time: {self.train_time:.2f}s ({self.train_time/self.actual_epochs:.2f}s/epoch)")
|
|
254
|
-
print(f" Peak GPU Memory: {self.peak_memory_gb:.3f} GB")
|
|
255
|
-
if early_stop:
|
|
256
|
-
print(f" Best Val Loss: {self.best_val_loss:.4f}")
|
|
257
|
-
print(f"{'='*70}\n")
|
|
268
|
+
# Final summary (after bar is closed, plain prints are fine)
|
|
269
|
+
self._print_training_summary(early_stop)
|
|
258
270
|
|
|
259
271
|
return self
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _print_training_summary(self, early_stop: bool):
|
|
275
|
+
"""Helper to print a clean final summary."""
|
|
276
|
+
print(f"\n{'='*60}")
|
|
277
|
+
print(f"{'Training Summary':^60}")
|
|
278
|
+
print(f"{'='*60}")
|
|
279
|
+
|
|
280
|
+
rows = [
|
|
281
|
+
("Total Epochs", f"{self.actual_epochs}"),
|
|
282
|
+
("Total Time", f"{self.train_time:.2f}s"),
|
|
283
|
+
("Time per Epoch", f"{self.train_time/self.actual_epochs:.3f}s"),
|
|
284
|
+
("Peak GPU Memory", f"{self.peak_memory_gb:.3f} GB"),
|
|
285
|
+
]
|
|
286
|
+
if early_stop:
|
|
287
|
+
rows.append(("Best Val Loss", f"{self.best_val_loss:.4f}"))
|
|
288
|
+
|
|
289
|
+
for label, value in rows:
|
|
290
|
+
print(f" {label:<20} : {value}")
|
|
291
|
+
print(f"{'='*60}\n")
|
|
292
|
+
|
|
260
293
|
# ========================================================================
|
|
261
294
|
# Representation Extraction
|
|
262
295
|
# ========================================================================
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|