FEDOT icon indicating copy to clipboard operation
FEDOT copied to clipboard

Selection minor refactoring

Open MorrisNein opened this issue 2 years ago • 4 comments

  • 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.

MorrisNein avatar Sep 29 '22 22:09 MorrisNein

Replaced while -> for, as it is significantly faster.

А почему он faster?

nicl-nno avatar Sep 29 '22 22:09 nicl-nno

Codecov Report

Merging #918 (b89185a) into master (530a066) will decrease coverage by 0.02%. The diff coverage is 94.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.

codecov[bot] avatar Sep 29 '22 22:09 codecov[bot]

А почему он faster?

Потому что в случае for инкрементирование и проверка числа итераций в заголовке на самом деле выполняется на C, а в случае while - на Python. Прочие действия в теле цикла примерно уравнивают время выполнения, но разница бывает заметной.

image

MorrisNein avatar Sep 29 '22 23:09 MorrisNein

Ускорил в 10 раз tournament_selection (по сравнению с предыдущей версией с for). Кроме того, при увеличении числа индивидов стабильно воспроизводилась ошибка, когда не удавалось набрать достаточно индивидов по достижении лимита итераций, поскольку раз за разом в выборку попадали лучшие индивиды, которые отсеивались как дубли. Ошибка была заметна при выборке 30 из 40 индивидов и более.

Исправил удалением выбранных индивидов из копии первоначальной выборки (которая теперь уникальный список), а также увеличил численность поколений в тесте tournament_selection.

MorrisNein avatar Oct 02 '22 16:10 MorrisNein