\doxysection{evolve\+\_\+optimizer.\+h} \hypertarget{evolve__optimizer_8h_source}{}\label{evolve__optimizer_8h_source}\index{E:/.WORK/STM32/STM32\_ExtendedLibs/MyLibsGeneral/Inc/evolve\_optimizer.h@{E:/.WORK/STM32/STM32\_ExtendedLibs/MyLibsGeneral/Inc/evolve\_optimizer.h}} \mbox{\hyperlink{evolve__optimizer_8h}{Go to the documentation of this file.}} \begin{DoxyCode}{0} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00001}00001\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00002}00002\ \textcolor{comment}{******************************************************************************}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00003}00003\ \textcolor{comment}{*\ @file\ evolve\_optimizer.h}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00004}00004\ \textcolor{comment}{*\ @brief\ Заголовочный\ файл\ для\ адаптивного\ подбора\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00005}00005\ \textcolor{comment}{******************************************************************************}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00006}00006\ \textcolor{comment}{*\ @addtogroup\ EVOLVE\_OPTIMIZER\ \ \ \ Evolve\ optimizer}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00007}00007\ \textcolor{comment}{*\ @ingroup\ \ \ \ MYLIBS\_DEFINES}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00008}00008\ \textcolor{comment}{*\ @brief\ \ \ \ \ \ Библиотека\ для\ эволюционного\ подбора\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00009}00009\ \textcolor{comment}{*\ @details}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00010}00010\ \textcolor{comment}{Поддерживает:}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00011}00011\ \textcolor{comment}{-\/\ Любое\ количество\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00012}00012\ \textcolor{comment}{-\/\ Генерацию\ новых\ параметров\ на\ основе\ лучших\ кандидатов}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00013}00013\ \textcolor{comment}{-\/\ Мутацию\ для\ поиска\ оптимальных\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00014}00014\ \textcolor{comment}{-\/\ Несколько\ независимых\ оптимизаторов\ в\ одной\ программе}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00015}00015\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00016}00016\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00017}00017\ \textcolor{comment}{Параметры\ для\ конфигурации:}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00018}00018\ \textcolor{comment}{-\/\ @ref\ ENABLE\_EVOLVE\_OPTIMIZATION\ -\/\ Включить\ оптимизацию\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00019}00019\ \textcolor{comment}{\ \ Если\ библиотека\ отключена\ @ref\ ENABLE\_EVOLVE\_OPTIMIZATION,\ то\ вставляются\ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00020}00020\ \textcolor{comment}{\ \ заглушки,\ никак\ не\ влияющие\ на\ параметры\ и\ остальную\ программу}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00021}00021\ \textcolor{comment}{-\/\ @ref\ EVOLVE\_MAX\_PARAMS\ \ \ \ \ \ \ \ \ \ -\/\ Максимальное\ количество\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00022}00022\ \textcolor{comment}{-\/\ @ref\ EVOLVE\_MAX\_CANDIDATES\ \ \ \ \ \ -\/\ Максимальное\ количество\ кандидатов\ для\ обучения}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00023}00023\ \textcolor{comment}{-\/\ (опционально)\ @ref\ EVOLVE\_MUTATION\_MIN\_PCT\ \ \ \ -\/\ Минимальная\ мутация\ в\ процентах\ от\ Loss\ (по\ умолчанию\ 10\%)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00024}00024\ \textcolor{comment}{-\/\ (опционально)\ @ref\ EVOLVE\_MUTATION\_MAX\_PCT\ \ \ \ -\/\ Максимальная\ мутация\ в\ процентах\ от\ Loss\ (по\ умолчанию\ 100\%)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00025}00025\ \textcolor{comment}{-\/\ (опционально)\ @ref\ ELOVLE\_N\_ELITE\_CANDIDATE\ \ \ -\/\ Количество\ кандидатов,\ которые\ проходят\ в\ поколение\ без\ изменений}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00026}00026\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00027}00027\ \textcolor{comment}{@par\ Пример\ использования:}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00028}00028\ \textcolor{comment}{@code}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00029}00029\ \textcolor{comment}{\#include\ "{}evolve\_optimizer.h"{}}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00030}00030\ \textcolor{comment}{\#define\ N\_PARAMS\ \ \ \ \ \ \ \ 4}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00031}00031\ \textcolor{comment}{\#define\ N\_CANDIDATES\ \ \ \ 100}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00032}00032\ \textcolor{comment}{\#define\ N\_BEST\ \ \ \ \ \ \ \ \ \ 10}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00033}00033\ \textcolor{comment}{\#define\ MUTATION\ \ \ \ \ \ \ \ 0.1f}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00034}00034\ \textcolor{comment}{float\ params[N\_PARAMS];}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00035}00035\ \textcolor{comment}{EvolveOptimizer\_t\ optimizer;}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00036}00036\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00037}00037\ \textcolor{comment}{//\ Формирование\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00038}00038\ \textcolor{comment}{uint16\_t\ \ param\_u16\ =\ 800;}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00039}00039\ \textcolor{comment}{float\ \ \ \ \ param\_f\ \ \ =\ 0.01f;}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00040}00040\ \textcolor{comment}{uint8\_t\ \ \ param\_u8\ \ =\ 40;}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00041}00041\ \textcolor{comment}{int16\_t\ \ \ param\_i16\ =\ 1600;}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00042}00042\ \textcolor{comment}{params[0]\ =\ PARAM\_SCALE(param\_u16,\ \ 0.0f,\ \ \ 1000.0f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00043}00043\ \textcolor{comment}{params[1]\ =\ PARAM\_SCALE(param\_f,\ \ \ \ 0.001f,\ 0.1f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00044}00044\ \textcolor{comment}{params[2]\ =\ PARAM\_SCALE(param\_u8,\ \ \ 10.0f,\ \ 100.0f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00045}00045\ \textcolor{comment}{params[3]\ =\ PARAM\_SCALE(param\_i16,\ \ 500.0f,\ 5000.0f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00046}00046\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00047}00047\ \textcolor{comment}{//\ Инициалиазция}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00048}00048\ \textcolor{comment}{EvolveOptimizer\_Init(\&optimizer,\ N\_PARAMS,\ N\_CANDIDATES,\ N\_BEST,\ MUTATION,\ params);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00049}00049\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00050}00050\ \textcolor{comment}{//\ Шаг\ эволюции}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00051}00051\ \textcolor{comment}{float\ loss\ =\ calc\_loss();\ //\ расчет\ эффективности\ параметров\ (от\ 0\ до\ 1)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00052}00052\ \textcolor{comment}{EvolveOptimizer\_Step(\&optimizer,\ params,\ loss);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00053}00053\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00054}00054\ \textcolor{comment}{//\ Взятие\ следующих\ для\ эволюции\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00055}00055\ \textcolor{comment}{param\_u16\ =\ PARAM\_UNSCALE(params[0],\ \ 0.0f,\ \ \ 1000.0f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00056}00056\ \textcolor{comment}{param\_f\ \ \ =\ PARAM\_UNSCALE(params[1],\ \ 0.001f,\ 0.1f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00057}00057\ \textcolor{comment}{param\_u8\ \ =\ PARAM\_UNSCALE(params[2],\ \ 10.0f,\ \ 100.0f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00058}00058\ \textcolor{comment}{param\_i16\ =\ PARAM\_UNSCALE(params[3],\ \ 500.0f,\ 5000.0f);}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00059}00059\ \textcolor{comment}{@endcode}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00060}00060\ \textcolor{comment}{*\ @\{\ \ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00061}00061\ \textcolor{comment}{*****************************************************************************/}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00062}00062\ \textcolor{preprocessor}{\#ifndef\ \_\_EVOLVE\_OPTIMIZER\_H\_}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00063}00063\ \textcolor{preprocessor}{\#define\ \_\_EVOLVE\_OPTIMIZER\_H\_}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00064}00064\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00065}00065\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{mylibs__defs_8h}{mylibs\_defs.h}}"{}}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00066}00066\ \textcolor{preprocessor}{\#include\ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00067}00067\ \textcolor{preprocessor}{\#include\ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00068}00068\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00069}00069\ \textcolor{preprocessor}{\#ifdef\ ENABLE\_EVOLVE\_OPTIMIZATION}\textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00070}00070\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00071}00071\ \textcolor{comment}{\ \ *\ @brief\ Линейное\ масштабирование\ x\ из\ диапазона\ [min\_val,\ max\_val]\ в\ диапазон\ [0,\ 1)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00072}00072\ \textcolor{comment}{\ \ */}\textcolor{preprocessor}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00073}\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga83abbcabaff9111c03ae2475ee72ea3e}{00073}}\ \textcolor{preprocessor}{\#define\ PARAM\_SCALE(x,\ min\_val,\ max\_val)\ \(\backslash\)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00074}00074\ \textcolor{preprocessor}{(((float)(x)\ -\/\ (float)(min\_val))\ /\ ((float)(max\_val)\ -\/\ (float)(min\_val)))}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00075}00075\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00076}00076\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00077}00077\ \textcolor{comment}{\ \ *\ @brief\ Обратное\ линейное\ масштабирование\ значения\ из\ [0,\ 1)\ в\ диапазон\ [min\_val,\ max\_val]}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00078}00078\ \textcolor{comment}{\ \ */}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00079}\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_gaa1d5510fe5f0bd989473f3ebe324bde3}{00079}}\ \textcolor{preprocessor}{\#define\ PARAM\_UNSCALE(val,\ min\_val,\ max\_val)\ \(\backslash\)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00080}00080\ \textcolor{preprocessor}{(((float)(val))\ *\ ((float)(max\_val)\ -\/\ (float)(min\_val))\ +\ (float)(min\_val))}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00081}00081\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00082}00082\ \textcolor{preprocessor}{\#ifndef\ local\_time}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00083}00083\ \textcolor{preprocessor}{\#define\ local\_time()\ \ HAL\_GetTick()\ }\textcolor{comment}{///<\ Локальное\ время}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00084}00084\ \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00085}00085\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00086}00086\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00087}00087\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00088}00088\ \textcolor{preprocessor}{\#ifndef\ EVOLVE\_MUTATION\_MIN\_PCT}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00089}\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga2f2b1be34ad4eb1bf3267237200cd6c6}{00089}}\ \textcolor{preprocessor}{\#define\ EVOLVE\_MUTATION\_MIN\_PCT\ \ \ 10\ \ \ \ }\textcolor{comment}{///<\ Минимальная\ мутация\ (в\ процентах\ от\ Loss)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00090}00090\ \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00091}00091\ \textcolor{preprocessor}{\#ifndef\ EVOLVE\_MUTATION\_MAX\_PCT}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00092}\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga861c1c6a503c21441abcec0d57b848bc}{00092}}\ \textcolor{preprocessor}{\#define\ EVOLVE\_MUTATION\_MAX\_PCT\ \ \ 100\ \ \ }\textcolor{comment}{///<\ Максимальная\ мутация\ (в\ процентах\ от\ Loss)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00093}00093\ \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00094}00094\ \textcolor{preprocessor}{\#ifndef\ ELOVLE\_N\_ELITE\_CANDIDATE}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00095}\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga38607e23d9234524bc7de5869b15b8eb}{00095}}\ \textcolor{preprocessor}{\#define\ ELOVLE\_N\_ELITE\_CANDIDATE\ \ 2\ \ \ \ \ }\textcolor{comment}{///<\ Количество\ кандидатов,\ которые\ проходят\ в\ поколение\ без\ изменений\ (по\ умолчанию\ 2)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00096}00096\ \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00097}00097\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00098}00098\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00099}00099\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00100}00100\ \textcolor{comment}{\ \ *\ @brief\ Структура\ эволюционного\ оптимизатора}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00101}00101\ \textcolor{comment}{\ \ */}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00102}\mbox{\hyperlink{struct_evolve_optimizer__t}{00102}}\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00103}\mbox{\hyperlink{struct_evolve_optimizer__t_a80eb0b8525b6bb838484f5922b9d8f7c}{00103}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_evolve_optimizer__t_a80eb0b8525b6bb838484f5922b9d8f7c}{stability}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Коэффициент\ насколько\ стабильная\ популяция\ (0..1)(@ref\ n\_cand)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00104}00104\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00105}\mbox{\hyperlink{struct_evolve_optimizer__t_a1c270fce82e0c97e6c88fd0971c1eed8}{00105}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_evolve_optimizer__t_a1c270fce82e0c97e6c88fd0971c1eed8}{n\_params}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Количество\ параметров}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00106}\mbox{\hyperlink{struct_evolve_optimizer__t_ac35c7ca8cede4ab9c53a2845a91cd1b1}{00106}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_evolve_optimizer__t_ac35c7ca8cede4ab9c53a2845a91cd1b1}{n\_cand}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Количество\ кандидатов\ в\ популяции}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00107}\mbox{\hyperlink{struct_evolve_optimizer__t_a950cd70cb6bff33b78ad35ee58c729a6}{00107}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_evolve_optimizer__t_a950cd70cb6bff33b78ad35ee58c729a6}{n\_best}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Количество\ лучших,\ усредняемых}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00108}\mbox{\hyperlink{struct_evolve_optimizer__t_af779c7aeba0053e36cee7aade160f1c8}{00108}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_evolve_optimizer__t_af779c7aeba0053e36cee7aade160f1c8}{mutation\_amp}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Амплитуда\ мутации\ (0..1)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00109}00109\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00110}\mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{00110}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{cand\_index}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Индекс\ кандидата\ для\ обработки}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00111}\mbox{\hyperlink{struct_evolve_optimizer__t_ad0f464d7048a9ed0753b61f76f563108}{00111}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_evolve_optimizer__t_ad0f464d7048a9ed0753b61f76f563108}{gen\_index}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Индекс\ популяции\ \ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00112}00112\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00113}00113\ \ \ \textcolor{comment}{//INTERNAL}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00114}\mbox{\hyperlink{struct_evolve_optimizer__t_a3be8c0c34db8429210ff470497a56727}{00114}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_evolve_optimizer__t_a3be8c0c34db8429210ff470497a56727}{gen\_mut}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Амплитуда\ мутации\ у\ текущей\ популяции\ \ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00115}00115\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00116}\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{00116}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[\mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga7c1396e5c95c766afccdb45cbfcf5971}{EVOLVE\_MAX\_CANDIDATES}}];\ \ \ \ \textcolor{comment}{///<\ Loss\ для\ каждого\ кандидата}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00117}\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{00117}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[\mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga7c1396e5c95c766afccdb45cbfcf5971}{EVOLVE\_MAX\_CANDIDATES}}][\mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga80d6162495fc3776d8902610657d4fee}{EVOLVE\_MAX\_PARAMS}}];\ \textcolor{comment}{///<\ Параметры\ кандидатов}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00118}\mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{00118}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{sorted\_idx}}[\mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga7c1396e5c95c766afccdb45cbfcf5971}{EVOLVE\_MAX\_CANDIDATES}}];\ \textcolor{comment}{///<\ Индексы\ отсортированных\ кандидатов}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00119}00119\ \}\ \mbox{\hyperlink{struct_evolve_optimizer__t}{EvolveOptimizer\_t}};} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00120}00120\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00121}00121\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00122}00122\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00123}00123\ \textcolor{comment}{/**\ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00124}00124\ \textcolor{comment}{\ *\ @cond\ EVOLVE\_INTERNAL}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00125}00125\ \textcolor{comment}{\ */}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00126}00126\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00127}00127\ \textcolor{comment}{//\ Вспомогательный\ указатель\ для\ сортировки}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00128}00128\ \textcolor{keyword}{static}\ \mbox{\hyperlink{struct_evolve_optimizer__t}{EvolveOptimizer\_t}}\ *g\_sort\_opt;\ \textcolor{comment}{//\ глобальный\ указатель\ на\ текущий\ оптимизатор}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00129}00129\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00130}00130\ \textcolor{comment}{//\ функция\ условия\ сортировки}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00131}00131\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ cmp\_idx(\textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *a,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *b)\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00132}00132\ \ \ \textcolor{keywordflow}{if}\ (g\_sort\_opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)a]\ <\ g\_sort\_opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)b])\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00133}00133\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00134}00134\ \ \ \textcolor{keywordflow}{if}\ (g\_sort\_opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)a]\ >\ g\_sort\_opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)b])\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00135}00135\ \ \ \ \ \textcolor{keywordflow}{return}\ 1;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00136}00136\ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00137}00137\ \}\textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00138}00138\ \textcolor{comment}{/**\ @endcond\ */}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00139}00139\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00140}00140\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00141}00141\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00142}00142\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00143}00143\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00144}00144\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00145}00145\ \textcolor{comment}{\ \ *\ @brief\ Инициализация\ эволюционного\ оптимизатора.}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00146}00146\ \textcolor{comment}{\ \ *\ @param\ opt\ \ \ \ \ \ \ \ \ \ Указатель\ на\ структуру\ оптимизатора}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00147}00147\ \textcolor{comment}{\ \ *\ @param\ n\_params\ \ \ \ \ Количество\ параметров\ в\ одном\ кандидате}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00148}00148\ \textcolor{comment}{\ \ *\ @param\ n\_cand\ \ \ \ \ \ \ Количество\ кандидатов}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00149}00149\ \textcolor{comment}{\ \ *\ @param\ n\_best\ \ \ \ \ \ \ Количество\ лучших,\ усредняемых}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00150}00150\ \textcolor{comment}{\ \ *\ @param\ mutation\_amp\ Амплитуда\ мутации\ (в\ диапазоне\ 0.0–1.0)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00151}00151\ \textcolor{comment}{\ \ *\ @param\ start\_params\ Начальные\ параметры\ (в\ диапазоне\ 0.0–1.0)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00152}00152\ \textcolor{comment}{\ \ *\ @return\ 0\ \ \ —\ если\ окей,\ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00153}00153\ \textcolor{comment}{\ \ *\ \ \ \ \ \ \ \ \ -\/1\ \ —\ если\ ошибка}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00154}00154\ \textcolor{comment}{\ \ */}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00155}\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga4e3ea118b5b9068619c57724a925ba21}{00155}}\ \_\_STATIC\_INLINE\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga4e3ea118b5b9068619c57724a925ba21}{EvolveOptimizer\_Init}}(\mbox{\hyperlink{struct_evolve_optimizer__t}{EvolveOptimizer\_t}}*\ opt,} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00156}00156\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ n\_params,} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00157}00157\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ n\_cand,} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00158}00158\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ n\_best,} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00159}00159\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ mutation\_amp,} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00160}00160\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}*\ start\_params)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00161}00161\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00162}00162\ \ \ \textcolor{keywordflow}{if}((opt\ ==\ NULL)\ ||\ (start\_params\ ==\ NULL))} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00163}00163\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00164}00164\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00165}00165\ \ \ \textcolor{keywordflow}{if}(n\_params\ >\ \mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga80d6162495fc3776d8902610657d4fee}{EVOLVE\_MAX\_PARAMS}})} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00166}00166\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00167}00167\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a1c270fce82e0c97e6c88fd0971c1eed8}{n\_params}}\ \ \ \ \ =\ n\_params;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00168}00168\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00169}00169\ \ \ \textcolor{keywordflow}{if}(n\_cand\ >\ \mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga7c1396e5c95c766afccdb45cbfcf5971}{EVOLVE\_MAX\_CANDIDATES}})} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00170}00170\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00171}00171\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_ac35c7ca8cede4ab9c53a2845a91cd1b1}{n\_cand}}\ \ \ \ \ \ \ =\ n\_cand;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00172}00172\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00173}00173\ \ \ \textcolor{keywordflow}{if}(n\_best\ >\ \mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga7c1396e5c95c766afccdb45cbfcf5971}{EVOLVE\_MAX\_CANDIDATES}}/2)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00174}00174\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00175}00175\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a950cd70cb6bff33b78ad35ee58c729a6}{n\_best}}\ \ \ \ \ \ \ =\ n\_best;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00176}00176\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00177}00177\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00178}00178\ \ \ \textcolor{keywordflow}{if}((mutation\_amp\ >\ 1)\ ||\ (mutation\_amp\ <\ 0))} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00179}00179\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00180}00180\ \ \ \textcolor{keywordflow}{if}(mutation\_amp\ <=\ 0.001f)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00181}00181\ \ \ \ \ mutation\_amp\ =\ 0.001f;\ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00182}00182\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_af779c7aeba0053e36cee7aade160f1c8}{mutation\_amp}}\ \ =\ mutation\_amp;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00183}00183\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00184}00184\ \ \ uint32\_t\ seed\ =\ \mbox{\hyperlink{group___l_i_b_s___c_o_n_f_i_g_ga9c853b02c22f26023c34d1d404b6d653}{local\_time}}();} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00185}00185\ \textcolor{preprocessor}{\#ifdef\ ADC1}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00186}00186\ \ \ seed\ +=\ (ADC1-\/>DR\ \&\ 0xFF);} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00187}00187\ \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00188}00188\ \ \ srand(seed);} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00189}00189\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00190}00190\ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_cand;\ i++)\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00191}00191\ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ j\ =\ 0;\ j\ <\ n\_params;\ j++)\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00192}00192\ \ \ \ \ \ \ \textcolor{comment}{//\ Добавляем\ случайную\ мутацию\ вокруг\ стартового\ параметра}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00193}00193\ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ base\ =\ start\_params[j];} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00194}00194\ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ inv\_randmax\ =\ 1.0f\ /\ (float)RAND\_MAX;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00195}00195\ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ noise\ =\ ((float)rand()\ *\ inv\_randmax\ *\ 2.0f\ -\/\ 1.0f)\ *\ mutation\_amp;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00196}00196\ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[i][j]\ =\ base\ +\ noise;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00197}00197\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[i][j]\ <\ 0.0f)\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[i][j]\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00198}00198\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[i][j]\ >\ 1.0f)\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[i][j]\ =\ 1.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00199}00199\ \ \ \ \ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00200}00200\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[i]\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00201}00201\ \ \ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00202}00202\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00203}00203\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{cand\_index}}\ =\ 0;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00204}00204\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_ad0f464d7048a9ed0753b61f76f563108}{gen\_index}}\ =\ 0;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00205}00205\ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00206}00206\ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00207}00207\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00208}00208\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00209}00209\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00210}00210\ \textcolor{comment}{\ \ *\ @brief\ Один\ шаг\ эволюционного\ оптимизатора.}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00211}00211\ \textcolor{comment}{\ \ *\ @param\ opt\ \ \ \ Указатель\ на\ структуру\ оптимизатора}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00212}00212\ \textcolor{comment}{\ \ *\ @param\ params\ Массив\ параметров,\ которые\ будут\ обновлены\ (на\ выходе\ —\ новые\ параметры)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00213}00213\ \textcolor{comment}{\ \ *\ @param\ loss\ \ \ Loss\ текущего\ кандидата}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00214}00214\ \textcolor{comment}{\ \ *\ @return\ 0\ \ \ —\ если\ окей,\ }} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00215}00215\ \textcolor{comment}{\ \ *\ \ \ \ \ \ \ \ \ -\/1\ \ —\ если\ ошибка}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00216}00216\ \textcolor{comment}{\ \ *\ @details}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00217}00217\ \textcolor{comment}{\ \ *\ Сохраняет\ loss\ текущего\ кандидата\ и\ формирует\ параметры\ следующего\ кандидата.}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00218}00218\ \textcolor{comment}{\ \ *\ Если\ накоплено\ n\_cand\ кандидатов,\ генерируется\ новое\ поколение.}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00219}00219\ \textcolor{comment}{\ \ *\ Новое\ поколение\ формируется\ случайным\ выбором\ из\ n\_best\ лучших\ с\ добавлением\ мутации.}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00220}00220\ \textcolor{comment}{\ \ *}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00221}00221\ \textcolor{comment}{\ \ *\ На\ выходе\ params\ содержит\ параметры\ следующего\ кандидата\ для\ измерений.}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00222}00222\ \textcolor{comment}{\ \ *\ @note\ Функция\ использует\ глобальную\ внутреннюю\ переменную\ для\ сортировки.}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00223}00223\ \textcolor{comment}{\ \ *\ Надо\ убедится\ что\ только\ один\ экземпляр\ функции\ запущен\ в\ момент\ времени}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00224}00224\ \textcolor{comment}{\ \ */}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00225}\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_gaef44a1f3298514569cc2b396a92101ef}{00225}}\ \_\_STATIC\_INLINE\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_gaef44a1f3298514569cc2b396a92101ef}{EvolveOptimizer\_Step}}(\mbox{\hyperlink{struct_evolve_optimizer__t}{EvolveOptimizer\_t}}*\ opt,} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00226}00226\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}*\ params,} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00227}00227\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ loss)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00228}00228\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00229}00229\ \ \ \textcolor{keywordflow}{if}((opt\ ==\ NULL)\ ||\ (params\ ==\ NULL))} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00230}00230\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00231}00231\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00232}00232\ \ \ uint16\_t\ n\_params\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a1c270fce82e0c97e6c88fd0971c1eed8}{n\_params}};\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00233}00233\ \ \ \textcolor{keywordflow}{if}(n\_params\ >\ \mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga80d6162495fc3776d8902610657d4fee}{EVOLVE\_MAX\_PARAMS}})} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00234}00234\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00235}00235\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00236}00236\ \ \ uint16\_t\ n\_cand\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_ac35c7ca8cede4ab9c53a2845a91cd1b1}{n\_cand}};\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00237}00237\ \ \ \textcolor{keywordflow}{if}(n\_cand\ >\ \mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga7c1396e5c95c766afccdb45cbfcf5971}{EVOLVE\_MAX\_CANDIDATES}})} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00238}00238\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00239}00239\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00240}00240\ \ \ uint16\_t\ n\_best\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a950cd70cb6bff33b78ad35ee58c729a6}{n\_best}};\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00241}00241\ \ \ \textcolor{keywordflow}{if}(n\_best\ >\ \mbox{\hyperlink{group___e_v_o_l_v_e___c_o_n_f_i_g_ga7c1396e5c95c766afccdb45cbfcf5971}{EVOLVE\_MAX\_CANDIDATES}}/2)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00242}00242\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00243}00243\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00244}00244\ \ \ \textcolor{keywordtype}{float}\ \ \ \ mut\ \ \ \ \ \ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_af779c7aeba0053e36cee7aade160f1c8}{mutation\_amp}};} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00245}00245\ \ \ \textcolor{keywordflow}{if}((mut\ >\ 1)\ ||(mut\ <\ 0))} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00246}00246\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00247}00247\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00248}00248\ \ \ \textcolor{comment}{//\ 1.\ Сохраняем\ loss\ текущего\ кандидата}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00249}00249\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{cand\_index}}]\ =\ loss;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00250}00250\ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{cand\_index}}++;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00251}00251\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00252}00252\ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{cand\_index}}\ >=\ n\_cand)\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00253}00253\ \ \ \ \ \textcolor{comment}{//\ 2.\ Сортируем\ текущее\ поколение\ по\ loss}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00254}00254\ \ \ \ \ \textcolor{keywordflow}{for}(uint16\_t\ i\ =\ 0;\ i\ <\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_ac35c7ca8cede4ab9c53a2845a91cd1b1}{n\_cand}};\ i++)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00255}00255\ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{sorted\_idx}}[i]\ =\ i;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00256}00256\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00257}00257\ \ \ \ \ g\_sort\_opt\ =\ opt;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00258}00258\ \ \ \ \ qsort(opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{sorted\_idx}},\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_ac35c7ca8cede4ab9c53a2845a91cd1b1}{n\_cand}},\ \textcolor{keyword}{sizeof}(uint16\_t),\ cmp\_idx);} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00259}00259\ \ \ \ \ g\_sort\_opt\ =\ NULL;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00260}00260\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00261}00261\ \ \ \ \ \textcolor{comment}{//\ -\/-\/-\/\ Адаптивная\ мутация\ в\ зависимости\ от\ Loss\ -\/-\/-\/}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00262}00262\ \ \ \ \ \textcolor{keywordtype}{float}\ best\_loss\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{sorted\_idx}}[0]];} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00263}00263\ \ \ \ \ \textcolor{keywordtype}{float}\ worst\_loss\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{sorted\_idx}}[opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_ac35c7ca8cede4ab9c53a2845a91cd1b1}{n\_cand}}\ -\/\ 1]];} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00264}00264\ \ \ \ \ \textcolor{keywordtype}{float}\ diff\ =\ worst\_loss\ -\/\ best\_loss;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00265}00265\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00266}00266\ \ \ \ \ \textcolor{keywordtype}{float}\ sum\_loss\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00267}00267\ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_cand;\ i++)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00268}00268\ \ \ \ \ \ \ sum\_loss\ +=\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[i];} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00269}00269\ \ \ \ \ \textcolor{keywordtype}{float}\ avg\_loss\ =\ sum\_loss\ /\ (float)n\_cand;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00270}00270\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00271}00271\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00272}00272\ \ \ \ \ \textcolor{keywordtype}{float}\ loss\_ratio\ =\ (diff\ >\ 0.0f)\ ?\ ((avg\_loss\ -\/\ best\_loss)\ /\ diff)\ :\ 0.5f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00273}00273\ \ \ \ \ \textcolor{keywordflow}{if}\ (loss\_ratio\ <\ 0.0f)\ loss\_ratio\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00274}00274\ \ \ \ \ \textcolor{keywordflow}{if}\ (loss\_ratio\ >\ 1.0f)\ loss\_ratio\ =\ 1.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00275}00275\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00276}00276\ \ \ \ \ \textcolor{comment}{//\ Записываем\ стабильность\ популяции\ в\ структуру}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00277}00277\ \ \ \ \ \textcolor{keywordflow}{if}(diff\ <\ 0.0f)\ diff\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00278}00278\ \ \ \ \ \textcolor{keywordflow}{if}(diff\ >\ 1.0f)\ diff\ =\ 1.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00279}00279\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a80eb0b8525b6bb838484f5922b9d8f7c}{stability}}\ =\ (1.0f\ -\/\ worst\_loss)\ *\ (1.0f\ -\/\ (worst\_loss\ -\/\ best\_loss));} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00280}00280\ \ \ \ \ \textcolor{keywordflow}{if}(opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a80eb0b8525b6bb838484f5922b9d8f7c}{stability}}\ <\ 0.0f)\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a80eb0b8525b6bb838484f5922b9d8f7c}{stability}}\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00281}00281\ \ \ \ \ \textcolor{keywordflow}{if}(opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a80eb0b8525b6bb838484f5922b9d8f7c}{stability}}\ >\ 1.0f)\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a80eb0b8525b6bb838484f5922b9d8f7c}{stability}}\ =\ 1.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00282}00282\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00283}00283\ \ \ \ \ \textcolor{keywordtype}{float}\ mut\_pct\ =\ \mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga2f2b1be34ad4eb1bf3267237200cd6c6}{EVOLVE\_MUTATION\_MIN\_PCT}}\ +} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00284}00284\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga861c1c6a503c21441abcec0d57b848bc}{EVOLVE\_MUTATION\_MAX\_PCT}}\ -\/\ \mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga2f2b1be34ad4eb1bf3267237200cd6c6}{EVOLVE\_MUTATION\_MIN\_PCT}})\ *\ loss\_ratio;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00285}00285\ \ \ \ \ \textcolor{keywordtype}{float}\ adaptive\_mut\ =\ mut\ *\ (mut\_pct\ /\ 100.0f);} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00286}00286\ \ \ \ \ \textcolor{keywordflow}{if}\ (adaptive\_mut\ <\ 0.0001f)\ adaptive\_mut\ =\ 0.0001f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00287}00287\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a3be8c0c34db8429210ff470497a56727}{gen\_mut}}\ =\ adaptive\_mut;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00288}00288\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00289}00289\ \ \ \ \ \textcolor{comment}{//\ 3.\ Генерируем\ новое\ поколение}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00290}00290\ \ \ \ \ uint16\_t\ n\_elite\ =\ \mbox{\hyperlink{group___e_v_o_l_v_e___o_p_t_i_m_i_z_e_r_ga38607e23d9234524bc7de5869b15b8eb}{ELOVLE\_N\_ELITE\_CANDIDATE}};} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00291}00291\ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ c\ =\ 0;\ c\ <\ n\_cand;\ c++)\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00292}00292\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (c\ <\ n\_elite)\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00293}00293\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_params;\ i++)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00294}00294\ \ \ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[c][i]\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{sorted\_idx}}[c]][i];} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00295}00295\ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[c]\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00296}00296\ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00297}00297\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_params;\ i++)\ \{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00298}00298\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ inv\_randmax\ =\ 1.0f\ /\ (float)RAND\_MAX;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00299}00299\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ noise\ =\ ((float)rand()\ *\ inv\_randmax\ *\ 2.0f\ -\/\ 1.0f)\ *\ adaptive\_mut;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00300}00300\ \ \ \ \ \ \ \ \ \ \ uint16\_t\ parent\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a74b81df1c298c99162310f3f7d91735a}{sorted\_idx}}[rand()\ \%\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a950cd70cb6bff33b78ad35ee58c729a6}{n\_best}}];} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00301}00301\ \ \ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[c][i]\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[parent][i]\ +\ noise;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00302}00302\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[c][i]\ <\ 0.0f)\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[c][i]\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00303}00303\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[c][i]\ >\ 1.0f)\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[c][i]\ =\ 1.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00304}00304\ \ \ \ \ \ \ \ \ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00305}00305\ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a93f628397c2f8d4027f2906752b650df}{loss}}[c]\ =\ 0.0f;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00306}00306\ \ \ \ \ \ \ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00307}00307\ \ \ \ \ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00308}00308\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{cand\_index}}\ =\ 0;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00309}00309\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_ad0f464d7048a9ed0753b61f76f563108}{gen\_index}}++;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00310}00310\ \ \ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00311}00311\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00312}00312\ \ \ \textcolor{comment}{//\ 4.\ Возвращаем\ параметры\ следующего\ кандидата}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00313}00313\ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a1c270fce82e0c97e6c88fd0971c1eed8}{n\_params}};\ i++)} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00314}00314\ \ \ \ \ params[i]\ =\ opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_aec67667fd1f1533e693e41c79bc28da4}{candidates}}[opt-\/>\mbox{\hyperlink{struct_evolve_optimizer__t_a0ae0e63ba351335d4445d927991c64ae}{cand\_index}}][i];} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00315}00315\ \ \ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00316}00316\ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00317}00317\ \}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00318}00318\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{//\ ENABLE\_EVOLVE\_OPTIMIZATION}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00319}00319\ \textcolor{comment}{//заглушки}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00320}00320\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\{} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00321}00321\ \ \ uint16\_t\ n\_params;\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00322}00322\ \ \ uint16\_t\ n\_cand;\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00323}00323\ \ \ uint16\_t\ n\_best;\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00324}00324\ \ \ \textcolor{keywordtype}{float}\ mutation\_amp;\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00325}00325\ \ \ \textcolor{keywordtype}{float}\ loss[0];\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00326}00326\ \ \ \textcolor{keywordtype}{float}\ candidates[0][0];\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00327}00327\ \}\ \mbox{\hyperlink{struct_evolve_optimizer__t}{EvolveOptimizer\_t}};} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00328}00328\ \textcolor{preprocessor}{\#define\ EvolveOptimizer\_Init(opt,\ n\_params,\ n\_cand,\ n\_best,\ mutation\_amp,\ start\_params)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00329}00329\ \textcolor{preprocessor}{\#define\ EvolveOptimizer\_Step(opt,\ params,\ LossFunc)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00330}00330\ \textcolor{preprocessor}{\#define\ PARAM\_SCALE(x,\ min\_val,\ max\_val)\ \ \ \ \ \ \ \ \ (x)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00331}00331\ \textcolor{preprocessor}{\#define\ PARAM\_UNSCALE(val,\ min\_val,\ max\_val)\ \ \ \ \ (val)}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00332}00332\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ ENABLE\_EVOLVE\_OPTIMIZATION}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00333}00333\ } \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00334}00334\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ \_\_EVOLVE\_OPTIMIZER\_H\_}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00335}00335\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00336}00336\ \textcolor{comment}{/**\ EVOLVE\_OPTIMIZER}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00337}00337\ \textcolor{comment}{\ \ *\ @\}}} \DoxyCodeLine{\Hypertarget{evolve__optimizer_8h_source_l00338}00338\ \textcolor{comment}{\ \ */}} \end{DoxyCode}