Skip to content

pydvl.valuation.methods.delta_shapley

DeltaShapleyValuation

DeltaShapleyValuation(
    utility: UtilityBase,
    is_done: StoppingCriterion,
    lower_bound: int,
    upper_bound: int,
    seed: Seed | None = None,
    progress: bool = False,
)

Bases: SemivalueValuation

Computes \(\delta\)-Shapley values.

\(\delta\)-Shapley does not accept custom samplers. Instead it uses a truncated hierarchical powerset sampler with a lower and upper bound on the size of the sets to sample from.

TODO See ...

Source code in src/pydvl/valuation/methods/delta_shapley.py
def __init__(
    self,
    utility: UtilityBase,
    is_done: StoppingCriterion,
    lower_bound: int,
    upper_bound: int,
    seed: Seed | None = None,
    progress: bool = False,
):
    sampler = TruncatedUniformStratifiedSampler(
        lower_bound=lower_bound, upper_bound=upper_bound, seed=seed
    )
    super().__init__(utility, sampler, is_done, progress=progress)

values

values(sort: bool = False) -> ValuationResult

Returns a copy of the valuation result.

The valuation must have been run with fit() before calling this method.

PARAMETER DESCRIPTION
sort

Whether to sort the valuation result before returning it.

TYPE: bool DEFAULT: False

Returns: The result of the valuation.

Source code in src/pydvl/valuation/base.py
def values(self, sort: bool = False) -> ValuationResult:
    """Returns a copy of the valuation result.

    The valuation must have been run with `fit()` before calling this method.

    Args:
        sort: Whether to sort the valuation result before returning it.
    Returns:
        The result of the valuation.
    """
    if not self.is_fitted:
        raise NotFittedException(type(self))
    assert self.result is not None

    from copy import copy

    r = copy(self.result)
    if sort:
        r.sort()
    return r