Skip to content

mix

Dataset wrapper that mixes each sample with a random partner via a pairwise transform.

Classes:

  • MixDataset –

    Draws a second random sample and applies a pairwise mix transform.

MixDataset [source] ΒΆ

MixDataset(
    dataset: Dataset,
    mix: Callable[
        [Dict[str, Any], Dict[str, Any]], Dict[str, Any]
    ],
    transform: Optional[
        Callable[[Dict[str, Any]], Dict[str, Any]]
    ] = None,
    seed: Optional[int] = None,
)

Bases: Dataset, Randomizable

Draws a second random sample and applies a pairwise mix transform.

Each source sample is produced by the wrapped dataset (its own transform runs first), then a partner sample is drawn at a random index and merged via mix(data, other). Pairwise mixes such as Mix3D, LaserMix, and PolarMix fit this contract; the mix's own p decides how often the merge actually happens.

Parameters:

  • dataset (Dataset) –

    The wrapped dataset; its own transform runs per source sample before mixing.

  • mix (Callable[[Dict[str, Any], Dict[str, Any]], Dict[str, Any]]) –

    Pairwise transform called as mix(data, other).

  • transform (Optional[Callable[[Dict[str, Any]], Dict[str, Any]]], default: None ) –

    Optional per-sample transform applied after mixing.

  • seed (Optional[int], default: None ) –

    Seed for the partner index; None draws from the global generator (see Randomizable).

Methods:

  • set_random_state –

    Give the object its own random stream, or return it to the global generator.

set_random_state [source] ΒΆ

set_random_state(
    seed: Optional[int] = None,
    state: Optional[Generator] = None,
) -> Self

Give the object its own random stream, or return it to the global generator.

Parameters:

  • seed (Optional[int], default: None ) –

    Seed of a new generator.

  • state (Optional[Generator], default: None ) –

    Generator to draw from, shared with the caller.

Returns:

  • Self –

    The object itself, for chaining.

Raises:

  • ValueError –

    If both seed and state are given.