FEDOT
FEDOT copied to clipboard
Selection minor refactoring
- Replaced
while
->for
, as it is significantly faster. - Moved some conditions out of cycles.
- Made copies of unique elements from the lists to avoid duplicates check.
- Used fast
random.sample()
where it is possible. - Forbade to sample the same element twice during tournament selection - it significantly improved speed and stability.
Replaced while -> for, as it is significantly faster.
А почему он faster?
Codecov Report
Merging #918 (b89185a) into master (530a066) will decrease coverage by
0.02%
. The diff coverage is94.28%
.
@@ Coverage Diff @@
## master #918 +/- ##
==========================================
- Coverage 88.32% 88.29% -0.03%
==========================================
Files 203 203
Lines 13380 13374 -6
==========================================
- Hits 11818 11809 -9
- Misses 1562 1565 +3
Impacted Files | Coverage Δ | |
---|---|---|
...dot/core/optimisers/gp_comp/operators/selection.py | 72.22% <93.93%> (-2.78%) |
:arrow_down: |
...edot/core/optimisers/gp_comp/operators/operator.py | 90.90% <100.00%> (ø) |
|
...on_implementations/models/discriminant_analysis.py | 92.59% <0.00%> (-1.86%) |
:arrow_down: |
...edot/core/optimisers/gp_comp/operators/mutation.py | 93.80% <0.00%> (+0.44%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
А почему он faster?
Потому что в случае for
инкрементирование и проверка числа итераций в заголовке на самом деле выполняется на C, а в случае while
- на Python. Прочие действия в теле цикла примерно уравнивают время выполнения, но разница бывает заметной.
Ускорил в 10 раз tournament_selection
(по сравнению с предыдущей версией с for). Кроме того, при увеличении числа индивидов стабильно воспроизводилась ошибка, когда не удавалось набрать достаточно индивидов по достижении лимита итераций, поскольку раз за разом в выборку попадали лучшие индивиды, которые отсеивались как дубли. Ошибка была заметна при выборке 30 из 40 индивидов и более.
Исправил удалением выбранных индивидов из копии первоначальной выборки (которая теперь уникальный список), а также увеличил численность поколений в тесте tournament_selection
.