Problem Definition

class fevovaq.problem.Problem(n_params: int, obj_function: Callable[[ndarray | cp.ndarray], float | ndarray | cp.ndarray], param_bounds: Tuple | Sequence[Tuple] | None = None, init_range: Tuple | Sequence[Tuple] | None = None, backend: str | None = 'cpu', vectorized: bool = False)[source]

Bases: object

Define a minimization problem for evolutionary optimization.

Supports CPU (NumPy) and GPU (CuPy) backends transparently.

Parameters:
  • n_params – Number of real parameters to be optimized.

  • obj_function – Objective function f(x, **args) -> float or vector. Must accept x of shape (n_params,) or (pop_size, n_params).

  • param_bounds – Tuple or list of (min, max) bounds.

  • init_range – Initialization range (same format as param_bounds). If None, the range (-1, 1) is used.

  • backend – “cpu” or “gpu”.

  • vectorized – If True, obj_function already supports batch input of shape (pop_size, n_params).

check_bounds(params: ndarray | cp.ndarray)[source]

Clip parameters to bounds.

evaluate_fitness(params: ndarray | cp.ndarray)[source]

Evaluate objective function.

Supports: - individual vector: (n_params,) - population vector: (pop_size, n_params)

generate_individual()[source]

Generate a single random individual.

generate_random_pop(pop_size: int)[source]

Generate a random population of individuals.

to_cpu(array: ndarray | cp.ndarray)[source]

Convert to NumPy array.