Skip to content

pydvl.valuation.methods.random

This module implements a trivial random valuation method.

RandomValuation

RandomValuation(random_state: Seed)

Bases: Valuation

A trivial valuation method that assigns random values to each data point.

Values are in the range [0, 1), as generated by ValuationResult.from_random.

Successive calls to fit() will generate different values.

Source code in src/pydvl/valuation/methods/random.py
def __init__(self, random_state: Seed):
    super().__init__()
    self.random_state = np.random.default_rng(random_state)

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 by value 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 by value 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

fit

fit(train: Dataset) -> Self

Dummy fitting that generates a set of random values.

Successive calls will generate different values.

PARAMETER DESCRIPTION
train

used to determine the size of the valuation result

TYPE: Dataset

Returns: self

Source code in src/pydvl/valuation/methods/random.py
def fit(self, train: Dataset) -> Self:
    """Dummy fitting that generates a set of random values.

    Successive calls will generate different values.

    Args:
        train: used to determine the size of the valuation result
    Returns:
        self
    """
    self.result = ValuationResult.from_random(
        size=len(train), seed=self.random_state
    )
    return self