scvi.external.contrastivevi.ContrastiveDataLoader#

class scvi.external.contrastivevi.ContrastiveDataLoader(adata_manager, background_indices, target_indices, shuffle=False, batch_size=128, data_and_attributes=None, drop_last=False, distributed_sampler=False, load_sparse_tensor=False, **data_loader_kwargs)[source]#

Bases: ConcatDataLoader

Dataloader to load background and target data for contrastive analysis.

Each iteration of the dataloader returns a dictionary containing background and target data points, indexed by “background” and “target”, respectively.

Parameters:
  • adata_manager (AnnDataManager) – AnnDataManager object that has been created via setup_anndata.

  • background_indices (list[int]) – Indices for background samples in the adata.

  • target_indices (list[int]) – Indices for target samples in the adata.

  • shuffle (bool (default: False)) – Whether the data should be shuffled.

  • batch_size (int (default: 128)) – Mini-batch size to load for background and target data.

  • data_and_attributes (dict | None (default: None)) – Dictionary with keys representing keys in data registry (adata_manager.data_registry) and value equal to desired numpy loading type (later made into torch tensor). If None, defaults to all registered data.

  • drop_last (bool | int (default: False)) – If int, drops the last batch if its length is less than drop_last. If drop_last == True, drops last non-full batch. If drop_last == False, iterate over all batches.

  • distributed_sampler (bool (default: False)) – EXPERIMENTAL Whether to use BatchDistributedSampler as the sampler. If True, sampler must be None. Not applicable here.

  • load_sparse_tensor (bool (default: False)) – EXPERIMENTAL If True, loads data with sparse CSR or CSC layout as a Tensor with the same layout. Can lead to speedups in data transfers to GPUs, depending on the sparsity of the data. Not applicable here.

  • **data_loader_kwargs (Keyword arguments for torch.utils.data.DataLoader.)

Attributes table#

Methods table#

Attributes#

ContrastiveDataLoader.dataset: Dataset[_T_co]#
ContrastiveDataLoader.batch_size: int | None#
ContrastiveDataLoader.num_workers: int#
ContrastiveDataLoader.pin_memory: bool#
ContrastiveDataLoader.drop_last: bool#
ContrastiveDataLoader.timeout: float#
ContrastiveDataLoader.sampler: Sampler | Iterable#
ContrastiveDataLoader.pin_memory_device: str#
ContrastiveDataLoader.prefetch_factor: int | None#

Methods#