pydvl.valuation.samplers.classwise
¶
ClasswiseSampler
¶
ClasswiseSampler(
in_class: IndexSampler,
out_of_class: PowersetSampler,
*,
min_elements_per_label: int = 1
)
Bases: IndexSampler
Sample permutations of indices and iterate through each returning increasing subsets, as required for the permutation definition of semi-values.
PARAMETER | DESCRIPTION |
---|---|
in_class |
Sampling scheme for elements of a given label.
TYPE:
|
out_of_class |
Sampling scheme for elements of different labels, i.e., the complement set.
TYPE:
|
min_elements_per_label |
Minimum number of elements per label to sample from the complement set, i.e., out of class elements.
TYPE:
|
Source code in src/pydvl/valuation/samplers/classwise.py
generate_batches
¶
Batches the samples and yields them.
Source code in src/pydvl/valuation/samplers/base.py
interrupt
¶
Interrupts the current sampler as well as the passed in samplers
roundrobin
¶
Taken samples from batch generators in order until all of them are exhausted.
This was heavily inspired by the roundrobin recipe in the official Python documentation for the itertools package.
Examples:
>>> from pydvl.valuation.samplers.classwise import roundrobin
>>> list(roundrobin({"A": "123"}, {"B": "456"}))
[("A", "1"), ("B", "4"), ("A", "2"), ("B", "5"), ("A", "3"), ("B", "6")]
PARAMETER | DESCRIPTION |
---|---|
batch_generators |
dictionary mapping labels to batch generators. |
RETURNS | DESCRIPTION |
---|---|
Generator[tuple[U, V], None, None]
|
Combined generators |
Source code in src/pydvl/valuation/samplers/classwise.py
get_unique_labels
¶
Returns unique labels in a categorical dataset.
PARAMETER | DESCRIPTION |
---|---|
array |
The input array to find unique labels from. It should be of categorical types such as Object, String, Unicode, Unsigned integer, Signed integer, or Boolean.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray
|
An array of unique labels. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input array is not of a categorical type. |