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_pools() List[str][source]

Return every pool that has bundled splits.

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 ood split.

laion_fmri.splits.load_split(name: str, pool: str) Split[source]

Load one bundled split.

Parameters:
Return type:

Split

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 five random_* and the five cluster_k5_* splits each ARE the variants — pick the split name; variant_id stays 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 (see list_ood_types()). None keeps 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" (see list_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". See get_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]
class laion_fmri.splits.Split(name: str, pool: str, splitter: str, params: Dict, n_train: int, n_test: int, variants: List[SplitVariant] = <factory>)[source]

One named split (e.g. "tau") for one pool (e.g. "sub-01").

property split_family: str

Coarse family.

One of "random", "cluster_k5", "tau", or "ood".

class laion_fmri.splits.SplitVariant(variant_id: int, train_ids: List[str], test_ids: List[str])[source]

A single train/test image-id partition within a Split.