pavi.data¶
pavi.data.generic
¶
PlateSampler
¶
Bases: Sampler
Sample chunks of plate indices, for mini-batch (stochastic) variational inference.
Each yielded item is a dict mapping plate names to a list of indices, and
indexes one dataset item. Used with
DataLoader(dataset, sampler=sampler, batch_size=sampler.batch_size), a
batch gathers one chunk of every plate; the indices are then passed to the
model and the guide as idx.
Example::
sampler = PlateSampler({"subjects": 4, "vertices": 6}, {"subjects": 2, "vertices": 3}, batch_plates=["subjects"])
next(iter(sampler)) # {'subjects': [0], 'vertices': [0, 1, 2]}
batch_size
property
¶
Return the number of batches in the dataset.
get_stops(full_size, reduced_size, drop_last)
staticmethod
¶
Generate a list of stop indices for dividing a sequence into chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full_size
|
Iterable[int]
|
The total size of the sequence. |
required |
reduced_size
|
int
|
The size of each chunk. |
required |
drop_last
|
bool
|
If True, the last chunk will be dropped if it is smaller than |
required |
Returns:
| Type | Description |
|---|---|
Iterable[int]
|
Iterable[int]: An array of stop indices. |