Skip to content

InitializationStrategy

InitializationStrategy

InitializationStrategy(name: str | None = None)

Bases: StrategyBase, ABC

Base class for strategies that produce an initial selection of k items.

Use the factory methods (fast, random_one_shot, random_batched, eager) to create instances.

get_next_samples abstractmethod

get_next_samples(
    state: SolverState, k_remaining: int | int32
) -> NDArray[int32]

Return next batch of samples to be added to the initial selection.

This method is called repeatedly by the Solver, until enough samples have been selected to reach the desired selection size.

Parameters:

Name Type Description Default
state SolverState

(SolverState) The current solver state, to fetch problem size, constraints, distances, etc..., so initial selection can be made in an informed way.

required
k_remaining int | int32

(int) number of samples that remain to be selected.

required

Returns:

Type Description
NDArray[int32]

np.array of unique np.int32 values, shape=(b,), with indices of samples to be added to the selection. b can be any value in range [1, k_remaining]. Samples should be unique and not yet selected.

fast classmethod

fast() -> InitFast

Deterministic greedy initialization.

Selects items one-by-one, always picking the one that maximizes the diversity contribution wrt the current selection. Fast but seed-independent.

random_one_shot classmethod

random_one_shot(
    uniform: bool = False, ignore_constraints: bool = False
) -> InitRandomOneShot

Random initialization that selects all k items in a single batch.

Probabilities are biased by the global diversity contribution (unless uniform=True).

Parameters:

Name Type Description Default
uniform bool

If True, sample uniformly instead of using contribution-based probabilities.

False
ignore_constraints bool

If True, ignore constraints during sampling.

False

random_batched classmethod

random_batched(b: int, ignore_constraints: bool = False) -> InitRandomBatched

Random initialization that selects items in batches of b.

Diversity contributions are re-evaluated between batches.

Parameters:

Name Type Description Default
b int

Batch size (number of items to select per batch).

required
ignore_constraints bool

If True, ignore constraints during sampling.

False

eager classmethod

eager(nc: int, ignore_constraints: bool = False) -> InitEager

Greedy initialization that evaluates nc random candidates per step and picks the best one.

Higher nc gives better quality but is slower.

Parameters:

Name Type Description Default
nc int

Number of candidates to evaluate at each step.

required
ignore_constraints bool

If True, ignore constraints during sampling.

False