\doxysection{gen\+\_\+optimizer.\+h}
\hypertarget{gen__optimizer_8h_source}{}\label{gen__optimizer_8h_source}\index{E:/.WORK/STM32/STM32\_ExtendedLibs/MyLibs/Inc/gen\_optimizer.h@{E:/.WORK/STM32/STM32\_ExtendedLibs/MyLibs/Inc/gen\_optimizer.h}}
\mbox{\hyperlink{gen__optimizer_8h}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00001}00001\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00002}00002\ \textcolor{comment}{******************************************************************************}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00003}00003\ \textcolor{comment}{*\ @file\ gen\_optimizer.h}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00004}00004\ \textcolor{comment}{*\ @brief\ Заголовочный\ файл\ для\ адаптивного\ подбора\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00005}00005\ \textcolor{comment}{******************************************************************************}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00006}00006\ \textcolor{comment}{*\ @addtogroup\ GEN\_OPTIMIZER\ \ \ \ Genetic\ optimizer}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00007}00007\ \textcolor{comment}{*\ @ingroup\ \ \ \ MYLIBS\_DEFINES}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00008}00008\ \textcolor{comment}{*\ @brief\ \ \ \ \ \ Библиотека\ для\ эволюционного\ подбора\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00009}00009\ \textcolor{comment}{*\ @details}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00010}00010\ \textcolor{comment}{Поддерживает:}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00011}00011\ \textcolor{comment}{-\/\ Любое\ количество\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00012}00012\ \textcolor{comment}{-\/\ Генерацию\ новых\ параметров\ на\ основе\ лучших\ кандидатов}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00013}00013\ \textcolor{comment}{-\/\ Мутацию\ для\ поиска\ оптимальных\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00014}00014\ \textcolor{comment}{-\/\ Несколько\ независимых\ оптимизаторов\ в\ одной\ программе}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00015}00015\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00016}00016\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00017}00017\ \textcolor{comment}{Параметры\ для\ конфигурации:}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00018}00018\ \textcolor{comment}{-\/\ @ref\ GEN\_OPTIMIZATION\_ENABLE\ -\/\ Включить\ оптимизацию\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00019}00019\ \textcolor{comment}{\ \ Если\ библиотека\ отключена\ @ref\ GEN\_OPTIMIZATION\_ENABLE,\ то\ вставляются\ }}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00020}00020\ \textcolor{comment}{\ \ заглушки,\ никак\ не\ влияющие\ на\ параметры\ и\ остальную\ программу}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00021}00021\ \textcolor{comment}{-\/\ @ref\ GEN\_MAX\_PARAMS\ \ \ \ \ \ \ \ \ \ -\/\ Максимальное\ количество\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00022}00022\ \textcolor{comment}{-\/\ @ref\ GEN\_MAX\_CANDIDATES\ \ \ \ \ \ -\/\ Максимальное\ количество\ кандидатов\ для\ обучения}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00023}00023\ \textcolor{comment}{-\/\ (опционально)\ @ref\ GEN\_MUTATION\_MIN\_PCT\ \ \ \ \ \ \ -\/\ Минимальная\ мутация\ в\ процентах\ от\ Loss\ (по\ умолчанию\ 10\%)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00024}00024\ \textcolor{comment}{-\/\ (опционально)\ @ref\ GEN\_MUTATION\_MAX\_PCT\ \ \ \ \ \ \ -\/\ Максимальная\ мутация\ в\ процентах\ от\ Loss\ (по\ умолчанию\ 100\%)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00025}00025\ \textcolor{comment}{-\/\ (опционально)\ @ref\ ELOVLE\_N\_ELITE\_CANDIDATE\ \ \ -\/\ Количество\ кандидатов,\ которые\ проходят\ в\ поколение\ без\ изменений}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00026}00026\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00027}00027\ \textcolor{comment}{@par\ Пример\ использования:}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00028}00028\ \textcolor{comment}{@code}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00029}00029\ \textcolor{comment}{\#include\ "{}gen\_optimizer.h"{}}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00030}00030\ \textcolor{comment}{\#define\ N\_PARAMS\ \ \ \ \ \ \ \ 4}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00031}00031\ \textcolor{comment}{\#define\ N\_CANDIDATES\ \ \ \ 100}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00032}00032\ \textcolor{comment}{\#define\ N\_BEST\ \ \ \ \ \ \ \ \ \ 10}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00033}00033\ \textcolor{comment}{\#define\ MUTATION\ \ \ \ \ \ \ \ 0.1f}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00034}00034\ \textcolor{comment}{float\ params[N\_PARAMS];}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00035}00035\ \textcolor{comment}{GenOptimizer\_t\ optimizer;}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00036}00036\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00037}00037\ \textcolor{comment}{//\ Формирование\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00038}00038\ \textcolor{comment}{uint16\_t\ \ param\_u16\ =\ 800;}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00039}00039\ \textcolor{comment}{float\ \ \ \ \ param\_f\ \ \ =\ 0.01f;}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00040}00040\ \textcolor{comment}{uint8\_t\ \ \ param\_u8\ \ =\ 40;}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00041}00041\ \textcolor{comment}{int16\_t\ \ \ param\_i16\ =\ 1600;}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00042}00042\ \textcolor{comment}{params[0]\ =\ PARAM\_SCALE(param\_u16,\ \ 0.0f,\ \ \ 1000.0f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00043}00043\ \textcolor{comment}{params[1]\ =\ PARAM\_SCALE(param\_f,\ \ \ \ 0.001f,\ 0.1f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00044}00044\ \textcolor{comment}{params[2]\ =\ PARAM\_SCALE(param\_u8,\ \ \ 10.0f,\ \ 100.0f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00045}00045\ \textcolor{comment}{params[3]\ =\ PARAM\_SCALE(param\_i16,\ \ 500.0f,\ 5000.0f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00046}00046\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00047}00047\ \textcolor{comment}{//\ Инициалиазция}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00048}00048\ \textcolor{comment}{GenOptimizer\_Init(\&optimizer,\ N\_PARAMS,\ N\_CANDIDATES,\ N\_BEST,\ MUTATION,\ params);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00049}00049\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00050}00050\ \textcolor{comment}{//\ Шаг\ эволюции}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00051}00051\ \textcolor{comment}{float\ loss\ =\ calc\_loss();\ //\ расчет\ эффективности\ параметров\ (от\ 0\ до\ 1)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00052}00052\ \textcolor{comment}{GenOptimizer\_Step(\&optimizer,\ params,\ loss);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00053}00053\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00054}00054\ \textcolor{comment}{//\ Взятие\ следующих\ для\ эволюции\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00055}00055\ \textcolor{comment}{param\_u16\ =\ PARAM\_UNSCALE(params[0],\ \ 0.0f,\ \ \ 1000.0f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00056}00056\ \textcolor{comment}{param\_f\ \ \ =\ PARAM\_UNSCALE(params[1],\ \ 0.001f,\ 0.1f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00057}00057\ \textcolor{comment}{param\_u8\ \ =\ PARAM\_UNSCALE(params[2],\ \ 10.0f,\ \ 100.0f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00058}00058\ \textcolor{comment}{param\_i16\ =\ PARAM\_UNSCALE(params[3],\ \ 500.0f,\ 5000.0f);}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00059}00059\ \textcolor{comment}{@endcode}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00060}00060\ \textcolor{comment}{*\ @\{\ \ }}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00061}00061\ \textcolor{comment}{*****************************************************************************/}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00062}00062\ \textcolor{preprocessor}{\#ifndef\ \_\_GEN\_OPTIMIZER\_H\_}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00063}00063\ \textcolor{preprocessor}{\#define\ \_\_GEN\_OPTIMIZER\_H\_}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00064}00064\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00065}00065\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{mylibs__defs_8h}{mylibs\_defs.h}}"{}}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00066}00066\ \textcolor{preprocessor}{\#include\ <stdint.h>}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00067}00067\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00068}00068\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00069}00069\ \textcolor{preprocessor}{\#ifdef\ GEN\_OPTIMIZATION\_ENABLE}\textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00070}00070\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00071}00071\ \textcolor{comment}{\ \ *\ @brief\ Линейное\ масштабирование\ x\ из\ диапазона\ [min\_val,\ max\_val]\ в\ диапазон\ [0,\ 1)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00072}00072\ \textcolor{comment}{\ \ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00073}\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga83abbcabaff9111c03ae2475ee72ea3e}{00073}}\ \textcolor{preprocessor}{\#define\ PARAM\_SCALE(x,\ min\_val,\ max\_val)\ \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00074}00074\ \textcolor{preprocessor}{(((float)(x)\ -\/\ (float)(min\_val))\ /\ ((float)(max\_val)\ -\/\ (float)(min\_val)))}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00075}00075\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00076}00076\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00077}00077\ \textcolor{comment}{\ \ *\ @brief\ Обратное\ линейное\ масштабирование\ значения\ из\ [0,\ 1)\ в\ диапазон\ [min\_val,\ max\_val]}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00078}00078\ \textcolor{comment}{\ \ */}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00079}\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_gaa1d5510fe5f0bd989473f3ebe324bde3}{00079}}\ \textcolor{preprocessor}{\#define\ PARAM\_UNSCALE(val,\ min\_val,\ max\_val)\ \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00080}00080\ \textcolor{preprocessor}{(((float)(val))\ *\ ((float)(max\_val)\ -\/\ (float)(min\_val))\ +\ (float)(min\_val))}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00081}00081\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00082}00082\ \textcolor{preprocessor}{\#ifndef\ local\_time}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00083}00083\ \textcolor{preprocessor}{\#define\ local\_time()\ \ HAL\_GetTick()\ }\textcolor{comment}{///<\ Локальное\ время}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00084}00084\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00085}00085\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00086}00086\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00087}00087\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00088}00088\ \textcolor{preprocessor}{\#ifndef\ GEN\_MUTATION\_MIN\_PCT}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00089}\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga3db7bdf57549722427e1e72dcaa87068}{00089}}\ \textcolor{preprocessor}{\#define\ GEN\_MUTATION\_MIN\_PCT\ \ \ 10\ \ \ \ }\textcolor{comment}{///<\ Минимальная\ мутация\ (в\ процентах\ от\ Loss)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00090}00090\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00091}00091\ \textcolor{preprocessor}{\#ifndef\ GEN\_MUTATION\_MAX\_PCT}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00092}\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga48dca8f0a0c9b96d02236ef76ac827fd}{00092}}\ \textcolor{preprocessor}{\#define\ GEN\_MUTATION\_MAX\_PCT\ \ \ 100\ \ \ }\textcolor{comment}{///<\ Максимальная\ мутация\ (в\ процентах\ от\ Loss)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00093}00093\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00094}00094\ \textcolor{preprocessor}{\#ifndef\ ELOVLE\_N\_ELITE\_CANDIDATE}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00095}\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga38607e23d9234524bc7de5869b15b8eb}{00095}}\ \textcolor{preprocessor}{\#define\ ELOVLE\_N\_ELITE\_CANDIDATE\ \ 2\ \ \ \ \ }\textcolor{comment}{///<\ Количество\ кандидатов,\ которые\ проходят\ в\ поколение\ без\ изменений\ (по\ умолчанию\ 2)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00096}00096\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00097}00097\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00098}00098\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00099}00099\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00100}00100\ \textcolor{comment}{\ \ *\ @brief\ Структура\ эволюционного\ оптимизатора}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00101}00101\ \textcolor{comment}{\ \ */}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00102}\mbox{\hyperlink{struct_gen_optimizer__t}{00102}}\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00103}\mbox{\hyperlink{struct_gen_optimizer__t_abe0aacea949fbe93e5d4c002e37d7192}{00103}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_gen_optimizer__t_abe0aacea949fbe93e5d4c002e37d7192}{stability}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Коэффициент\ насколько\ стабильная\ популяция\ (0..1)(@ref\ n\_cand)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00104}00104\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00105}\mbox{\hyperlink{struct_gen_optimizer__t_afe598a90024a8aa628dd16f3a2b38eb5}{00105}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_gen_optimizer__t_afe598a90024a8aa628dd16f3a2b38eb5}{n\_params}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Количество\ параметров}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00106}\mbox{\hyperlink{struct_gen_optimizer__t_a9e20d2f6f39a5147e6dbac46baca73a9}{00106}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_gen_optimizer__t_a9e20d2f6f39a5147e6dbac46baca73a9}{n\_cand}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Количество\ кандидатов\ в\ популяции}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00107}\mbox{\hyperlink{struct_gen_optimizer__t_a8201f1eede36a2c04ec7b4caac7465c9}{00107}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_gen_optimizer__t_a8201f1eede36a2c04ec7b4caac7465c9}{n\_best}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Количество\ лучших,\ усредняемых}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00108}\mbox{\hyperlink{struct_gen_optimizer__t_ad4dc0e53b3ca6bf2a642dfe7a1d1f26c}{00108}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_gen_optimizer__t_ad4dc0e53b3ca6bf2a642dfe7a1d1f26c}{mutation\_amp}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Амплитуда\ мутации\ (0..1)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00109}00109\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00110}\mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{00110}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{cand\_index}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Индекс\ текущего\ кандидата}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00111}\mbox{\hyperlink{struct_gen_optimizer__t_a8f226c85e9bb034cb811aa0366bb191c}{00111}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_gen_optimizer__t_a8f226c85e9bb034cb811aa0366bb191c}{gen\_index}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Индекс\ популяции\ \ }}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00112}00112\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00113}00113\ \ \ \textcolor{comment}{//INTERNAL}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00114}\mbox{\hyperlink{struct_gen_optimizer__t_acfeb93ef4823e09473ddba52fae9a6b1}{00114}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_gen_optimizer__t_acfeb93ef4823e09473ddba52fae9a6b1}{gen\_mut}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{///<\ Амплитуда\ мутации\ у\ текущей\ популяции\ \ }}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00115}00115\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00116}\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{00116}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[\mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga201cffde04ebc6540869c74bd1dae869}{GEN\_MAX\_CANDIDATES}}];\ \ \ \ \textcolor{comment}{///<\ Loss\ для\ каждого\ кандидата}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00117}\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{00117}}\ \ \ \textcolor{keywordtype}{float}\ \ \ \ \ \mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[\mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga201cffde04ebc6540869c74bd1dae869}{GEN\_MAX\_CANDIDATES}}][\mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga8daf4b266a95353d580bd7946f47c0ab}{GEN\_MAX\_PARAMS}}];\ \textcolor{comment}{///<\ Параметры\ кандидатов}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00118}\mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{00118}}\ \ \ uint16\_t\ \ \mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{sorted\_idx}}[\mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga201cffde04ebc6540869c74bd1dae869}{GEN\_MAX\_CANDIDATES}}];\ \textcolor{comment}{///<\ Индексы\ отсортированных\ кандидатов}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00119}00119\ \}\ \mbox{\hyperlink{struct_gen_optimizer__t}{GenOptimizer\_t}};}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00120}00120\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00121}00121\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00122}00122\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00123}00123\ \textcolor{comment}{/**\ }}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00124}00124\ \textcolor{comment}{\ *\ @cond\ GEN\_INTERNAL}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00125}00125\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00126}00126\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00127}00127\ \textcolor{comment}{//\ Вспомогательный\ указатель\ для\ сортировки}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00128}00128\ \textcolor{keyword}{static}\ \mbox{\hyperlink{struct_gen_optimizer__t}{GenOptimizer\_t}}\ *g\_sort\_opt;\ \textcolor{comment}{//\ глобальный\ указатель\ на\ текущий\ оптимизатор}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00129}00129\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00130}00130\ \textcolor{comment}{//\ функция\ условия\ сортировки}}
\DoxyCodeLine{\Hypertarget{gen__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{gen__optimizer_8h_source_l00132}00132\ \ \ \textcolor{keywordflow}{if}\ (g\_sort\_opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)a]\ <\ g\_sort\_opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)b])\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00133}00133\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00134}00134\ \ \ \textcolor{keywordflow}{if}\ (g\_sort\_opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)a]\ >\ g\_sort\_opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[*(\textcolor{keyword}{const}\ uint16\_t*)b])\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00135}00135\ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00136}00136\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00137}00137\ \}\textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00138}00138\ \textcolor{comment}{/**\ @endcond\ */}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00139}00139\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00140}00140\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00141}00141\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00142}00142\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00143}00143\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00144}00144\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00145}00145\ \textcolor{comment}{\ \ *\ @brief\ Инициализация\ эволюционного\ оптимизатора.}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00146}00146\ \textcolor{comment}{\ \ *\ @param\ opt\ \ \ \ \ \ \ \ \ \ Указатель\ на\ структуру\ оптимизатора}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00147}00147\ \textcolor{comment}{\ \ *\ @param\ n\_params\ \ \ \ \ Количество\ параметров\ в\ одном\ кандидате}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00148}00148\ \textcolor{comment}{\ \ *\ @param\ n\_cand\ \ \ \ \ \ \ Количество\ кандидатов}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00149}00149\ \textcolor{comment}{\ \ *\ @param\ n\_best\ \ \ \ \ \ \ Количество\ лучших,\ усредняемых}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00150}00150\ \textcolor{comment}{\ \ *\ @param\ mutation\_amp\ Амплитуда\ мутации\ (в\ диапазоне\ 0.0–1.0)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00151}00151\ \textcolor{comment}{\ \ *\ @param\ start\_params\ Начальные\ параметры\ (в\ диапазоне\ 0.0–1.0)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00152}00152\ \textcolor{comment}{\ \ *\ @return\ 0\ \ \ —\ если\ окей,\ }}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00153}00153\ \textcolor{comment}{\ \ *\ \ \ \ \ \ \ \ \ -\/1\ \ —\ если\ ошибка}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00154}00154\ \textcolor{comment}{\ \ */}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00155}\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga2db1df46b4082ad9280ef4344fdf4e8a}{00155}}\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga2db1df46b4082ad9280ef4344fdf4e8a}{GenOptimizer\_Init}}(\mbox{\hyperlink{struct_gen_optimizer__t}{GenOptimizer\_t}}*\ opt,}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00156}00156\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ n\_params,}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00157}00157\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ n\_cand,}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00158}00158\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ n\_best,}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00159}00159\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ mutation\_amp,}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00160}00160\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}*\ start\_params)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00161}00161\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00162}00162\ \ \ \textcolor{keywordflow}{if}((opt\ ==\ NULL)\ ||\ (start\_params\ ==\ NULL))}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00163}00163\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00164}00164\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00165}00165\ \ \ \textcolor{keywordflow}{if}(n\_params\ >\ \mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga8daf4b266a95353d580bd7946f47c0ab}{GEN\_MAX\_PARAMS}})}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00166}00166\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00167}00167\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_afe598a90024a8aa628dd16f3a2b38eb5}{n\_params}}\ \ \ \ \ =\ n\_params;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00168}00168\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00169}00169\ \ \ \textcolor{keywordflow}{if}(n\_cand\ >\ \mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga201cffde04ebc6540869c74bd1dae869}{GEN\_MAX\_CANDIDATES}})}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00170}00170\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00171}00171\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a9e20d2f6f39a5147e6dbac46baca73a9}{n\_cand}}\ \ \ \ \ \ \ =\ n\_cand;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00172}00172\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00173}00173\ \ \ \textcolor{keywordflow}{if}(n\_best\ >\ \mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga201cffde04ebc6540869c74bd1dae869}{GEN\_MAX\_CANDIDATES}}/2)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00174}00174\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00175}00175\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8201f1eede36a2c04ec7b4caac7465c9}{n\_best}}\ \ \ \ \ \ \ =\ n\_best;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00176}00176\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00177}00177\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00178}00178\ \ \ \textcolor{keywordflow}{if}((mutation\_amp\ >\ 1)\ ||\ (mutation\_amp\ <\ 0))}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00179}00179\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00180}00180\ \ \ \textcolor{keywordflow}{if}(mutation\_amp\ <=\ 0.001f)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00181}00181\ \ \ \ \ mutation\_amp\ =\ 0.001f;\ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00182}00182\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad4dc0e53b3ca6bf2a642dfe7a1d1f26c}{mutation\_amp}}\ \ =\ mutation\_amp;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00183}00183\ }
\DoxyCodeLine{\Hypertarget{gen__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{gen__optimizer_8h_source_l00185}00185\ \textcolor{preprocessor}{\#ifdef\ ADC1}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00186}00186\ \ \ seed\ +=\ (ADC1-\/>DR\ \&\ 0xFF);}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00187}00187\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00188}00188\ \ \ srand(seed);}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00189}00189\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00190}00190\ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_cand;\ i++)\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00191}00191\ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ j\ =\ 0;\ j\ <\ n\_params;\ j++)\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00192}00192\ \ \ \ \ \ \ \textcolor{comment}{//\ Добавляем\ случайную\ мутацию\ вокруг\ стартового\ параметра}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00193}00193\ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ base\ =\ start\_params[j];}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00194}00194\ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ inv\_randmax\ =\ 1.0f\ /\ (float)RAND\_MAX;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00195}00195\ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ noise\ =\ ((float)rand()\ *\ inv\_randmax\ *\ 2.0f\ -\/\ 1.0f)\ *\ mutation\_amp;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00196}00196\ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[i][j]\ =\ base\ +\ noise;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00197}00197\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[i][j]\ <\ 0.0f)\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[i][j]\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00198}00198\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[i][j]\ >\ 1.0f)\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[i][j]\ =\ 1.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00199}00199\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00200}00200\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[i]\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00201}00201\ \ \ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00202}00202\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00203}00203\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{cand\_index}}\ =\ 0;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00204}00204\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8f226c85e9bb034cb811aa0366bb191c}{gen\_index}}\ =\ 0;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00205}00205\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00206}00206\ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00207}00207\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00208}00208\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00209}00209\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00210}00210\ \textcolor{comment}{\ \ *\ @brief\ Один\ шаг\ эволюционного\ оптимизатора.}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00211}00211\ \textcolor{comment}{\ \ *\ @param\ opt\ \ \ \ Указатель\ на\ структуру\ оптимизатора}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00212}00212\ \textcolor{comment}{\ \ *\ @param\ params\ Массив\ параметров,\ которые\ будут\ обновлены\ (на\ выходе\ —\ новые\ параметры)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00213}00213\ \textcolor{comment}{\ \ *\ @param\ loss\ \ \ Loss\ текущего\ кандидата}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00214}00214\ \textcolor{comment}{\ \ *\ @return\ 0\ \ \ —\ если\ окей,\ }}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00215}00215\ \textcolor{comment}{\ \ *\ \ \ \ \ \ \ \ \ -\/1\ \ —\ если\ ошибка}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00216}00216\ \textcolor{comment}{\ \ *\ @details}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00217}00217\ \textcolor{comment}{\ \ *\ Сохраняет\ loss\ текущего\ кандидата\ и\ формирует\ параметры\ следующего\ кандидата.}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00218}00218\ \textcolor{comment}{\ \ *\ Если\ накоплено\ n\_cand\ кандидатов,\ генерируется\ новое\ поколение.}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00219}00219\ \textcolor{comment}{\ \ *\ Новое\ поколение\ формируется\ случайным\ выбором\ из\ n\_best\ лучших\ с\ добавлением\ мутации.}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00220}00220\ \textcolor{comment}{\ \ *}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00221}00221\ \textcolor{comment}{\ \ *\ На\ выходе\ params\ содержит\ параметры\ следующего\ кандидата\ для\ измерений.}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00222}00222\ \textcolor{comment}{\ \ *\ @note\ Функция\ использует\ глобальную\ внутреннюю\ переменную\ для\ сортировки.}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00223}00223\ \textcolor{comment}{\ \ *\ Надо\ убедится\ что\ только\ один\ экземпляр\ функции\ запущен\ в\ момент\ времени}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00224}00224\ \textcolor{comment}{\ \ */}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00225}\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_gaa9a4c4f43f7beb926c85bd4817ebd628}{00225}}\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_gaa9a4c4f43f7beb926c85bd4817ebd628}{GenOptimizer\_Step}}(\mbox{\hyperlink{struct_gen_optimizer__t}{GenOptimizer\_t}}*\ opt,}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00226}00226\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}*\ params,}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00227}00227\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ loss)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00228}00228\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00229}00229\ \ \ \textcolor{keywordflow}{if}((opt\ ==\ NULL)\ ||\ (params\ ==\ NULL))}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00230}00230\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00231}00231\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00232}00232\ \ \ uint16\_t\ n\_params\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_afe598a90024a8aa628dd16f3a2b38eb5}{n\_params}};\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00233}00233\ \ \ \textcolor{keywordflow}{if}(n\_params\ >\ \mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga8daf4b266a95353d580bd7946f47c0ab}{GEN\_MAX\_PARAMS}})}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00234}00234\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00235}00235\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00236}00236\ \ \ uint16\_t\ n\_cand\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a9e20d2f6f39a5147e6dbac46baca73a9}{n\_cand}};\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00237}00237\ \ \ \textcolor{keywordflow}{if}(n\_cand\ >\ \mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga201cffde04ebc6540869c74bd1dae869}{GEN\_MAX\_CANDIDATES}})}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00238}00238\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;\ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00239}00239\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00240}00240\ \ \ uint16\_t\ n\_best\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8201f1eede36a2c04ec7b4caac7465c9}{n\_best}};\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00241}00241\ \ \ \textcolor{keywordflow}{if}(n\_best\ >\ \mbox{\hyperlink{group___g_e_n___c_o_n_f_i_g_ga201cffde04ebc6540869c74bd1dae869}{GEN\_MAX\_CANDIDATES}}/2)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00242}00242\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00243}00243\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00244}00244\ \ \ \textcolor{keywordtype}{float}\ \ \ \ mut\ \ \ \ \ \ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad4dc0e53b3ca6bf2a642dfe7a1d1f26c}{mutation\_amp}};}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00245}00245\ \ \ \textcolor{keywordflow}{if}((mut\ >\ 1)\ ||(mut\ <\ 0))}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00246}00246\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00247}00247\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00248}00248\ \ \ \textcolor{comment}{//\ 1.\ Сохраняем\ loss\ текущего\ кандидата}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00249}00249\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{cand\_index}}]\ =\ loss;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00250}00250\ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{cand\_index}}++;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00251}00251\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00252}00252\ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{cand\_index}}\ >=\ n\_cand)\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00253}00253\ \ \ \ \ \textcolor{comment}{//\ 2.\ Сортируем\ текущее\ поколение\ по\ loss}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00254}00254\ \ \ \ \ \textcolor{keywordflow}{for}(uint16\_t\ i\ =\ 0;\ i\ <\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a9e20d2f6f39a5147e6dbac46baca73a9}{n\_cand}};\ i++)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00255}00255\ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{sorted\_idx}}[i]\ =\ i;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00256}00256\ \ \ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00257}00257\ \ \ \ \ g\_sort\_opt\ =\ opt;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00258}00258\ \ \ \ \ qsort(opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{sorted\_idx}},\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a9e20d2f6f39a5147e6dbac46baca73a9}{n\_cand}},\ \textcolor{keyword}{sizeof}(uint16\_t),\ cmp\_idx);}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00259}00259\ \ \ \ \ g\_sort\_opt\ =\ NULL;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00260}00260\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00261}00261\ \ \ \ \ \textcolor{comment}{//\ -\/-\/-\/\ Адаптивная\ мутация\ в\ зависимости\ от\ Loss\ -\/-\/-\/}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00262}00262\ \ \ \ \ \textcolor{keywordtype}{float}\ best\_loss\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{sorted\_idx}}[0]];}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00263}00263\ \ \ \ \ \textcolor{keywordtype}{float}\ worst\_loss\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{sorted\_idx}}[opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a9e20d2f6f39a5147e6dbac46baca73a9}{n\_cand}}\ -\/\ 1]];}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00264}00264\ \ \ \ \ \textcolor{keywordtype}{float}\ diff\ =\ worst\_loss\ -\/\ best\_loss;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00265}00265\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00266}00266\ \ \ \ \ \textcolor{keywordtype}{float}\ sum\_loss\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00267}00267\ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_cand;\ i++)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00268}00268\ \ \ \ \ \ \ sum\_loss\ +=\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[i];}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00269}00269\ \ \ \ \ \textcolor{keywordtype}{float}\ avg\_loss\ =\ sum\_loss\ /\ (float)n\_cand;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00270}00270\ \ \ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00271}00271\ \ \ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00272}00272\ \ \ \ \ \textcolor{keywordtype}{float}\ loss\_ratio\ =\ (diff\ >\ 0.0f)\ ?\ ((avg\_loss\ -\/\ best\_loss)\ /\ diff)\ :\ 0.5f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00273}00273\ \ \ \ \ \textcolor{keywordflow}{if}\ (loss\_ratio\ <\ 0.0f)\ loss\_ratio\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00274}00274\ \ \ \ \ \textcolor{keywordflow}{if}\ (loss\_ratio\ >\ 1.0f)\ loss\_ratio\ =\ 1.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00275}00275\ \ \ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00276}00276\ \ \ \ \ \textcolor{comment}{//\ Записываем\ стабильность\ популяции\ в\ структуру}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00277}00277\ \ \ \ \ \textcolor{keywordflow}{if}(diff\ <\ 0.0f)\ diff\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00278}00278\ \ \ \ \ \textcolor{keywordflow}{if}(diff\ >\ 1.0f)\ diff\ =\ 1.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00279}00279\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_abe0aacea949fbe93e5d4c002e37d7192}{stability}}\ =\ (1.0f\ -\/\ worst\_loss)\ *\ (1.0f\ -\/\ (worst\_loss\ -\/\ best\_loss));}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00280}00280\ \ \ \ \ \textcolor{keywordflow}{if}(opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_abe0aacea949fbe93e5d4c002e37d7192}{stability}}\ <\ 0.0f)\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_abe0aacea949fbe93e5d4c002e37d7192}{stability}}\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00281}00281\ \ \ \ \ \textcolor{keywordflow}{if}(opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_abe0aacea949fbe93e5d4c002e37d7192}{stability}}\ >\ 1.0f)\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_abe0aacea949fbe93e5d4c002e37d7192}{stability}}\ =\ 1.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00282}00282\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00283}00283\ \ \ \ \ \textcolor{keywordtype}{float}\ mut\_pct\ =\ \mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga3db7bdf57549722427e1e72dcaa87068}{GEN\_MUTATION\_MIN\_PCT}}\ +}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00284}00284\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga48dca8f0a0c9b96d02236ef76ac827fd}{GEN\_MUTATION\_MAX\_PCT}}\ -\/\ \mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga3db7bdf57549722427e1e72dcaa87068}{GEN\_MUTATION\_MIN\_PCT}})\ *\ loss\_ratio;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00285}00285\ \ \ \ \ \textcolor{keywordtype}{float}\ adaptive\_mut\ =\ mut\ *\ (mut\_pct\ /\ 100.0f);}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00286}00286\ \ \ \ \ \textcolor{keywordflow}{if}\ (adaptive\_mut\ <\ 0.0001f)\ adaptive\_mut\ =\ 0.0001f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00287}00287\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_acfeb93ef4823e09473ddba52fae9a6b1}{gen\_mut}}\ =\ adaptive\_mut;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00288}00288\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00289}00289\ \ \ \ \ \textcolor{comment}{//\ 3.\ Генерируем\ новое\ поколение}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00290}00290\ \ \ \ \ uint16\_t\ n\_elite\ =\ \mbox{\hyperlink{group___g_e_n___o_p_t_i_m_i_z_e_r_ga38607e23d9234524bc7de5869b15b8eb}{ELOVLE\_N\_ELITE\_CANDIDATE}};}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00291}00291\ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ c\ =\ 0;\ c\ <\ n\_cand;\ c++)\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00292}00292\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (c\ <\ n\_elite)\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00293}00293\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_params;\ i++)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00294}00294\ \ \ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[c][i]\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{sorted\_idx}}[c]][i];}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00295}00295\ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[c]\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00296}00296\ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00297}00297\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ n\_params;\ i++)\ \{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00298}00298\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ inv\_randmax\ =\ 1.0f\ /\ (float)RAND\_MAX;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00299}00299\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ noise\ =\ ((float)rand()\ *\ inv\_randmax\ *\ 2.0f\ -\/\ 1.0f)\ *\ adaptive\_mut;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00300}00300\ \ \ \ \ \ \ \ \ \ \ uint16\_t\ parent\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_ad37161efa27ef1390d1f7e6ee2f79b12}{sorted\_idx}}[rand()\ \%\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8201f1eede36a2c04ec7b4caac7465c9}{n\_best}}];}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00301}00301\ \ \ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[c][i]\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[parent][i]\ +\ noise;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00302}00302\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[c][i]\ <\ 0.0f)\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[c][i]\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00303}00303\ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[c][i]\ >\ 1.0f)\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[c][i]\ =\ 1.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00304}00304\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00305}00305\ \ \ \ \ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8b5066935d99f2fc7ebb94cc3652fc73}{loss}}[c]\ =\ 0.0f;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00306}00306\ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00307}00307\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00308}00308\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{cand\_index}}\ =\ 0;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00309}00309\ \ \ \ \ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a8f226c85e9bb034cb811aa0366bb191c}{gen\_index}}++;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00310}00310\ \ \ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00311}00311\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00312}00312\ \ \ \textcolor{comment}{//\ 4.\ Возвращаем\ параметры\ следующего\ кандидата}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00313}00313\ \ \ \textcolor{keywordflow}{for}\ (uint16\_t\ i\ =\ 0;\ i\ <\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_afe598a90024a8aa628dd16f3a2b38eb5}{n\_params}};\ i++)}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00314}00314\ \ \ \ \ params[i]\ =\ opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a2c9a50ea7d975b9bc22a67e453ab83df}{candidates}}[opt-\/>\mbox{\hyperlink{struct_gen_optimizer__t_a04a72c1a13e17581e84eaaf3d245bbfc}{cand\_index}}][i];}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00315}00315\ \ \ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00316}00316\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00317}00317\ \}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00318}00318\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{//\ GEN\_OPTIMIZATION\_ENABLE}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00319}00319\ \textcolor{comment}{//заглушки}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00320}00320\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\{}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00321}00321\ \ \ uint16\_t\ n\_params;\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00322}00322\ \ \ uint16\_t\ n\_cand;\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00323}00323\ \ \ uint16\_t\ n\_best;\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00324}00324\ \ \ \textcolor{keywordtype}{float}\ mutation\_amp;\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00325}00325\ \ \ \textcolor{keywordtype}{float}\ loss[0];\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00326}00326\ \ \ \textcolor{keywordtype}{float}\ candidates[0][0];\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00327}00327\ \}\ \mbox{\hyperlink{struct_gen_optimizer__t}{GenOptimizer\_t}};}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00328}00328\ \textcolor{preprocessor}{\#define\ GenOptimizer\_Init(opt,\ n\_params,\ n\_cand,\ n\_best,\ mutation\_amp,\ start\_params)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00329}00329\ \textcolor{preprocessor}{\#define\ GenOptimizer\_Step(opt,\ params,\ LossFunc)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00330}00330\ \textcolor{preprocessor}{\#define\ PARAM\_SCALE(x,\ min\_val,\ max\_val)\ \ \ \ \ \ \ \ \ (x)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00331}00331\ \textcolor{preprocessor}{\#define\ PARAM\_UNSCALE(val,\ min\_val,\ max\_val)\ \ \ \ \ (val)}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00332}00332\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ GEN\_OPTIMIZATION\_ENABLE}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00333}00333\ }
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00334}00334\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ \_\_GEN\_OPTIMIZER\_H\_}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00335}00335\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00336}00336\ \textcolor{comment}{/**\ GEN\_OPTIMIZER}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00337}00337\ \textcolor{comment}{\ \ *\ @\}}}
\DoxyCodeLine{\Hypertarget{gen__optimizer_8h_source_l00338}00338\ \textcolor{comment}{\ \ */}}

\end{DoxyCode}
