metaheuristic_designer.operators.operator_functions.utils module#
- dummy_op(population_matrix, fitness_array, rng=None, f=0)[source]#
Return a matrix of constant value f with the same shape as the input.
This operator is intended only for debugging and testing. It ignores the population contents and produces an array where every gene equals f.
- Return type:
ndarray- Parameters:
- population_matrixnp.ndarray
2-D array of shape
(N, M)(ignored, but its shape is used).- _fitness_arraynp.ndarray
Fitness values (unused, kept for interface compatibility).
- rngnp.random.Generator, optional
Random number generator (unused).
- fScalarLike, optional
Value to fill the array with. Default is
0.
- Returns:
- np.ndarray
A
(N, M)array filled with the constant f.
- Parameters:
population_matrix (ndarray)
fitness_array (ndarray)
rng (Generator | None)
f (number | float | int)
- add_const(population_matrix, fitness_array, rng=None, f=0)[source]#
Add a constant (or vector) to every gene of the population.
Useful as a trivial baseline operator: it simply returns
population_matrix + f, where f can be a scalar (added to all genes) or a vector (added per gene).- Return type:
ndarray- Parameters:
- population_matrixnp.ndarray
2-D array of shape
(N, M).- fitness_arraynp.ndarray
Fitness values (unused).
- rngnp.random.Generator, optional
Random number generator (unused).
- fVectorLike or ScalarLike, optional
Value(s) to add. A scalar is broadcast to every gene; a 1-D array of length M is added per gene. Default is
0.
- Returns:
- np.ndarray
population_matrix + f.
- Parameters:
population_matrix (ndarray)
fitness_array (ndarray)
rng (Generator | None)
f (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | number | float | int)
- class OperatorFnDef(operator_fn, params=<factory>, forced_params=<factory>)[source]#
Bases:
objectBridge a matrix-to-matrix operator function into an
Operator.This wrapper accepts a callable that operates on a genotype matrix, fitness array, and random state, and turns it into an object that can be used directly on a
Population. It merges user-supplied keyword arguments with stored defaults and forced parameters, then invokes the underlying function and updates the population’s genotype.- Parameters:
- operator_fncallable
Function with signature
(population_matrix, fitness_array, rng, **kwargs) -> np.ndarray.- paramsdict, optional
Default keyword arguments for the operator.
- forced_paramsdict, optional
Keyword arguments that always override user-supplied ones.
- Parameters:
operator_fn (callable)
params (dict)
forced_params (dict)
Methods
__call__(population[, rng])Execute the wrapped operator and return a new population.
-
operator_fn:
callable#
-
params:
dict#
-
forced_params:
dict#
- class OperatorRandomDef(operator_fn, params=<factory>, forced_params=<factory>)[source]#
Bases:
objectBridge a random-style operator function into an
Operator.This wrapper is intended for operators that replace the genotype with entirely new random values (e.g., uniform sampling, initializer-based reset). It passes the population’s genotype matrix, the initializer, and the random state to the underlying function.
- Parameters:
- operator_fncallable
Function with signature
(population_matrix, initializer, rng, **kwargs) -> np.ndarray.- paramsdict, optional
Default keyword arguments.
- forced_paramsdict, optional
Keyword arguments that override any user-supplied ones.
- Parameters:
operator_fn (callable)
params (dict)
forced_params (dict)
Methods
__call__(population, initializer[, rng])Execute the random operator and return a new population.
-
operator_fn:
callable#
-
params:
dict#
-
forced_params:
dict#
- class ObtainStatisticDef(operator_fn, params=<factory>, forced_params=<factory>)[source]#
Bases:
objectWrap a statistic‑computing function into an
Operator.This adapter is used for functions that compute a single summary vector (e.g., population mean, median, standard deviation) and store it as the new genotype (usually a single-row population).
- Parameters:
- operator_fncallable
Function with signature
(population_matrix, rng, **kwargs) -> np.ndarray.- paramsdict, optional
Default keyword arguments.
- forced_paramsdict, optional
Keyword arguments that override user-supplied ones.
- Parameters:
operator_fn (callable)
params (dict)
forced_params (dict)
Methods
__call__(population[, rng])Compute a statistic and replace the population’s genotype.
-
operator_fn:
callable#
-
params:
dict#
-
forced_params:
dict#
- class OperatorSwarmDef(operator_fn, params=<factory>, forced_params=<factory>)[source]#
Bases:
objectBridge a swarm operator function into an
Operator.This wrapper is designed for operators that directly receive the whole
Populationobject and the initializer, and are responsible for returning an updatedPopulationthemselves (e.g., PSO operators that need access to historical bests).- Parameters:
- operator_fncallable
Function with signature
(population, initializer, rng, **kwargs) -> Population.- paramsdict, optional
Default keyword arguments.
- forced_paramsdict, optional
Keyword arguments that override user-supplied ones.
- Parameters:
operator_fn (callable)
params (dict)
forced_params (dict)
Methods
__call__(population, rng, **kwargs)Execute the swarm operator and return the new population.
-
operator_fn:
callable#
-
params:
dict#
-
forced_params:
dict#