porcupy.utils.helpers
Functions
|
Initialize population within the specified bounds. |
|
Clip positions to stay within the specified bounds. |
Module Contents
- porcupy.utils.helpers.initialize_population(pop_size, dim, lb, ub)[source]
Initialize population within the specified bounds.
Generates random positions for the porcupine population using uniform distribution. Supports both single bounds (same for all dimensions) and per-dimension bounds.
- Parameters:
- Returns:
positions – Initialized population of shape (pop_size, dim).
- Return type:
ndarray
- Raises:
ValueError – If pop_size or dim is non-positive, or lb and ub are incompatible.
- porcupy.utils.helpers.clip_to_bounds(positions, lb, ub)[source]
Clip positions to stay within the specified bounds.
Ensures all positions remain within the search space by clipping values that exceed the lower or upper bounds.
- Parameters:
positions (ndarray) – Population positions of shape (pop_size, dim).
lb (ndarray) – Lower bounds for each dimension (or single value).
ub (ndarray) – Upper bounds for each dimension (or single value).
- Returns:
clipped_positions – Positions clipped to stay within bounds.
- Return type:
ndarray