{"id":346310,"date":"2023-03-06T03:00:46","date_gmt":"2023-03-06T03:00:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=346310"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=346310","title":{"rendered":"<span>\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u043b\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430, \u0432 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0440\u0430\u0437 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0441\u0442\u0440\u0435\u0432\u0430\u043d\u0438\u044e \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435, \u0447\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 (\u0438 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f).<\/p>\n<p>\u0414\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u043e\u0431\u0443\u0434\u0438\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 \u043d\u0430 \u0442\u0435\u043c\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (<a href=\"https:\/\/habr.com\/ru\/company\/skillfactory\/blog\/717360\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/company\/skillfactory\/blog\/717360\/<\/a> Wouter van Heeswijk, PhD).<\/p>\n<h2>\u0427\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043d\u0435 \u0442\u0430\u043a?<\/h2>\n<blockquote>\n<p>\u041d\u0435\u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u044b\u0435 \u0448\u0430\u0433\u0438, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0432\u0438\u0441\u0430\u044e\u0442 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435, \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0448\u0430\u0433\u0438, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0432\u043e\u0437\u043d\u0430\u0433\u0440\u0430\u0436\u0434\u0435\u043d\u0438\u0435.<\/p>\n<\/blockquote>\n<p>\u0412 \u043b\u044e\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0435 \u043c\u044b <strong>\u0438\u043b\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043c\u0430\u043b\u044b\u043c\u0438 \u0448\u0430\u0433\u0430\u043c\u0438<\/strong> (\u0438 \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c), <strong>\u0438\u043b\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043c \u043a \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0448\u0430\u0433\u0430\u043c\u0438<\/strong>. \u0412\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0448\u0430\u0433\u043e\u0432 \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0411\u041f\u0424, \u043d\u043e \u044d\u0442\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<blockquote>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438, \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0437\u0430\u0432\u044b\u0448\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<\/blockquote>\n<p><strong>\u0417\u0430\u043b\u043e\u0433 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0437\u0430\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438<\/strong>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\\\u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434 \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u0431\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430 \u0442\u0440\u0438\u043b\u043b\u0438\u043e\u043d.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e <strong>\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u043e\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong> (\u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c, \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0442\u0440\u044e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f). \u041e\u0434\u043d\u0430\u043a\u043e \u043b\u0438\u0448\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0443\u0441\u0442\u044c \u0434\u0430\u0436\u0435 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435\u0442.<\/p>\n<h2>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430, \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c N \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0442\u043e\u0447\u0435\u043a \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c (\u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e)<\/p>\n<p>\u0426\u0438\u043a\u043b:<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0441\u0442\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0442\u043e\u0447\u043a\u0430 \u0437\u0430\u0441\u0442\u0440\u044f\u043b\u0430 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435 (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 N \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u043d\u0430 \u044d\u043f\u0441\u0438\u043b\u043e\u043d) &#8212; \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0441\u0442\u0440\u044f\u0432\u0448\u0438\u0445 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435 (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0442\u043e\u0447\u043a\u0443)<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u0442 &#8212; \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u043f. 2-4 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442\u0441\u044f \u0448\u0430\u0433\u0438 \u0438\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0448\u0438\u0431\u043a\u0438<\/p>\n<p>\u0427\u0442\u043e \u043d\u0430\u043c \u044d\u0442\u043e \u0434\u0430\u0441\u0442?<\/p>\n<p>\u041d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432, \u0447\u0442\u043e \u0448\u0430\u043d\u0441 \u0437\u0430\u0441\u0442\u0440\u044f\u0442\u044c \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0432 N \u0440\u0430\u0437, \u0433\u0434\u0435 N &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a.<\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0448\u0430\u0433\u043e\u0432, \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f) \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c N \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u043f\u0443\u0441\u043a\u043e\u0432 (\u043f\u043e M \u0448\u0430\u0433\u043e\u0432), \u0438\u043b\u0438 M*N, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 M+N(\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0441\u043f\u0443\u0441\u043a).<\/p>\n<h2>\u041a\u043e\u0434<\/h2>\n<details class=\"spoiler\">\n<summary>python<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from queue import PriorityQueue import numpy as np import random from math import sqrt  ##Parameters  #learning rate dt = 0.01  #maximum step count maxSteps = 1000000  #minimum_error minError = 0.01 ##Specifical parameters  #small number to calculate derivative of target function (for using script with large object functions, like neural nets or so) delta = 0.001  #target vector len trace_len = 20  #initilal point count N = 100000  #size of parameters space spaceSize=[[-1000,1000],[-1000,1000]]  #for analysis purpose GetErrorCallCount = 0  localOptimums = []  #taked from https:\/\/github.com\/behnamasadi\/gradient_descent\/ def objective_function(vector):     z=-(4*np.exp(-(vector[0]-4)**2 - (vector[1]-4)**2)+2*np.exp(-(vector[0]-2)**2 - (vector[1]-2)**2))+4     return z      #we will compute exact derivative def get_objective_function_derivatives(vector,delta,error):     res = []          initial_error = error          pos_vector = vector[0]      for n in range(len(pos_vector)):         vec = pos_vector         vec[n] = vec[n]+delta                  derivative_n = -(GetError(vec)-initial_error)\/delta         res.append(derivative_n)           #change to correct derivative calculation     return res      #returns normalized derivative vector def get_error_gradient(vector,delta, error):     derivative = get_objective_function_derivatives(vector, delta, error)     #recalculate derivative, if take 0 multiply delta by ten          while all(d ==0 for d in derivative):         # print(\"get zero derivative\")         # print(derivative)         # print(delta)         delta=delta*10                  #doesnt help, return ReInitialization flag         if (delta>1000):             return derivative                                   derivative = get_objective_function_derivatives(vector, delta, error)              return derivative      def initGradDesc(sampleVector, priorityQueue, N):     res = []     global spaceSize     #Let's generate N random vectors with same length     for num in range(N):          #Initialize derivatives and vector randomly         pos = []         for i in range(len(sampleVector)):             pos.append(random.uniform(spaceSize[i][0],spaceSize[i][1]))                  error = GetError(pos)          res.append([error, [pos]])          #Now we have N random vectors, please note that we must have normaziled data everywhere )     #lets add all those vectors in priorityQueue with our GetError Function      for x in res:         priorityQueue.put(x)  #TODO: rewrite euler integration and calculation of derivatives  #use simpliest Euler method to find change of coordinates with some derivatives def calculateNewPosition(stateVector, error_grad):     delta = []      delta = [x[0]+x[1]*dt for x in zip(stateVector[0],error_grad)]      return delta       #returns error for current vector as a solution def GetError(vector):     #update call count     global GetErrorCallCount     GetErrorCallCount = GetErrorCallCount+1;     return objective_function(vector)      def getLengthBetween(item, newPoint):     l = sqrt(sum((i[0]-i[1])*(i[0]-i[1]) for i in zip(item,newPoint)))     return l      def makeGradDesc(priorityQ, point):     global delta          errorInit = point[0]     state_vector = point[1]       #Note that point structure is [vec, derivatives_1,...,derivatives_N]     error_grad = get_error_gradient(state_vector,delta,errorInit)         newPoint = calculateNewPosition(state_vector, error_grad)          error = GetError(newPoint)          #merge data into one list     res = [newPoint]      curr_trace = 0;     for positions in state_vector:         res.append(positions)         curr_trace = curr_trace+1         if (curr_trace>=trace_len):             break              #calculate error      res = [error,res]              #Check for local optimum (cost function dont change last N steps), initialize new point     if (all(getLengthBetween(item, newPoint) &lt; dt for item in state_vector)):         localOptimums.append(res)         initGradDesc(newPoint, priorityQ, 1)     else:         priorityQ.put(res)      #main gradient descent function that runs for MaxStepCount or while minimal error is not reached     def PreformDradDesc(priorityQ, MaxStepCount,minError):     point = priorityQ.get()     error = point[0]     steps = 0     while ((abs(error)>=abs(minError)) and (steps&lt;MaxStepCount)):         steps = steps + 1         makeGradDesc(priorityQ, point)         point = priorityQ.get()         error =  point[0]              return [steps, error, point]  #Where to store statistics about steps count\/result error research_results = []  #Queue needed for our A* priorityQ = PriorityQueue()  initGradDesc(spaceSize, priorityQ, N+1)  print(\"Data example: \") point = priorityQ.get() print(point)   #Print results print(\"Cost function calls for initialization: \") print(GetErrorCallCount)  minimum_error = PreformDradDesc(priorityQ, maxSteps, minError) print(\"Minimum error: \") print(minimum_error[1]) print(\"Result point: \") print(minimum_error[2][1][1])  print(\"Initial points: \") print(N) print(\"Total steps: \") print(minimum_error[0]) print(\"Maximum steps: \") print(maxSteps)  print(\"Cost function calls: \") print(GetErrorCallCount)  print(\"Local minimums queue len: \") print(len(localOptimums)) # for item in localOptimums:     # print(item)       print(\"Raw results: \") for item in research_results:     print(item) <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e, \u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0432\u0435\u043b\u0438\u043a\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043c\u043d\u043e\u0436\u0430\u044e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u0430\u043b\u043e\u0435 \u043f\u0440\u0438\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 10.<br \/>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0434\u0430\u0436\u0435 \u043c\u0430\u043b\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 float32-64).<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/h2>\n<p>\u0412 10 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0445 \u0438\u0437 10 \u0431\u044b\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c (\u0447\u0442\u043e \u0443\u0436\u0435 \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435\u043f\u043b\u043e\u0445\u043e \ud83d\ude42 ).<\/p>\n<p>\u0414\u0435\u0442\u0435\u043a\u0442\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0442\u0430\u043a \u0438 \u043d\u0430 \u043f\u043b\u0430\u0442\u043e. <\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h2>\n<ol>\n<li>\n<p><a href=\"https:\/\/github.com\/Rezmason\/matrix\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 <\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/behnamasadi\/gradient_descent\/\" rel=\"noopener noreferrer nofollow\">\u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <\/a><\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/720592\/\"> https:\/\/habr.com\/ru\/post\/720592\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430, \u0432 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0440\u0430\u0437 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0441\u0442\u0440\u0435\u0432\u0430\u043d\u0438\u044e \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435, \u0447\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 (\u0438 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f).<\/p>\n<p>\u0414\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u043e\u0431\u0443\u0434\u0438\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 \u043d\u0430 \u0442\u0435\u043c\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (<a href=\"https:\/\/habr.com\/ru\/company\/skillfactory\/blog\/717360\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/company\/skillfactory\/blog\/717360\/<\/a> Wouter van Heeswijk, PhD).<\/p>\n<h2>\u0427\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043d\u0435 \u0442\u0430\u043a?<\/h2>\n<blockquote>\n<p>\u041d\u0435\u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u044b\u0435 \u0448\u0430\u0433\u0438, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0432\u0438\u0441\u0430\u044e\u0442 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435, \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0448\u0430\u0433\u0438, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0432\u043e\u0437\u043d\u0430\u0433\u0440\u0430\u0436\u0434\u0435\u043d\u0438\u0435.<\/p>\n<\/blockquote>\n<p>\u0412 \u043b\u044e\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0435 \u043c\u044b <strong>\u0438\u043b\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043c\u0430\u043b\u044b\u043c\u0438 \u0448\u0430\u0433\u0430\u043c\u0438<\/strong> (\u0438 \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c), <strong>\u0438\u043b\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043c \u043a \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0448\u0430\u0433\u0430\u043c\u0438<\/strong>. \u0412\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0448\u0430\u0433\u043e\u0432 \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0411\u041f\u0424, \u043d\u043e \u044d\u0442\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<blockquote>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438, \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0437\u0430\u0432\u044b\u0448\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<\/blockquote>\n<p><strong>\u0417\u0430\u043b\u043e\u0433 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0437\u0430\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438<\/strong>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\\\u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434 \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u0431\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430 \u0442\u0440\u0438\u043b\u043b\u0438\u043e\u043d.<\/p>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e <strong>\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u043e\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong> (\u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c, \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0442\u0440\u044e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f). \u041e\u0434\u043d\u0430\u043a\u043e \u043b\u0438\u0448\u0430\u0442\u044c\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0443\u0441\u0442\u044c \u0434\u0430\u0436\u0435 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435\u0442.<\/p>\n<h2>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430, \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c N \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0442\u043e\u0447\u0435\u043a \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c (\u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e)<\/p>\n<p>\u0426\u0438\u043a\u043b:<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0441\u0442\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0442\u043e\u0447\u043a\u0430 \u0437\u0430\u0441\u0442\u0440\u044f\u043b\u0430 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435 (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 N \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u043d\u0430 \u044d\u043f\u0441\u0438\u043b\u043e\u043d) &#8212; \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0441\u0442\u0440\u044f\u0432\u0448\u0438\u0445 \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435 (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0442\u043e\u0447\u043a\u0443)<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435\u0442 &#8212; \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u043f. 2-4 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442\u0441\u044f \u0448\u0430\u0433\u0438 \u0438\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043e\u0448\u0438\u0431\u043a\u0438<\/p>\n<p>\u0427\u0442\u043e \u043d\u0430\u043c \u044d\u0442\u043e \u0434\u0430\u0441\u0442?<\/p>\n<p>\u041d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432, \u0447\u0442\u043e \u0448\u0430\u043d\u0441 \u0437\u0430\u0441\u0442\u0440\u044f\u0442\u044c \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0432 N \u0440\u0430\u0437, \u0433\u0434\u0435 N &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a.<\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0448\u0430\u0433\u043e\u0432, \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f) \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c N \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0445 \u0441\u043f\u0443\u0441\u043a\u043e\u0432 (\u043f\u043e M \u0448\u0430\u0433\u043e\u0432), \u0438\u043b\u0438 M*N, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 M+N(\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0441\u043f\u0443\u0441\u043a).<\/p>\n<h2>\u041a\u043e\u0434<\/h2>\n<details class=\"spoiler\">\n<summary>python<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from queue import PriorityQueue import numpy as np import random from math import sqrt  ##Parameters  #learning rate dt = 0.01  #maximum step count maxSteps = 1000000  #minimum_error minError = 0.01 ##Specifical parameters  #small number to calculate derivative of target function (for using script with large object functions, like neural nets or so) delta = 0.001  #target vector len trace_len = 20  #initilal point count N = 100000  #size of parameters space spaceSize=[[-1000,1000],[-1000,1000]]  #for analysis purpose GetErrorCallCount = 0  localOptimums = []  #taked from https:\/\/github.com\/behnamasadi\/gradient_descent\/ def objective_function(vector):     z=-(4*np.exp(-(vector[0]-4)**2 - (vector[1]-4)**2)+2*np.exp(-(vector[0]-2)**2 - (vector[1]-2)**2))+4     return z      #we will compute exact derivative def get_objective_function_derivatives(vector,delta,error):     res = []          initial_error = error          pos_vector = vector[0]      for n in range(len(pos_vector)):         vec = pos_vector         vec[n] = vec[n]+delta                  derivative_n = -(GetError(vec)-initial_error)\/delta         res.append(derivative_n)           #change to correct derivative calculation     return res      #returns normalized derivative vector def get_error_gradient(vector,delta, error):     derivative = get_objective_function_derivatives(vector, delta, error)     #recalculate derivative, if take 0 multiply delta by ten          while all(d ==0 for d in derivative):         # print(\"get zero derivative\")         # print(derivative)         # print(delta)         delta=delta*10                  #doesnt help, return ReInitialization flag         if (delta>1000):             return derivative                                   derivative = get_objective_function_derivatives(vector, delta, error)              return derivative      def initGradDesc(sampleVector, priorityQueue, N):     res = []     global spaceSize     #Let's generate N random vectors with same length     for num in range(N):          #Initialize derivatives and vector randomly         pos = []         for i in range(len(sampleVector)):             pos.append(random.uniform(spaceSize[i][0],spaceSize[i][1]))                  error = GetError(pos)          res.append([error, [pos]])          #Now we have N random vectors, please note that we must have normaziled data everywhere )     #lets add all those vectors in priorityQueue with our GetError Function      for x in res:         priorityQueue.put(x)  #TODO: rewrite euler integration and calculation of derivatives  #use simpliest Euler method to find change of coordinates with some derivatives def calculateNewPosition(stateVector, error_grad):     delta = []      delta = [x[0]+x[1]*dt for x in zip(stateVector[0],error_grad)]      return delta       #returns error for current vector as a solution def GetError(vector):     #update call count     global GetErrorCallCount     GetErrorCallCount = GetErrorCallCount+1;     return objective_function(vector)      def getLengthBetween(item, newPoint):     l = sqrt(sum((i[0]-i[1])*(i[0]-i[1]) for i in zip(item,newPoint)))     return l      def makeGradDesc(priorityQ, point):     global delta          errorInit = point[0]     state_vector = point[1]       #Note that point structure is [vec, derivatives_1,...,derivatives_N]     error_grad = get_error_gradient(state_vector,delta,errorInit)         newPoint = calculateNewPosition(state_vector, error_grad)          error = GetError(newPoint)          #merge data into one list     res = [newPoint]      curr_trace = 0;     for positions in state_vector:         res.append(positions)         curr_trace = curr_trace+1         if (curr_trace>=trace_len):             break              #calculate error      res = [error,res]              #Check for local optimum (cost function dont change last N steps), initialize new point     if (all(getLengthBetween(item, newPoint) &lt; dt for item in state_vector)):         localOptimums.append(res)         initGradDesc(newPoint, priorityQ, 1)     else:         priorityQ.put(res)      #main gradient descent function that runs for MaxStepCount or while minimal error is not reached     def PreformDradDesc(priorityQ, MaxStepCount,minError):     point = priorityQ.get()     error = point[0]     steps = 0     while ((abs(error)>=abs(minError)) and (steps&lt;MaxStepCount)):         steps = steps + 1         makeGradDesc(priorityQ, point)         point = priorityQ.get()         error =  point[0]              return [steps, error, point]  #Where to store statistics about steps count\/result error research_results = []  #Queue needed for our A* priorityQ = PriorityQueue()  initGradDesc(spaceSize, priorityQ, N+1)  print(\"Data example: \") point = priorityQ.get() print(point)   #Print results print(\"Cost function calls for initialization: \") print(GetErrorCallCount)  minimum_error = PreformDradDesc(priorityQ, maxSteps, minError) print(\"Minimum error: \") print(minimum_error[1]) print(\"Result point: \") print(minimum_error[2][1][1])  print(\"Initial points: \") print(N) print(\"Total steps: \") print(minimum_error[0]) print(\"Maximum steps: \") print(maxSteps)  print(\"Cost function calls: \") print(GetErrorCallCount)  print(\"Local minimums queue len: \") print(len(localOptimums)) # for item in localOptimums:     # print(item)       print(\"Raw results: \") for item in research_results:     print(item) <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e, \u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0432\u0435\u043b\u0438\u043a\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043c\u043d\u043e\u0436\u0430\u044e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u0430\u043b\u043e\u0435 \u043f\u0440\u0438\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 10.<br \/>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0434\u0430\u0436\u0435 \u043c\u0430\u043b\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 float32-64).<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/h2>\n<p>\u0412 10 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0445 \u0438\u0437 10 \u0431\u044b\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c (\u0447\u0442\u043e \u0443\u0436\u0435 \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435\u043f\u043b\u043e\u0445\u043e \ud83d\ude42 ).<\/p>\n<p>\u0414\u0435\u0442\u0435\u043a\u0442\u043e\u0440 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0442\u0430\u043a \u0438 \u043d\u0430 \u043f\u043b\u0430\u0442\u043e. <\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h2>\n<ol>\n<li>\n<p><a href=\"https:\/\/github.com\/Rezmason\/matrix\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 <\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/behnamasadi\/gradient_descent\/\" rel=\"noopener noreferrer nofollow\">\u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <\/a><\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/720592\/\"> https:\/\/habr.com\/ru\/post\/720592\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-346310","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=346310"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346310\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=346310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=346310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=346310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}