Skip to content

InitializationStrategy

InitializationStrategy

InitializationStrategy(name: str | None = None)

Bases: StrategyBase, ABC

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

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() -> Self

Deterministic greedy initialization. Selects vectors one-by-one, always picking the one that maximizes separation from the current selection. Fast but seed-independent.

random_one_shot classmethod

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

Random initialization that selects all k vectors in a single batch, with probabilities biased by global separation (unless uniform=True).

Parameters:

Name Type Description Default
uniform bool

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

False
ignore_constraints bool

If True, ignore constraints during sampling.

False

random_batched classmethod

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

Random initialization that selects vectors in batches of b, re-evaluating separations between batches.

Parameters:

Name Type Description Default
b int

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

required
ignore_constraints bool

If True, ignore constraints during sampling.

False

eager classmethod

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

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