API Reference¶
This page documents the public Python API for the laion_fmri package.
For usage examples and workflows, see the usage guide.
Top-level Functions¶
Configuration¶
Loading Data¶
Discovery¶
Subject¶
Group¶
Exceptions¶
Constants¶
Utilities¶
Train / Test Splits (laion_fmri.splits)¶
The laion_fmri.splits subpackage bundles the predefined
train/test splits used by the re:vision generalization framework.
See Train / Test Splits for the conceptual guide.
- laion_fmri.splits.list_splits() List[str][source]¶
Return the 11 split names available in every pool.
- laion_fmri.splits.list_ood_types() List[str][source]¶
Return the 9 OOD categories present in the
oodsplit.
- laion_fmri.splits.load_split(name: str, pool: str) Split[source]¶
Load one bundled split.
- Parameters:
name (str) – One of the 11 split names (see
list_splits()).pool (str) –
"shared"or a subject id like"sub-01"(seelist_pools()).
- Return type:
- laion_fmri.splits.load_all_splits(pool: str) Dict[str, Split][source]¶
Load every split for
pool→{name: Split}.
- laion_fmri.splits.get_train_test_ids(name: str, pool: str, variant_id: int = 0, ood_types: str | Iterable[str] | None = None) Tuple[List[str], List[str]][source]¶
Convenience: return
(train_ids, test_ids)for one variant.Most splits have a single
variant_id=0. The fiverandom_*and the fivecluster_k5_*splits each ARE the variants — pick the split name;variant_idstays 0.- Parameters:
ood_types (str, list[str], or None) – Only meaningful when
name == "ood". Restricts the test set to image_ids of these OOD categories (seelist_ood_types()).Nonekeeps all 9 categories.
- laion_fmri.splits.get_split_masks(trials, name: str, pool: str, variant_id: int = 0, ood_types: str | Iterable[str] | None = None) Tuple[ndarray, ndarray][source]¶
Build
(train_mask, test_mask)over rows of a trial table.The masks are derived by matching
trials["label"]against the train/test image-id lists of the requested split. They line up one-to-one with the trials passed in, so you can apply them to any trial-aligned array (betas, features, decoded labels, …).- Parameters:
trials (pandas.DataFrame, pandas.Series, np.ndarray or list) – Trial-level labels. If a
DataFrame, the"label"column is used; otherwise the input is treated as label values directly.name (str) – One of the 12 split names (see
list_splits()).pool (str) –
"shared"or a subject id like"sub-01"(seelist_pools()).variant_id (int, default 0) – Variant within the split. Almost always 0.
ood_types (str, list[str], or None) – Only meaningful when
name == "ood". Seeget_train_test_ids().
- Returns:
(train_mask, test_mask) – Boolean arrays, both of length
len(trials).- Return type:
tuple of np.ndarray
Examples
>>> sub = laion_fmri.load_subject("sub-01") >>> trials = pd.concat( ... sub.get_trial_info(session=sub.get_sessions()).values(), ... ignore_index=True, ... ) >>> train_mask, test_mask = get_split_masks( ... trials, "tau", pool="shared", ... ) >>> betas[train_mask], betas[test_mask]