{"id":371885,"date":"2024-05-21T04:58:54","date_gmt":"2024-05-21T04:58:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=371885"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=371885","title":{"rendered":"<span>\u041a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f Q-learning \u0438 \u043a\u0430\u043a \u043e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Python \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/3c5\/105\/889\/3c5105889fecbb52e0145035ff594104.jpg\" width=\"1280\" height=\"720\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3c5\/105\/889\/3c5105889fecbb52e0145035ff594104.jpg\" data-blurred=\"true\"\/><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/p>\n<p><strong>Q-learning<\/strong> \u2014 \u044d\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u0434\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0430\u0433\u0435\u043d\u0442\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435, \u0441\u0442\u0440\u0435\u043c\u044f\u0441\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043d\u0430\u0433\u0440\u0430\u0434. \u0410\u0433\u0435\u043d\u0442 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0440\u0435\u0434\u0443, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043e\u043f\u044b\u0442\u0435, \u0430 \u043d\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0438\u0440\u0430.<\/p>\n<p><em>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c.<\/em><\/p>\n<h3>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b<\/h3>\n<p><strong>\u0410\u0433\u0435\u043d\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/strong> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <strong>\u0438\u0437 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435&#8230;.\u0421\u0442\u043e\u043f..\u0447\u0442\u043e \u0437\u0430 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430?<\/p>\n<p><strong>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0443,<\/strong> \u0433\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0440\u0435\u0434\u044b, \u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0430\u0433\u0435\u043d\u0442\u0430 \u0432 \u044d\u0442\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0443\u044e \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438.<\/p>\n<p><strong>\u0412 \u043d\u0430\u0447\u0430\u043b\u0435<\/strong> \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 <strong>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0443\u043b\u044f\u043c\u0438 \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/strong>. \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0430\u0433\u0435\u043d\u0442\u0430 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 (\u043e \u043d\u0435\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435).<\/p>\n<p>\u0410\u0433\u0435\u043d\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0438\u0437 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0447\u0430\u0441\u0442\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c  <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%96%D0%B0%D0%B4%D0%BD%D1%8B%D0%B9_%D0%B0%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC\">\u03b5-\u0436\u0430\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438,<\/a> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0435\u0439 \u0443\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0440\u0435\u0434\u0430 \u0441 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 <em>S1, S2, S3, S4<\/em> \u0438 \u0434\u0432\u0443\u043c\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 <em>A1, A2<\/em> \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438. Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0440\u0435\u0434\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430 \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\/\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435<\/p>\n<\/th>\n<th>\n<p>A1<\/p>\n<\/th>\n<th>\n<p>A2<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S1<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.5<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S2<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.1<\/p>\n<\/td>\n<td>\n<p align=\"left\">-0.4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S3<\/p>\n<\/td>\n<td>\n<p align=\"left\">-0.2<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.0<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S4<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.6<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.3<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0443\u044e \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u0437\u0430 \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f A1 \u0438\u043b\u0438 A2 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0.5 \u0432 \u044f\u0447\u0435\u0439\u043a\u0435 S1, A1 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0430\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u0430 \u0437\u0430 \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f A1 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 S1 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 0.5. \u0421 \u0442\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u043e \u043c\u0435\u0440\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0433\u0435\u043d\u0442\u0430, \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u043e\u0442\u0440\u0430\u0436\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u044b\u0442 \u0438 \u0443\u0442\u043e\u0447\u043d\u044f\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u043d\u0430\u0433\u0440\u0430\u0434.<\/p>\n<p><strong>\u0422\u0430\u043a \u0432\u043e\u0442&#8230;<\/strong><\/p>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0430\u0433\u0435\u043d\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <strong>\u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430<\/strong>, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. <\/p>\n<p>\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438\u0437 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u042d\u0442\u0438 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0430\u0433\u0435\u043d\u0442\u0430, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0431\u0449\u0435\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u043d\u0430\u0433\u0440\u0430\u0434\u044b.<\/p>\n<p>\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0434\u043b\u044f Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043e \u043a\u0430\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"Q(s, a) = r + \\gamma \\max_{a'}Q(s', a')\" alt=\"Q(s, a) = r + \\gamma \\max_{a'}Q(s', a')\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/31c\/99a\/14f\/31c99a14ff324d81cbfc50f8d4f6d75f.svg\" width=\"238\" height=\"34\"\/><\/p>\n<p>\u0413\u0434\u0435:<\/p>\n<ul>\n<li>\n<p><em>Q(s, a)<\/em> \u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f,<\/p>\n<\/li>\n<li>\n<p><em>r<\/em> \u2014 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f <em>a<\/em> \u0438\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <em>s<\/em>,<\/p>\n<\/li>\n<li>\n<p><em>\u03b3<\/em>   \u2014 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0434\u0438\u0441\u043a\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043d\u0430\u0433\u0440\u0430\u0434 (\u043e\u0431\u044b\u0447\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 0 \u0438 1),<\/p>\n<\/li>\n<li>\n<p>\u0410 max \u0438 \u0432\u0441\u0435 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e  \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <em>a&#8217;<\/em> \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <em>s&#8217;<\/em>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0430\u0433\u0435\u043d\u0442\u0443 \u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f \u0441\u0432\u043e\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0431\u0443\u0434\u0443\u0449\u0438\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439. <\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 Python<\/h3>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0447\u0438\u0441\u0442\u044b\u043c \u043d\u0430\u043c\u043f\u0430\u0435\u043c, \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u0435\u0442\u043a\u0438 3&#215;3:  <\/p>\n<pre><code class=\"python\">import numpy as np  # \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b Q = np.zeros([3, 3])  # \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 alpha = 0.1  # \u043a\u043e\u044d\u0444. \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f gamma = 0.9  # \u043a\u043e\u044d\u0444. \u0434\u0438\u0441\u043a\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f epsilon = 0.1  # \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f vs. \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438  # \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b  for episode in range(1000):  # \u043a\u043e\u043b\u0432\u043e \u044d\u043f\u0438\u0437\u043e\u0434\u043e\u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f     state = np.random.randint(0, 3)  # \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435          while state != 2:  # \u043f\u043e\u043a\u0430 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442\u0430 \u0446\u0435\u043b\u044c         # \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f         if np.random.rand() &lt; epsilon:             action = np.random.randint(0, 3)  # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435         else:             action = np.argmax(Q[state])                   # \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b         new_state = action         reward = -1 if new_state != 2 else 0  # \u043d\u0430\u0433\u0440\u0430\u0434\u0430 -1 \u0437\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433, 0 \u0437\u0430 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0438                  # \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f         Q[state, action] = (1 - alpha) * Q[state, action] + alpha * (reward + gamma * np.max(Q[new_state]))                  state = new_state  print(\"Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430:\") print(Q)<\/code><\/pre>\n<pre><code>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430: [[-0.6861894  -0.71757046  0.        ]  [-0.74581342 -0.81469798  0.        ]  [ 0.          0.          0.        ]]<\/code><\/pre>\n<p>Q-learning \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0440\u0435\u0434\u044b <a href=\"https:\/\/store.steampowered.com\/app\/396890\/Gridworld\/\">Gridworld<\/a>:<\/p>\n<pre><code class=\"python\">import numpy as np  # \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0440\u0435\u0434\u044b (Gridworld) class Gridworld:     def __init__(self):         self.grid_size = (4, 4)         self.num_actions = 4         self.goal_state = (3, 3)          def reset(self):         self.agent_pos = (0, 0)         return self.agent_pos          def step(self, action):         if action == 0:  # \u0412\u0432\u0435\u0440\u0445             self.agent_pos = (max(0, self.agent_pos[0] - 1), self.agent_pos[1])         elif action == 1:  # \u0412\u043d\u0438\u0437             self.agent_pos = (min(self.grid_size[0] - 1, self.agent_pos[0] + 1), self.agent_pos[1])         elif action == 2:  # \u0412\u043b\u0435\u0432\u043e             self.agent_pos = (self.agent_pos[0], max(0, self.agent_pos[1] - 1))         elif action == 3:  # \u0412\u043f\u0440\u0430\u0432\u043e             self.agent_pos = (self.agent_pos[0], min(self.grid_size[1] - 1, self.agent_pos[1] + 1))                  reward = -1 if self.agent_pos != self.goal_state else 0         done = self.agent_pos == self.goal_state         return self.agent_pos, reward, done  # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b Q = np.zeros((4, 4, 4))  # \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f alpha = 0.1 gamma = 0.99 epsilon = 0.1 num_episodes = 1000  # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 env = Gridworld() for i in range(num_episodes):     state = env.reset()     done = False     while not done:         if np.random.rand() &lt; epsilon:             action = np.random.randint(0, env.num_actions)  # \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435         else:             action = np.argmax(Q[state[0], state[1], :])  # \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c                  next_state, reward, done = env.step(action)         Q[state[0], state[1], action] = (1 - alpha) * Q[state[0], state[1], action] + alpha * (reward + gamma * np.max(Q[next_state[0], next_state[1], :]))                  state = next_state  print(\"Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430:\") print(Q)<\/code><\/pre>\n<pre><code>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430: [[[-5.63733656 -4.90099172 -5.78723972 -4.90099167]   [-4.53658863 -3.9403968  -5.34673741 -3.94039681]   [-3.58282726 -2.97009883 -3.97937951 -2.97009888]   [-2.37438071 -1.98999995 -2.93539914 -2.21899042]]   [[-5.27339855 -3.9403967  -4.51348278 -3.94039674]   [-3.86562705 -2.97009964 -4.10058156 -2.97009964]   [-2.75481593 -1.98999997 -2.33378391 -1.98999997]   [-2.12960968 -1.         -2.06496437 -1.56168583]]   [[-4.18589727 -2.97009877 -3.28672302 -2.97009878]   [-3.13003944 -1.98999995 -3.10226658 -1.98999994]   [-2.51335353 -1.         -2.29706595 -1.        ]   [-1.5997738   0.         -1.40803817 -0.81469798]]   [[-2.87489189 -2.15624595 -2.15161794 -1.98999995]   [-1.23354402 -1.45941412 -2.08135222 -1.        ]   [-1.25371027 -0.77123208 -1.45474141  0.        ]   [ 0.          0.          0.          0.        ]]]<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0447\u0430\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u0431\u0443 gym \u043e\u0442 OpenAI. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c taxi:<\/p>\n<pre><code class=\"python\">import gym import numpy as np  env = gym.make('Taxi-v3')  alpha = 0.1  gamma = 0.99   epsilon = 0.1    # Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 num_states = env.observation_space.n num_actions = env.action_space.n Q = np.zeros((num_states, num_actions))  # \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0430\u0433\u0435\u043d\u0442\u0430 num_episodes = 1000 for episode in range(num_episodes):     state = env.reset()     done = False     while not done:         # \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f         if np.random.rand() &lt; epsilon:             action = env.action_space.sample()  # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f         else:             action = np.argmax(Q[state])  # \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043d\u0430\u0438\u0432\u044b\u0441\u0448\u0438\u043c Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c                      # \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b         next_state, reward, done, _ = env.step(action)                  # \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430         Q[state, action] = (1 - alpha) * Q[state, action] + alpha * (reward + gamma * np.max(Q[next_state]))                  # \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e         state = next_state      print(\"Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430:\") print(Q)<\/code><\/pre>\n<pre><code>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430: [[ 0.          0.          0.          0.          0.          0.        ]  [-4.37743896 -4.30379883 -4.52970509 -4.37685397  1.29064633 -7.46319523]  [-1.66879694 -0.44507461 -2.07826517 -1.23688895 13.8078767  -2.43668637]  ...  [-1.07785638 -0.74885187 -0.99551198 -0.99053731 -1.         -1.        ]  [-2.74269569 -2.73474617 -2.73781084 -2.76714114 -3.95870558 -4.68360176]  [-0.1999     -0.19       -0.1         6.47055995 -1.9        -1.        ]]<\/code><\/pre>\n<hr\/>\n<p><em>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 <\/em><a href=\"https:\/\/otus.pw\/5Twn\/\"><em>\u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432 \u043e\u0442 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432 OTUS<\/em><\/a><em> \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e. \u0422\u0430\u043a\u0436\u0435 \u0432 <\/em><a href=\"https:\/\/otus.pw\/qoVR\/\"><em>\u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u0435 \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u0439 <\/em><\/a><em>\u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f <\/em><a href=\"https:\/\/otus.pw\/qoVR\/\"><em>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0432\u0435\u0431\u0438\u043d\u0430\u0440<\/em><\/a><em>.<\/em><\/p>\n<\/p>\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\/articles\/803041\/\"> https:\/\/habr.com\/ru\/articles\/803041\/<\/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<figure class=\"full-width\"><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/p>\n<p><strong>Q-learning<\/strong> \u2014 \u044d\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u0434\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0430\u0433\u0435\u043d\u0442\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435, \u0441\u0442\u0440\u0435\u043c\u044f\u0441\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043d\u0430\u0433\u0440\u0430\u0434. \u0410\u0433\u0435\u043d\u0442 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0440\u0435\u0434\u0443, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043e\u043f\u044b\u0442\u0435, \u0430 \u043d\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0438\u0440\u0430.<\/p>\n<p><em>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c.<\/em><\/p>\n<h3>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b<\/h3>\n<p><strong>\u0410\u0433\u0435\u043d\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/strong> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <strong>\u0438\u0437 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435&#8230;.\u0421\u0442\u043e\u043f..\u0447\u0442\u043e \u0437\u0430 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430?<\/p>\n<p><strong>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0443,<\/strong> \u0433\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0440\u0435\u0434\u044b, \u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0430\u0433\u0435\u043d\u0442\u0430 \u0432 \u044d\u0442\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0443\u044e \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438.<\/p>\n<p><strong>\u0412 \u043d\u0430\u0447\u0430\u043b\u0435<\/strong> \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 <strong>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0443\u043b\u044f\u043c\u0438 \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/strong>. \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0430\u0433\u0435\u043d\u0442\u0430 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 (\u043e \u043d\u0435\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435).<\/p>\n<p>\u0410\u0433\u0435\u043d\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0438\u0437 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0447\u0430\u0441\u0442\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c  <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%96%D0%B0%D0%B4%D0%BD%D1%8B%D0%B9_%D0%B0%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC\">\u03b5-\u0436\u0430\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438,<\/a> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0435\u0439 \u0443\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0440\u0435\u0434\u0430 \u0441 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 <em>S1, S2, S3, S4<\/em> \u0438 \u0434\u0432\u0443\u043c\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 <em>A1, A2<\/em> \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438. Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0440\u0435\u0434\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430 \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\/\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435<\/p>\n<\/th>\n<th>\n<p>A1<\/p>\n<\/th>\n<th>\n<p>A2<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S1<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.5<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S2<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.1<\/p>\n<\/td>\n<td>\n<p align=\"left\">-0.4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S3<\/p>\n<\/td>\n<td>\n<p align=\"left\">-0.2<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.0<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">S4<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.6<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.3<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0443\u044e \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u0437\u0430 \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f A1 \u0438\u043b\u0438 A2 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0.5 \u0432 \u044f\u0447\u0435\u0439\u043a\u0435 S1, A1 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0430\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u0430 \u0437\u0430 \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f A1 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 S1 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 0.5. \u0421 \u0442\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u043e \u043c\u0435\u0440\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0433\u0435\u043d\u0442\u0430, \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u043e\u0442\u0440\u0430\u0436\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u044b\u0442 \u0438 \u0443\u0442\u043e\u0447\u043d\u044f\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0445 \u043d\u0430\u0433\u0440\u0430\u0434.<\/p>\n<p><strong>\u0422\u0430\u043a \u0432\u043e\u0442&#8230;<\/strong><\/p>\n<p>\u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0430\u0433\u0435\u043d\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <strong>\u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430<\/strong>, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. <\/p>\n<p>\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438\u0437 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u042d\u0442\u0438 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0430\u0433\u0435\u043d\u0442\u0430, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0431\u0449\u0435\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u043d\u0430\u0433\u0440\u0430\u0434\u044b.<\/p>\n<p>\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u0434\u043b\u044f Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043e \u043a\u0430\u043a:<\/p>\n<p>\u0413\u0434\u0435:<\/p>\n<ul>\n<li>\n<p><em>Q(s, a)<\/em> \u2014 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f,<\/p>\n<\/li>\n<li>\n<p><em>r<\/em> \u2014 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u0430\u0433\u0440\u0430\u0434\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f <em>a<\/em> \u0438\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <em>s<\/em>,<\/p>\n<\/li>\n<li>\n<p><em>\u03b3<\/em>   \u2014 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0434\u0438\u0441\u043a\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043d\u0430\u0433\u0440\u0430\u0434 (\u043e\u0431\u044b\u0447\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 0 \u0438 1),<\/p>\n<\/li>\n<li>\n<p>\u0410 max \u0438 \u0432\u0441\u0435 \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e  \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <em>a&#8217;<\/em> \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <em>s&#8217;<\/em>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0430\u0433\u0435\u043d\u0442\u0443 \u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f \u0441\u0432\u043e\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0431\u0443\u0434\u0443\u0449\u0438\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b. <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439. <\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 Python<\/h3>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0447\u0438\u0441\u0442\u044b\u043c \u043d\u0430\u043c\u043f\u0430\u0435\u043c, \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u0435\u0442\u043a\u0438 3&#215;3:  <\/p>\n<pre><code class=\"python\">import numpy as np  # \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b Q = np.zeros([3, 3])  # \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 alpha = 0.1  # \u043a\u043e\u044d\u0444. \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f gamma = 0.9  # \u043a\u043e\u044d\u0444. \u0434\u0438\u0441\u043a\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f epsilon = 0.1  # \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f vs. \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438  # \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b  for episode in range(1000):  # \u043a\u043e\u043b\u0432\u043e \u044d\u043f\u0438\u0437\u043e\u0434\u043e\u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f     state = np.random.randint(0, 3)  # \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435          while state != 2:  # \u043f\u043e\u043a\u0430 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442\u0430 \u0446\u0435\u043b\u044c         # \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f         if np.random.rand() &lt; epsilon:             action = np.random.randint(0, 3)  # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435         else:             action = np.argmax(Q[state])                   # \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b         new_state = action         reward = -1 if new_state != 2 else 0  # \u043d\u0430\u0433\u0440\u0430\u0434\u0430 -1 \u0437\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433, 0 \u0437\u0430 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0438                  # \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f         Q[state, action] = (1 - alpha) * Q[state, action] + alpha * (reward + gamma * np.max(Q[new_state]))                  state = new_state  print(\"Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430:\") print(Q)<\/code><\/pre>\n<pre><code>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430: [[-0.6861894  -0.71757046  0.        ]  [-0.74581342 -0.81469798  0.        ]  [ 0.          0.          0.        ]]<\/code><\/pre>\n<p>Q-learning \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0440\u0435\u0434\u044b <a href=\"https:\/\/store.steampowered.com\/app\/396890\/Gridworld\/\">Gridworld<\/a>:<\/p>\n<pre><code class=\"python\">import numpy as np  # \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0440\u0435\u0434\u044b (Gridworld) class Gridworld:     def __init__(self):         self.grid_size = (4, 4)         self.num_actions = 4         self.goal_state = (3, 3)          def reset(self):         self.agent_pos = (0, 0)         return self.agent_pos          def step(self, action):         if action == 0:  # \u0412\u0432\u0435\u0440\u0445             self.agent_pos = (max(0, self.agent_pos[0] - 1), self.agent_pos[1])         elif action == 1:  # \u0412\u043d\u0438\u0437             self.agent_pos = (min(self.grid_size[0] - 1, self.agent_pos[0] + 1), self.agent_pos[1])         elif action == 2:  # \u0412\u043b\u0435\u0432\u043e             self.agent_pos = (self.agent_pos[0], max(0, self.agent_pos[1] - 1))         elif action == 3:  # \u0412\u043f\u0440\u0430\u0432\u043e             self.agent_pos = (self.agent_pos[0], min(self.grid_size[1] - 1, self.agent_pos[1] + 1))                  reward = -1 if self.agent_pos != self.goal_state else 0         done = self.agent_pos == self.goal_state         return self.agent_pos, reward, done  # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Q-\u0442\u0430\u0431\u043b\u0438\u0446\u044b Q = np.zeros((4, 4, 4))  # \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f alpha = 0.1 gamma = 0.99 epsilon = 0.1 num_episodes = 1000  # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 env = Gridworld() for i in range(num_episodes):     state = env.reset()     done = False     while not done:         if np.random.rand() &lt; epsilon:             action = np.random.randint(0, env.num_actions)  # \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435         else:             action = np.argmax(Q[state[0], state[1], :])  # \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c                  next_state, reward, done = env.step(action)         Q[state[0], state[1], action] = (1 - alpha) * Q[state[0], state[1], action] + alpha * (reward + gamma * np.max(Q[next_state[0], next_state[1], :]))                  state = next_state  print(\"Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430:\") print(Q)<\/code><\/pre>\n<pre><code>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430: [[[-5.63733656 -4.90099172 -5.78723972 -4.90099167]   [-4.53658863 -3.9403968  -5.34673741 -3.94039681]   [-3.58282726 -2.97009883 -3.97937951 -2.97009888]   [-2.37438071 -1.98999995 -2.93539914 -2.21899042]]   [[-5.27339855 -3.9403967  -4.51348278 -3.94039674]   [-3.86562705 -2.97009964 -4.10058156 -2.97009964]   [-2.75481593 -1.98999997 -2.33378391 -1.98999997]   [-2.12960968 -1.         -2.06496437 -1.56168583]]   [[-4.18589727 -2.97009877 -3.28672302 -2.97009878]   [-3.13003944 -1.98999995 -3.10226658 -1.98999994]   [-2.51335353 -1.         -2.29706595 -1.        ]   [-1.5997738   0.         -1.40803817 -0.81469798]]   [[-2.87489189 -2.15624595 -2.15161794 -1.98999995]   [-1.23354402 -1.45941412 -2.08135222 -1.        ]   [-1.25371027 -0.77123208 -1.45474141  0.        ]   [ 0.          0.          0.          0.        ]]]<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0447\u0430\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u0431\u0443 gym \u043e\u0442 OpenAI. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c taxi:<\/p>\n<pre><code class=\"python\">import gym import numpy as np  env = gym.make('Taxi-v3')  alpha = 0.1  gamma = 0.99   epsilon = 0.1    # Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 num_states = env.observation_space.n num_actions = env.action_space.n Q = np.zeros((num_states, num_actions))  # \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0430\u0433\u0435\u043d\u0442\u0430 num_episodes = 1000 for episode in range(num_episodes):     state = env.reset()     done = False     while not done:         # \u0432\u044b\u0431\u043e\u0440 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f         if np.random.rand() &lt; epsilon:             action = env.action_space.sample()  # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f         else:             action = np.argmax(Q[state])  # \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043d\u0430\u0438\u0432\u044b\u0441\u0448\u0438\u043c Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c                      # \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0433\u0440\u0430\u0434\u044b         next_state, reward, done, _ = env.step(action)                  # \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 Q-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0411\u0435\u043b\u043b\u043c\u0430\u043d\u0430         Q[state, action] = (1 - alpha) * Q[state, action] + alpha * (reward + gamma * np.max(Q[next_state]))                  # \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e         state = next_state      print(\"Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430:\") print(Q)<\/code><\/pre>\n<pre><code>Q-\u0442\u0430\u0431\u043b\u0438\u0446\u0430: [[ 0.          0.          0.          0.          0.          0.        ]  [-4.37743896 -4.30379883 -4.52970509 -4.37685397  1.29064633 -7.46319523]  [-1.66879694 -0.44507461 -2.07826517 -1.23688895 13.8078767  -2.43668637]  ...  [-1.07785638 -0.74885187 -0.99551198 -0.99053731 -1.         -1.        ]  [-2.74269569 -2.73474617 -2.73781084 -2.76714114 -3.95870558 -4.68360176]  [-0.1999     -0.19       -0.1         6.47055995 -1.9        -1.        ]]<\/code><\/pre>\n<hr\/>\n<p><em>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 <\/em><a href=\"https:\/\/otus.pw\/5Twn\/\"><em>\u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432 \u043e\u0442 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432 OTUS<\/em><\/a><em> \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e. \u0422\u0430\u043a\u0436\u0435 \u0432 <\/em><a href=\"https:\/\/otus.pw\/qoVR\/\"><em>\u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u0435 \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u0439 <\/em><\/a><em>\u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0432\u0448\u0438\u0439\u0441\u044f <\/em><a href=\"https:\/\/otus.pw\/qoVR\/\"><em>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0432\u0435\u0431\u0438\u043d\u0430\u0440<\/em><\/a><em>.<\/em><\/p>\n<\/p>\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\/articles\/803041\/\"> https:\/\/habr.com\/ru\/articles\/803041\/<\/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-371885","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371885","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=371885"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371885\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}