{"id":336082,"date":"2022-07-24T03:00:05","date_gmt":"2022-07-24T03:00:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=336082"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=336082","title":{"rendered":"<span>\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0412\u0438\u0442\u0435\u0440\u0431\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>\u0420\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0451\u0442 \u043e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u0412\u0438\u0442\u0435\u0440\u0431\u0438, \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u043e \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u043c \u0438\u0445 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0435 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0438.  <\/p>\n<p>\u0414\u043b\u044f \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u0430\u043d\u044b \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u044b: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u044b\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u043e\u0432. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/e08\/587\/562\/e08587562c4b602200b02649e5e9da5f.jpg\" alt=\"https:\/\/towardsdatascience.com\/markov-chains-and-hmms-ceaf2c854788\" title=\"https:\/\/towardsdatascience.com\/markov-chains-and-hmms-ceaf2c854788\" width=\"3127\" height=\"2505\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e08\/587\/562\/e08587562c4b602200b02649e5e9da5f.jpg\" data-blurred=\"true\"\/><figcaption>https:\/\/towardsdatascience.com\/markov-chains-and-hmms-ceaf2c854788<\/figcaption><\/figure>\n<p>\u0415\u0433\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0443\u0442\u044c:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/845\/ba5\/06b\/845ba506b584d482f5ab390b741f78aa.png\" width=\"367\" height=\"27\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/845\/ba5\/06b\/845ba506b584d482f5ab390b741f78aa.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0433\u0434\u0435 x- \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, y &#8212; \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, f &#8212; \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<p>\u0421 \u0443\u0447\u0451\u0442\u043e\u043c \u0411\u0430\u0439\u0435\u0441\u0430 \u044d\u0442\u0443 \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/9d8\/673\/cd1\/9d8673cd116ed61d9715b391289707b7.jpg\" width=\"367\" height=\"81\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d8\/673\/cd1\/9d8673cd116ed61d9715b391289707b7.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<ul>\n<li>\n<p><strong>P(F)<\/strong>: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f F (\u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0432 \u0412\u0438\u0442\u0435\u0440\u0431\u0438) <\/p>\n<\/li>\n<li>\n<p><strong>P(X|F)<\/strong>: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0425 (\u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0412\u0438\u0442\u0435\u0440\u0431\u0438)  \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f F <\/p>\n<\/li>\n<li>\n<p><strong>P(Y|X)<\/strong>: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Y (\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0432 \u0412\u0438\u0442\u0435\u0440\u0431\u0438) \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f X <\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435, \u043f\u0440\u0438 \u0434\u043e\u043f\u0443\u0449\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u0442\u0438\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0435, <strong>P(Y)=P(F)*P(X|F)*P(Y|X)<\/strong> \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0432\u044b\u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 Y. \u0418\u0434\u0435\u0439\u043d\u043e \u044d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u043c\u043e\u0434\u0443\u0441 \u043f\u043e\u043d\u0435\u043d\u0441. \u0417\u043d\u0430\u044f F, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c Y.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/699\/dab\/d4d\/699dabd4d2923f028a9a57c552bb4598.jpg\" width=\"408\" height=\"91\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/699\/dab\/d4d\/699dabd4d2923f028a9a57c552bb4598.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0425\u043e\u0442\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0412\u0438\u0442\u0435\u0440\u0431\u0438, \u0440\u0435\u0448\u0430\u044e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435 \u0441\u0445\u043e\u0436\u0438\u0435\u00a0 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443 \u043d\u0438\u0445 \u0440\u0430\u0437\u043d\u043e\u0435. \u0421 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0432\u0430\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043d\u0435\u0432\u0430\u0436\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u0430\u043a \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439) \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0439. \u0427\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb. \u0421\u0443\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u043e \u0432 \u0441\u0438\u043b\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430 \u0440\u0430\u0432\u043d\u044b\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u0435 \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0435, \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u0430.  <\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043d\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0447\u0442\u043e \u043e\u043d \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0418\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0421 \u0443\u0447\u0451\u0442\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u0430\u043a \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.  <\/p>\n<pre><code>#\u041f\u0443\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0442\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0432\u043b\u0438\u044f\u044e\u0442 \u043b\u0438 \u043e\u043d\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 [1, 2, 1, 1, 2, 2, 1, 2, 2, 1] [3, 4, 4, 3, 3, 4, 3, 3, 4, 3] [5, 6, 5, 6, 5, 6, 5, 6, 5, 5]<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439. \u0418 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438. \u0412\u0438\u0434\u043d\u043e \u043f\u043e \u0432\u044b\u0432\u043e\u0434\u0443 \u043d\u0438\u0436\u0435, \u0447\u0442\u043e [3, 4, 4, 3, 3, 4, 3, 3, 4, 3] \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 [1, 2, 1, 1, 2, 2, 1, 2, 2, 1]. \u041e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043f\u0430\u0440\u044b 100%. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 &#8212; \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0432 \u0442\u0430\u043a\u043e\u043c \u0433\u0440\u0430\u0444\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/004\/bea\/5f1\/004bea5f1110ba607e69190bc605cd38.jpg\" width=\"669\" height=\"555\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/004\/bea\/5f1\/004bea5f1110ba607e69190bc605cd38.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0412\u0438\u0442\u0435\u0440\u0431\u0438. \u0415\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0442\u0435 \u0436\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u043e \u043d\u0430\u043b\u0438\u0446\u043e \u043e\u0448\u0438\u0431\u043a\u0438 2\/6.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/b37\/1ae\/66c\/b371ae66ceb4858114364ebb32ad2a45.jpg\" width=\"748\" height=\"170\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b37\/1ae\/66c\/b371ae66ceb4858114364ebb32ad2a45.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a <a href=\"https:\/\/towardsdatascience.com\/markov-chains-and-hmms-ceaf2c854788\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u043c. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0438\u0437\u043a\u0438\u0439. \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u0434\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u044c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/d85\/f8a\/f25\/d85f8af25d4f9736d1eff34ab8eebeb3.jpg\" alt=\"e\" title=\"e\" width=\"1022\" height=\"361\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d85\/f8a\/f25\/d85f8af25d4f9736d1eff34ab8eebeb3.jpg\" data-blurred=\"true\"\/><figcaption>e<\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u0432\u0430\u0436\u043d\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044f\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0439. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/de4\/ebb\/5ff\/de4ebb5ff193bf3d28b42ce07df802f8.jpg\" width=\"922\" height=\"382\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/de4\/ebb\/5ff\/de4ebb5ff193bf3d28b42ce07df802f8.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043a\u043d\u0438\u0433\u0438 \u042d\u0448\u0431\u0438 \u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438. \u041d\u0438 \u0442\u0430, \u043d\u0438 \u0434\u0440\u0443\u0433\u0430\u044f \u0435\u044e \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f. \u041f\u043e\u0441\u043b\u0435 (Holidays, Work) Holidays \u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0442\u043e\u0439 \u0435\u0435 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c85\/6fd\/97f\/c856fd97faf6bc511e707c471bd86090.jpg\" width=\"669\" height=\"145\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c85\/6fd\/97f\/c856fd97faf6bc511e707c471bd86090.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0435 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u044d\u0442\u0438\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0422\u0430\u043a\u0436\u0435 \u043e\u043d \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u043c \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u043b\u0438\u0448\u0435\u043d \u044d\u0442\u0438\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432, \u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443 \u043d\u0435\u0433\u043e \u0438\u043d\u043e\u0435: \u043e\u043d \u043d\u0430\u0446\u0435\u043b\u0435\u043d \u043d\u0430 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u0435\u043d\u0438\u0439. <\/p>\n<pre><code>import random import matplotlib.pyplot as plt  class Hd(): def __init__(self, graph): self.graph = graph  def rnd_get(self, v): return random.choice(v.split(\"|\"))  def show(self, graph): for x in graph: print(x, \":\", graph[x])  def get_ku(self, graph): '''return (\u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0437\u043c\u0435\u0440)''' n = 0; u = 0 for x in graph: for y in graph[x]: if y[0]: u += y[0].count(\"|\") n += 1 if n != 0: return (round(1- u\/(n+u), 3), n)  else: return (None, None)  def get_states(self, x, f_list = [], n=11): ''' \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435     \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439''' x_list = [] x_list.append(x)  if f_list != []: for f in f_list: xf = [xf for xf in g[x] if xf[1] == f] if not xf: x_list.append(''); f_list[len(x_list)-2] = '' return (x_list, f_list[:len(x_list)-1]) x = self.rnd_get(xf[0][0]) x_list.append(x) else: for i in range(n): if not self.graph[x]: x_list.append(''); f_list.append('') break t = random.choice(self.graph[x]) f = t[1] x = random.choice(t[0].split('|')) x_list.append(x); f_list.append(f)  if len(f_list) == len(x_list) -1: return (x_list, f_list) else: return ([], [])  def get_yfx(self, f_list, x_list, t = True): '''\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 (x, f, y)''' if len(x_list) == len(f_list): x_list.append('')  path = [] for i in range(len(f_list)): path.append((x_list[i], f_list[i], x_list[i+1]))  if t: return path  else: p = [] for xfy in path: if xfy[2] != '': p.append(xfy[2]+'='+xfy[1]+'('+xfy[0]+')') return p  def flow(self, path, rnd=False): if not path:  return [] fl = [] for p in path: if not rnd: fl.append(p[:-1]) else: pr = list(p[:-1]) random.shuffle(pr) fl.append(tuple(pr)) return fl  def fORx(self, flow, f=0): '''\u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043f\u043e\u0442\u043e\u043a, \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0434\u0432\u0435 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b    index: f=0, x=1 or x=0, f=1''' def add_empty(): empty = [] for k in graph: for x in graph[k]: z = list(set(x[0].split('|')) - set(list(graph.keys()))) if z: empty.append(z[0]) return empty  if not flow: return []  graph = {} fli = flow[0]  for t in flow[1:]: if f == 0: if fli[1] not in graph: graph[fli[1]] = [] r = [(i, xf) for i,xf in enumerate(graph[fli[1]]) if xf[1] == fli[0]] if r: if t[1] not in r[0][1][0]: x_new = r[0][1][0] + \"|\" + t[1] if x_new != '': graph[fli[1]][r[0][0]] = (x_new, r[0][1][1]) if not r: if t[1] != '': graph[fli[1]].append((t[1], fli[0]))  if f == 1: if fli[0] not in graph: graph[fli[0]] = [] r = [(i, xf) for i,xf in enumerate(graph[fli[0]]) if xf[1] == fli[1]] if r: if t[0] not in r[0][1][0]: x_new = r[0][1][0] + \"|\" + t[0] if x_new != '': graph[fli[0]][r[0][0]] = (x_new, r[0][1][1]) if not r: if t[0] != '': graph[fli[0]].append((t[0], fli[1])) fli = t  em = add_empty() if em: graph[em[0]] = [] return graph  def merge(self, g1, g2): '''\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0434\u0432\u0430 \u0433\u0440\u0430\u0444\u0430 \u0432 \u043e\u0434\u0438\u043d''' def find_index(): for i in range(len(graph[k])): if graph[k][i][1] == x[1]: return i return -1  all_keys = set(list(g1.keys()) + list(g2.keys())) graph = {}  for k in all_keys: if k not in graph:  if k in g1: graph[k] = g1[k] else: graph[k] = g2[k]  if k in g2: for x in g2[k]: ind = find_index() if ind != -1: if x[0] != []: t1 = x[0].split('|') if graph[k][ind] != -1: t2 = graph[k][ind][0].split('|') z = \"|\".join(set(t1+t2)) xf = [z, graph[k][ind][1]] graph[k][ind] = xf else: graph[k].append(x)  return graph  class Vm(): def print_dptable(self, V): '''https:\/\/russianblogs.com\/article\/255172857\/''' for i in range(len(V)): print(\"%8d\" % i, end=\"\") print() for y in V[0].keys(): print(\"%.5s: \" % y, end=\" \") for t in range(len(V)): print(\"%.7s\" % V[t][y], end=\" \") print()   def viterbi(self, obs, states, start_p, trans_p, emit_p): '''https:\/\/russianblogs.com\/article\/255172857\/''' V = [{}] path = {} for y in states: V[0][y] = start_p[y] * emit_p[y][obs[0]] path[y] = [y]  for t in range(1, len(obs)): V.append({}) newpath = {}  for y in states: (prob, state) = max([(V[t - 1][y0] * trans_p[y0][y] * emit_p[y][obs[t]], y0) for y0 in states]) V[t][y] = prob newpath[y] = path[state] + [y] path = newpath  self.print_dptable(V) (prob, state) = max([(V[len(obs) - 1][y], y) for y in states]) return prob, path[state]   def startProbability(self, x_list): '''\u0440\u0430\u0441\u0447\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438''' start_probability = {}  for z in x_list: if z not in start_probability: start_probability[z] = 1 else: start_probability[z] +=1  start_probability = {z:start_probability[z]\/(len(x_list)) for z in start_probability} return start_probability   def transitionProbability(self, x_list): '''\u0440\u0430\u0441\u0447\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438''' transition_probability = {}  for i,z in enumerate(x_list): if z not in transition_probability: transition_probability[z] = {} if i == 0: z_old = z continue  if z not in transition_probability[z_old]: transition_probability[z_old][z] = 1 else: transition_probability[z_old][z] = transition_probability[z_old][z] +1  z_old = z  for z_old in transition_probability: z_list = [transition_probability[z_old][z] for z in transition_probability[z_old]] for z in transition_probability[z_old]: transition_probability[z_old][z] = transition_probability[z_old][z] \/ sum(z_list)  return transition_probability  def emissionProbability(self, x_list, f_list): '''\u0440\u0430\u0441\u0447\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0430''' emission_probability = {} for i,z in enumerate(x_list): if z not in emission_probability: emission_probability[z] = {} if f_list[i] not in emission_probability[z]: emission_probability[z][f_list[i]] = 1 else: emission_probability[z][f_list[i]] += 1  for z_old in emission_probability: z_list = [emission_probability[z_old][z] for z in emission_probability[z_old]] for z in emission_probability[z_old]: emission_probability[z_old][z] = emission_probability[z_old][z] \/ sum(z_list)  return emission_probability  def isMarkov(self, w_list, prev_s, s): '''\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e''' transition_probability = {}  for i,z in enumerate(w_list): if z not in transition_probability: transition_probability[z] = {} if i == 0: z_old = z continue  if z not in transition_probability[z_old]: transition_probability[z_old][z] = 1 else: transition_probability[z_old][z] = transition_probability[z_old][z] +1  z_old = z zz_old = z_old  transition_probability_ = {}  for i,z in enumerate(w_list): if z not in transition_probability_ and z == s: transition_probability_[z] = {} if i == 0: z_old = z continue if i == 1: zz_old = z_old z_old = z continue  if zz_old == prev_s and z_old == s: if z not in transition_probability_[z_old]: transition_probability_[z_old][z] = 1 else: transition_probability_[z_old][z] = transition_probability_[z_old][z] +1  zz_old = z_old z_old = z  return ((prev_s, s), transition_probability_[s], transition_probability[s])   #--------- main ---------#     if __name__ == \"__main__\": g = {} hd = Hd(g)  print(\"\\n__  \u0414\u0432\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\") x_list = [str(x) for x in [1, 2, 1, 1, 2, 2, 1, 2, 2, 1]] f_list = [str(f) for f in [3, 4, 4, 3, 3, 4, 3, 3, 4, 3]]  print(x_list) print(f_list)  path = hd.get_yfx(f_list, x_list) print(\"\\n  \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430 1: \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c - \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439\") gn = hd.fORx(hd.flow(path), f=0) hd.show(gn) ku = hd.get_ku(gn) print(\"ku =\", ku[0])  print(\"\\n  \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430 2: \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c - \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439\") gn = hd.fORx(hd.flow(path), f=1) hd.show(gn) ku = hd.get_ku(gn) print(\"ku =\", ku[0])  ########################### print(\"\\n__  \u0414\u0432\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\") x_list = [str(x) for x in [1, 2, 1, 1, 2, 2, 1, 2, 2, 1]] f_list = [str(f) for f in [5, 6, 5, 6, 5, 6, 5, 6, 5, 5]]  ''' x = \"Work   Work   Work     Holidays Holidays Holidays Work     Work Holidays Holidays Holidays Holidays Holidays Holidays Holidays\" f = \"Python Python Python   Bear     Bear     Python   Python   Bear Python   Python   Bear     Bear     Bear     Bear     Bear\" x_list = x.split() f_list = f.split() '''  print(\"  \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430 1: \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c - \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439\") path = hd.get_yfx(f_list, x_list) gn = hd.fORx(hd.flow(path), f=0) hd.show(gn) ku = hd.get_ku(gn) print(\"ku =\", ku[0])  print(\"\\n  \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430 2: \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c - \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439\") gn = hd.fORx(hd.flow(path), f=1) hd.show(gn) ku = hd.get_ku(gn) print(\"ku =\", ku[0])  print(\"\\n__\u0412\u0438\u0442\u0435\u0440\u0431\u0438\") x_list = [str(x) for x in [1, 2, 1, 1, 2, 2, 1, 2, 2, 1]] f_list = [str(f) for f in [3, 4, 4, 3, 3, 4, 3, 3, 4, 3]]  ''' x = \"Work   Work   Work     Holidays Holidays Holidays Work     Work Holidays Holidays Holidays Holidays Holidays Holidays Holidays\" f = \"Python Python Python   Bear     Bear     Python   Python   Bear Python   Python   Bear     Bear     Bear     Bear     Bear\" x_list = x.split() f_list = f.split() '''  states_x = set(x_list) states_f = set(f_list)  observations = f_list[1:7] states = states_x  vm = Vm() start_probability = vm.startProbability(x_list) transition_probability = vm.transitionProbability(x_list) emission_probability = vm.emissionProbability(x_list, f_list)  r = vm.viterbi(observations,            states,            start_probability,            transition_probability,            emission_probability)      print(\"\\n\", observations, \"#\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439\") print(x_list[1:7], \"#\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 (\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b)\") print(r[1], \"#\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 (\u0432\u0438\u0442\u0435\u0440\u0431\u0438)\")   print(\"\\n__isMarkov\") w = 'A A B B A B B A A B B A B B A B B A B B A A B B A B B A B A B A' w_list = w.split() r = vm.isMarkov(w_list, 'A', 'B') print(*r) r = vm.isMarkov(w_list, 'B', 'B') print(*r, \"\\n\") w = \"Work   Work   Work     Holidays Holidays Holidays Work     Work Holidays Holidays Holidays Holidays Holidays Holidays Holidays\" w_list = w.split() r = vm.isMarkov(w_list, 'Holidays', 'Work') print(*r) r = vm.isMarkov(w_list, 'Work', 'Work') print(*r, \"\\n\") <\/code><\/pre>\n<\/p>\n<p>P.S. \u0414\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 [1, 2, 1, 1, 2, 2, 1, 2, 2, 1], [3, 4, 4, 3, 3, 4, 3, 3, 4, 3] \u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0433\u0440\u0430\u0444\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a, \u0433\u0434\u0435 \u043f\u0443\u043d\u043a\u0442\u0438\u0440\u043d\u043e\u0439 \u043b\u0438\u043d\u0438\u0438 \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0430. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b 0,67, \u0442.\u043a \u0432\u0441\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 2+1+2+1, \u0430 \u0435\u0441\u043b\u0438 \u0431\u044b \u0431\u044b\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b, \u0442\u043e 4.<\/p>\n<ul>\n<li>\n<p>4|3 = 1(3)  # \u0438\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f 3 \u043f\u0440\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 1 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043b\u0438\u0431\u043e 4, \u043b\u0438\u0431\u043e 3<\/p>\n<\/li>\n<li>\n<p>4 = 2(3) # \u0438\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f 3 \u043f\u0440\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 2 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 4.<\/p>\n<\/li>\n<li>\n<p>4|3 = 2(4)<\/p>\n<\/li>\n<li>\n<p>3 = 1(4)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/eda\/390\/0d1\/eda3900d1e97372683c3b931fb059318.jpg\" width=\"885\" height=\"279\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eda\/390\/0d1\/eda3900d1e97372683c3b931fb059318.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/678604\/\"> https:\/\/habr.com\/ru\/post\/678604\/<\/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>\u0420\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0451\u0442 \u043e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u0412\u0438\u0442\u0435\u0440\u0431\u0438, \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u043e \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u043c \u0438\u0445 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0435 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0438.  <\/p>\n<p>\u0414\u043b\u044f \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u0430\u043d\u044b \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u044b: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u043a\u0440\u044b\u0442\u044b\u0445 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u044b\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u043e\u0432. <\/p>\n<figure class=\"full-width\"><figcaption>https:\/\/towardsdatascience.com\/markov-chains-and-hmms-ceaf2c854788<\/figcaption><\/figure>\n<p>\u0415\u0433\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0443\u0442\u044c:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0433\u0434\u0435 x- \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, y &#8212; \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, f &#8212; \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<p>\u0421 \u0443\u0447\u0451\u0442\u043e\u043c \u0411\u0430\u0439\u0435\u0441\u0430 \u044d\u0442\u0443 \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<ul>\n<li>\n<p><strong>P(F)<\/strong>: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f F (\u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0432 \u0412\u0438\u0442\u0435\u0440\u0431\u0438) <\/p>\n<\/li>\n<li>\n<p><strong>P(X|F)<\/strong>: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0425 (\u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0412\u0438\u0442\u0435\u0440\u0431\u0438)  \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f F <\/p>\n<\/li>\n<li>\n<p><strong>P(Y|X)<\/strong>: \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Y (\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043a\u0440\u044b\u0442\u043e\u0435 \u0432 \u0412\u0438\u0442\u0435\u0440\u0431\u0438) \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f X <\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435, \u043f\u0440\u0438 \u0434\u043e\u043f\u0443\u0449\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u0442\u0438\u0445 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0435, <strong>P(Y)=P(F)*P(X|F)*P(Y|X)<\/strong> \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0432\u044b\u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 Y. \u0418\u0434\u0435\u0439\u043d\u043e \u044d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u043c\u043e\u0434\u0443\u0441 \u043f\u043e\u043d\u0435\u043d\u0441. \u0417\u043d\u0430\u044f F, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c Y.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0425\u043e\u0442\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0412\u0438\u0442\u0435\u0440\u0431\u0438, \u0440\u0435\u0448\u0430\u044e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435 \u0441\u0445\u043e\u0436\u0438\u0435\u00a0 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443 \u043d\u0438\u0445 \u0440\u0430\u0437\u043d\u043e\u0435. \u0421 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0432\u0430\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043d\u0435\u0432\u0430\u0436\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u0430\u043a \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439) \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0439. \u0427\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb. \u0421\u0443\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u043e \u0432 \u0441\u0438\u043b\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430 \u0440\u0430\u0432\u043d\u044b\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u0435 \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0435, \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u0430.  <\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043d\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0447\u0442\u043e \u043e\u043d \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0418\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0421 \u0443\u0447\u0451\u0442\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u0430\u043a \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.  <\/p>\n<pre><code>#\u041f\u0443\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0442\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0432\u043b\u0438\u044f\u044e\u0442 \u043b\u0438 \u043e\u043d\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 [1, 2, 1, 1, 2, 2, 1, 2, 2, 1] [3, 4, 4, 3, 3, 4, 3, 3, 4, 3] [5, 6, 5, 6, 5, 6, 5, 6, 5, 5]<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439. \u0418 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438. \u0412\u0438\u0434\u043d\u043e \u043f\u043e \u0432\u044b\u0432\u043e\u0434\u0443 \u043d\u0438\u0436\u0435, \u0447\u0442\u043e [3, 4, 4, 3, 3, 4, 3, 3, 4, 3] \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 [1, 2, 1, 1, 2, 2, 1, 2, 2, 1]. \u041e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u043f\u0430\u0440\u044b 100%. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 &#8212; \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0432 \u0442\u0430\u043a\u043e\u043c \u0433\u0440\u0430\u0444\u0435.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0412\u0438\u0442\u0435\u0440\u0431\u0438. \u0415\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0442\u0435 \u0436\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0442\u043e \u043d\u0430\u043b\u0438\u0446\u043e \u043e\u0448\u0438\u0431\u043a\u0438 2\/6.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a <a href=\"https:\/\/towardsdatascience.com\/markov-chains-and-hmms-ceaf2c854788\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u043c. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0438\u0437\u043a\u0438\u0439. \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u0434\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u044c.<\/p>\n<figure class=\"full-width\"><figcaption>e<\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u0432\u0430\u0436\u043d\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044f\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0439. <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043a\u043d\u0438\u0433\u0438 \u042d\u0448\u0431\u0438 \u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438. \u041d\u0438 \u0442\u0430, \u043d\u0438 \u0434\u0440\u0443\u0433\u0430\u044f \u0435\u044e \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f. \u041f\u043e\u0441\u043b\u0435 (Holidays, Work) Holidays \u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0442\u043e\u0439 \u0435\u0435 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0412\u0438\u0442\u0435\u0440\u0431\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0435 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u044d\u0442\u0438\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0422\u0430\u043a\u0436\u0435 \u043e\u043d \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u043c \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u043b\u0438\u0448\u0435\u043d \u044d\u0442\u0438\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432, \u043d\u043e \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443 \u043d\u0435\u0433\u043e \u0438\u043d\u043e\u0435: \u043e\u043d \u043d\u0430\u0446\u0435\u043b\u0435\u043d \u043d\u0430 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u0435\u043d\u0438\u0439. <\/p>\n<pre><code>import random import matplotlib.pyplot as plt  class Hd(): def __init__(self, graph): self.graph = graph  def rnd_get(self, v): return random.choice(v.split(\"|\"))  def show(self, graph): for x in graph: print(x, \":\", graph[x])  def get_ku(self, graph): '''return (\u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0437\u043c\u0435\u0440)''' n = 0; u = 0 for x in graph: for y in graph[x]: if y[0]: u += y[0].count(\"|\") n += 1 if n != 0: return (round(1- u\/(n+u), 3), n)  else: return (None, None)  def get_states(self, x, f_list = [], n=11): ''' \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435     \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439''' x_list = [] x_list.append(x)  if f_list != []: for f in f_list: xf = [xf for xf in g[x] if xf[1] == f] if not xf: x_list.append(''); f_list[len(x_list)-2] = '' return (x_list, f_list[:len(x_list)-1]) x = self.rnd_get(xf[0][0]) x_list.append(x) else: for i in range(n): if not self.graph[x]: x_list.append(''); f_list.append('') break t = random.choice(self.graph[x]) f = t[1] x = random.choice(t[0].split('|')) x_list.append(x); f_list.append(f)  if len(f_list) == len(x_list) -1: return (x_list, f_list) else: return ([], [])  def get_yfx(self, f_list, x_list, t = True): '''\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 (x, f, y)''' if len(x_list) == len(f_list): x_list.append('')  path = [] for i in range(len(f_list)): path.append((x_list[i], f_list[i], x_list[i+1]))  if t: return path  else: p = [] for xfy in path: if xfy[2] != '': p.append(xfy[2]+'='+xfy[1]+'('+xfy[0]+')') return p  def flow(self, path, rnd=False): if not path:  return [] fl = [] for p in path: if not rnd: fl.append(p[:-1]) else: pr = list(p[:-1]) random.shuffle(pr) fl.append(tuple(pr)) return fl  def fORx(self, flow, f=0): '''\u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u043f\u043e\u0442\u043e\u043a, \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0434\u0432\u0435 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b    index: f=0, x=1 or x=0, f=1''' def add_empty(): empty = [] for k in graph: for x in graph[k]: z = list(set(x[0].split('|')) - set(list(graph.keys()))) if z: empty.append(z[0]) return empty  if not flow: return []  graph = {} fli = flow[0]  for t in flow[1:]: if f == 0: if fli[1] not in graph: graph[fli[1]] = [] r = [(i, xf) for i,xf in enumerate(graph[fli[1]]) if xf[1] == fli[0]] if r: if t[1] not in r[0][1][0]: x_new = r[0][1][0] + \"|\" + t[1] if x_new != '': graph[fli[1]][r[0][0]] = (x_new, r[0][1][1]) if not r: if t[1] != '': graph[fli[1]].append((t[1], fli[0]))  if f == 1: if fli[0] not in graph: graph[fli[0]] = [] r = [(i, xf) for i,xf in enumerate(graph[fli[0]]) if xf[1] == fli[1]] if r: if t[0] not in r[0][1][0]: x_new = r[0][1][0] + \"|\" + t[0] if x_new != '': graph[fli[0]][r[0][0]] = (x_new, r[0][1][1]) if not r: if t[0] != '': graph[fli[0]].append((t[0], fli[1])) fli = t  em = add_empty() if em: graph[em[0]] = [] return graph  def merge(self, g1, g2): '''\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0434\u0432\u0430 \u0433\u0440\u0430\u0444\u0430 \u0432 \u043e\u0434\u0438\u043d''' def find_index(): for i in range(len(graph[k])): if graph[k][i][1] == x[1]: return i return -1  all_keys = set(list(g1.keys()) + list(g2.keys())) graph = {}  for k in all_keys: if k not in graph:  if k in g1: graph[k] = g1[k] else: graph[k] = g2[k]  if k in g2: for x in g2[k]: ind = find_index() if ind != -1: if x[0] != []: t1 = x[0].split('|') if graph[k][ind] != -1: t2 = graph[k][ind][0].split('|') z = \"|\".join(set(t1+t2)) xf = [z, graph[k][ind][1]] graph[k][ind] = xf else: graph[k].append(x)  return graph  class Vm(): def print_dptable(self, V): '''https:\/\/russianblogs.com\/article\/255172857\/''' for i in range(len(V)): print(\"%8d\" % i, end=\"\") print() for y in V[0].keys(): print(\"%.5s: \" % y, end=\" \") for t in range(len(V)): print(\"%.7s\" % V[t][y], end=\" \") print()   def viterbi(self, obs, states, start_p, trans_p, emit_p): '''https:\/\/russianblogs.com\/article\/255172857\/''' V = [{}] path = {} for y in states: V[0][y] = start_p[y] * emit_p[y][obs[0]] path[y] = [y]  for t in range(1, len(obs)): V.append({}) newpath = {}  for y in states: (prob, state) = max([(V[t - 1][y0] * trans_p[y0][y] * emit_p[y][obs[t]], y0) for y0 in states]) V[t][y] = prob newpath[y] = path[state] + [y] path = newpath  self.print_dptable(V) (prob, state) = max([(V[len(obs) - 1][y], y) for y in states]) return prob, path[state]   def startProbability(self, x_list): '''\u0440\u0430\u0441\u0447\u0435\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438''' start_probability = {}  for z in x_list: if z not in start_probability: start_probability[z] = 1 else: start_probability[z] +=1  start_probability = {z:start_probability[z]\/(len(x_list)) for z in start_probability} return start_probability   def transitionProbability(self, x_list): '''\u0440\u0430\u0441\u0447\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438''' transition_probability = {}  for i,z in enumerate(x_list): if z not in transition_probability: transition_probability[z] = {} if i == 0: z_old = z continue  if z not in transition_probability[z_old]: transition_probability[z_old][z] = 1 else: transition_probability[z_old][z] = transition_probability[z_old][z] +1  z_old = z  for z_old in transition_probability: z_list = [transition_probability[z_old][z] for z in transition_probability[z_old]] for z in transition_probability[z_old]: transition_probability[z_old][z] = transition_probability[z_old][z] \/ sum(z_list)  return transition_probability  def emissionProbability(self, x_list, f_list): '''\u0440\u0430\u0441\u0447\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0430''' emission_probability = {} for i,z in enumerate(x_list): if z not in emission_probability: emission_probability[z] = {} if f_list[i] not in emission_probability[z]: emission_probability[z][f_list[i]] = 1 else: emission_probability[z][f_list[i]] += 1  for z_old in emission_probability: z_list = [emission_probability[z_old][z] for z in emission_probability[z_old]] for z in emission_probability[z_old]: emission_probability[z_old][z] = emission_probability[z_old][z] \/ sum(z_list)  return emission_probability  def isMarkov(self, w_list, prev_s, s): '''\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e''' transition_probability = {}  for i,z in enumerate(w_list): if z not in transition_probability: transition_probability[z] = {} if i == 0: z_old = z continue  if z not in transition_probability[z_old]: transition_probability[z_old][z] = 1 else: transition_probability[z_old][z] = transition_probability[z_old][z] +1  z_old = z zz_old = z_old  transition_probability_ = {}  for i,z in enumerate(w_list): if z not in transition_probability_ and z == s: transition_probability_[z] = {} if i == 0: z_old = z continue if i == 1: zz_old = z_old z_old = z continue  if zz_old == prev_s and z_old == s: if z not in transition_probability_[z_old]: transition_probability_[z_old][z] = 1 else: transition_probability_[z_old][z] = transition_probability_[z_old][z] +1  zz_old = z_old z_old = z  return ((prev_s, s), transition_probability_[s], transition_probability[s])   #--------- main ---------#     if __name__ == \"__main__\": g = {} hd<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-336082","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336082","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=336082"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/336082\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}