General-based mathematical functions.

opytimizer.math.general.euclidean_distance(x: numpy.ndarray, y: numpy.ndarray) → float

Calculates the Euclidean distance between two n-dimensional points.

  • x – N-dimensional point.
  • y – N-dimensional point.

Euclidean distance between x and y.

Return type:


opytimizer.math.general.kmeans(x: numpy.ndarray, n_clusters: Optional[int] = 1, max_iterations: Optional[int] = 100, tol: Optional[float] = 0.0001) → numpy.ndarray

Performs the K-Means clustering over the input data.

  • x – Input array with a shape equal to (n_samples, n_variables, n_dimensions).
  • n_clusters – Number of clusters.
  • max_iterations – Maximum number of clustering iterations.
  • tol – Tolerance value to stop the clustering.

An array holding the assigned cluster per input sample.

Return type:


opytimizer.math.general.n_wise(x: List[Any], size: Optional[int] = 2) → Iterable

Iterates over an iterator and returns n-wise samples from it.

  • x (list) – Values to be iterated over.
  • size – Amount of samples per iteration.

N-wise samples from the iterator.

Return type:


opytimizer.math.general.tournament_selection(fitness: List[float], n: int, size: Optional[int] = 2) → numpy.array

Selects n-individuals based on a tournament selection.

  • fitness (list) – List of individuals fitness.
  • n – Number of individuals to be selected.
  • size – Tournament size.

Indexes of selected individuals.

Return type:


opytimizer.math.general.weighted_wheel_selection(weights: List[float]) → int

Selects an individual from a weight-based roulette.

Parameters:weights – List of individuals weights.
Returns:Weight-based roulette individual.
Return type:(int)