best_values


This function determines the best, best id, worst particle and worst id. It also determines the average value (OF and FIT) of the population.

best_values(x_pop, of_pop, fit_pop)

Input variables

</table> Output variables {: .label .label-yellow }
Name Description Type
x_pop Population design variables List
of_pop Population objective function values List
fit_pop Population fitness values List
Name Description Type
best_id Best id in population Integer
worst_id Worst id in population Integer
x_best Best design variables in population List
x_worst Worst design variables in population List
of_best Best objective function value in population Float
of_worst Worst objective function value in population Float
fit_best Best fitness value in population Float
fit_worst Worst fitness value in population Float
of_avg Average objective function value Float
fit_avg Average fitness value Float
Example 1 {: .label .label-blue } Use the `best_values` function to find the best and worst values in the pop array: $\mathbf{x}_0 = \left[1,\;2,\;3\right]$, $of_0 = 10$ and $fit_0 = 0.09$ $\mathbf{x}_1 = \left[4,\;5,\;6\right]$, $of_1 = 5$ and $fit_1 = 0.17$ $\mathbf{x}_2 = \left[7,\;8,\;9\right]$, $of_2 = 8$ and $fit_2 = 0.11$ ```python # Import # pip install metapy-toolbox or pip install --upgrade metapy-toolbox from metapy_toolbox import best_values # or import * # Data xPop = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ofPop = [10, 5, 8] fitPop = [0.09, 0.17, 0.11] # Call function bestPos, worstPos, xBest, xWorst, ofBest, ofWorst, fitBest, fitWorst, \ ofAverage, fitAverage = best_values(xPop, ofPop, fitPop) # Output details print("Best position in the population:", bestPos) print("Worst position in the population:", worstPos) print("Best value of X:", xBest) print("Worst value of X:", xWorst) print("Best OF:", ofBest) print("Worst OF:", ofWorst) print("Best FIT:", fitBest) print("Worst FIT:", fitWorst) print("Average OF:", ofAverage) print("Average FIT:", fitAverage) ``` ```bash Best position in the population: 1 Worst position in the population: 0 Best value of X: [4, 5, 6] Worst value of X: [1, 2, 3] Best OF: 5 Worst OF: 10 Best FIT: 0.17 Worst FIT: 0.09 Average OF: 7.666666666666667 Average FIT: 0.12333333333333334 ```