review-response: upload src/pino/upload_data.py
Browse files- src/pino/upload_data.py +11 -1
src/pino/upload_data.py
CHANGED
|
@@ -328,6 +328,10 @@ def create_hub_excluded_component_split_from_records(
|
|
| 328 |
|
| 329 |
target_val = max(1, int(round(len(data_indices) * (1.0 - train_ratio))))
|
| 330 |
rng = random.Random(seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
component_items = [
|
| 332 |
(rng.random(), comp_id, idxs)
|
| 333 |
for comp_id, idxs in component_to_indices.items()
|
|
@@ -336,9 +340,15 @@ def create_hub_excluded_component_split_from_records(
|
|
| 336 |
val_components: set[int] = set()
|
| 337 |
val_count = 0
|
| 338 |
for _tie, comp_id, idxs in component_items:
|
| 339 |
-
if
|
| 340 |
val_components.add(comp_id)
|
| 341 |
val_count += len(idxs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
validation_indices = sorted(
|
| 344 |
idx for comp_id in val_components for idx in component_to_indices[comp_id]
|
|
|
|
| 328 |
|
| 329 |
target_val = max(1, int(round(len(data_indices) * (1.0 - train_ratio))))
|
| 330 |
rng = random.Random(seed)
|
| 331 |
+
# Deterministic greedy assignment: walk components smallest-first (ties broken by
|
| 332 |
+
# the seeded RNG) and add a component to validation only while doing so does not
|
| 333 |
+
# overshoot the target. This avoids forcing an oversized first component into val
|
| 334 |
+
# and keeps the split reproducible for a given seed.
|
| 335 |
component_items = [
|
| 336 |
(rng.random(), comp_id, idxs)
|
| 337 |
for comp_id, idxs in component_to_indices.items()
|
|
|
|
| 340 |
val_components: set[int] = set()
|
| 341 |
val_count = 0
|
| 342 |
for _tie, comp_id, idxs in component_items:
|
| 343 |
+
if val_count < target_val and val_count + len(idxs) <= target_val:
|
| 344 |
val_components.add(comp_id)
|
| 345 |
val_count += len(idxs)
|
| 346 |
+
# Fallback: if nothing fit under the target (tiny/fragmented graph), take the
|
| 347 |
+
# single smallest component so validation is non-empty.
|
| 348 |
+
if not val_components and component_items:
|
| 349 |
+
_tie, comp_id, idxs = component_items[0]
|
| 350 |
+
val_components.add(comp_id)
|
| 351 |
+
val_count += len(idxs)
|
| 352 |
|
| 353 |
validation_indices = sorted(
|
| 354 |
idx for comp_id in val_components for idx in component_to_indices[comp_id]
|