opytimizer.math.general¶
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.
Parameters: - x – N-dimensional point.
- y – N-dimensional point.
Returns: Euclidean distance between x and y.
Return type: (float)
-
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.
Parameters: - 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.
Returns: An array holding the assigned cluster per input sample.
Return type: (np.ndarray)
-
opytimizer.math.general.
n_wise
(x: List[Any], size: Optional[int] = 2) → Iterable¶ Iterates over an iterator and returns n-wise samples from it.
Parameters: - x (list) – Values to be iterated over.
- size – Amount of samples per iteration.
Returns: N-wise samples from the iterator.
Return type: (Iterable)
-
opytimizer.math.general.
tournament_selection
(fitness: List[float], n: int, size: Optional[int] = 2) → numpy.array¶ Selects n-individuals based on a tournament selection.
Parameters: - fitness (list) – List of individuals fitness.
- n – Number of individuals to be selected.
- size – Tournament size.
Returns: Indexes of selected individuals.
Return type: (np.array)
-
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)