{"id":285611,"date":"2017-04-27T15:40:15","date_gmt":"2017-04-27T11:40:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=285611"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=285611","title":{"rendered":"PyMC3 \u2014 MCMC \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e"},"content":{"rendered":"<h1 id=\"pymc3---msms-i-ne-tolko\">PyMC3 \u2014 \u041c\u0421\u041c\u0421 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e<\/h1>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/pymc-devs\/pymc3\/master\/docs\/pymc3_logo.jpg\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440!<\/p>\n<p>  <\/p>\n<p>\u0412 <a href=\"https:\/\/habrahabr.ru\/company\/wunderfund\/blog\/279545\/\">\u044d\u0442\u043e\u043c<\/a> \u043f\u043e\u0441\u0442\u0435 \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0441\u044f PyMC3. \u0422\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e \u043e\u0441\u043d\u043e\u0432\u044b MCMC-\u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0417\u0434\u0435\u0441\u044c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 (<a href=\"https:\/\/arxiv.org\/abs\/1603.00788\">ADVI<\/a>), \u043f\u0440\u043e \u0442\u043e, \u0437\u0430\u0447\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0438 \u043f\u043e\u043a\u0430\u0436\u0443 \u043d\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0437 \u0433\u0430\u043b\u0435\u0440\u0435\u0438 PyMC3, \u0447\u0435\u043c \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0430\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043d\u043e \u044d\u0442\u043e \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435. \u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c!<\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u0441\u0447\u0438\u0442\u0430\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u044e \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041f\u0440\u0435\u0434\u043c\u0435\u0442 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0442\u0435\u043e\u0440\u0438\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u2014 \u0432\u044b\u0432\u043e\u0434 \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<br \/>  \u0410\u043d\u0430\u043b\u0438\u0442\u0438\u043a \u0445\u043e\u0447\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043d\u0435\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 (\u043b\u0430\u0442\u0435\u043d\u0442\u043d\u044b\u0445) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043c\u043e\u0434\u0435\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math> \u0438 \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u0438\u0435 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u0438\u043c\u0438 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/cad\/a01\/c8d\/cada01c8dd59acd5a34521aef762766c.svg\" alt=\"$p(z)$\" data-tex=\"inline\"\/><\/math>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0434\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e \u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/918\/0fa\/eba\/9180faebaa9da51bca81b7ef85e3750f.svg\" alt=\"$D$\" data-tex=\"inline\"\/><\/math> \u043b\u043e\u0436\u0430\u0442\u0441\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math>. \u0412\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8f\/acb\/4d8\/f8facb4d8a5c44e211d28ecd17130ddc.svg\" alt=\"$p(D|z)$\" data-tex=\"inline\"\/><\/math> \u2014 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445.<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f3d\/321\/133\/f3d321133174b4a049c9ff46e4cbc0cb.svg\" alt=\"$\\large p(z|D) = \\frac{p(z, D)}{p(D)} = \\frac{p(D|z)p(z)}{p(D)}$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0413\u0434\u0435 <\/p>\n<p>  <\/p>\n<ul>\n<li>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/cad\/a01\/c8d\/cada01c8dd59acd5a34521aef762766c.svg\" alt=\"$p(z)$\" data-tex=\"inline\"\/><\/math> \u2014 \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u0447\u0435\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<br \/>  \u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0448\u044c \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438, \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c \u044f\u0432\u043b\u0435\u043d\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f. <\/p>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0444\u0438\u0437\u0438\u043a\u0438. \u0422\u0430\u043c \u0435\u0441\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u044b \u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043e \u043d\u0438\u0445 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0435\u043b\u0438\u0447\u0438\u043d, \u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0442\u0440\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0430 \u0441 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u044c\u044e). \u041c\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u043a\u0430\u043a\u0438\u043c \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u0438 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u043d\u0438\u0439. \u0425\u043e\u0442\u044f \u0431\u044b \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442, \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0446\u0435\u043d\u0438\u0442\u044c.<\/li>\n<li><strong>\u0412\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0418\u043d\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0441\u043e\u0431\u043b\u0430\u0437\u043d \u043f\u043e\u0434\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0421\u043a\u0430\u0436\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u0438\u043a\u0438\u043d\u0443\u043b\u0438 \u043d\u0430 \u0434\u0430\u043d\u043d\u043d\u044b\u0445, \u0447\u0442\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math> \u0433\u0434\u0435-\u0442\u043e \u043e\u043a\u043e\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/865\/891\/656\/8658916560196dd654e1796e33930b49.svg\" alt=\"$3$\" data-tex=\"inline\"\/><\/math> \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435. \u041f\u043e\u0441\u0442\u043e\u0439\u0442\u0435, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u0442\u0435\u043e\u0440\u0435\u043c\u0443, \u0432\u044b \u0436\u0435 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435\u0441\u044c \u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u0435\u0435 \u0436\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430? \u0422\u0430\u043a \u0436\u0435 \u0438 \u0437\u0434\u0435\u0441\u044c, \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <em>\u0438\u0437\u0443\u0447\u0430\u0435\u043c\u044b\u0439<\/em> \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<\/ul>\n<p>  <\/li>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8f\/acb\/4d8\/f8facb4d8a5c44e211d28ecd17130ddc.svg\" alt=\"$p(D|z)$\" data-tex=\"inline\"\/><\/math> \u2014 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u0435, \u043e\u0446\u0435\u043d\u043a\u0430 \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math>. \u0412\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u044b \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math>. <br \/> \n<ul>\n<li>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c, &quot;\u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043c\u0438\u0440&quot;. \u042d\u0442\u0443 \u0438\u0434\u0435\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u0440\u0438 MLE \u043e\u0446\u0435\u043d\u043a\u0435.<\/li>\n<\/ul>\n<\/li>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f72\/617\/a72\/f72617a72cf5def03fc363b2719b3682.svg\" alt=\"$p(z|D)$\" data-tex=\"inline\"\/><\/math> \u2014 \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0432\u044b\u0432\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c. <br \/> \n<ul>\n<li>\u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043a\u043e\u044d\u0444. \u0442\u0440\u0435\u043d\u0438\u044f), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0436\u0438\u043b\u0438\u0441\u044c \u0443 \u043d\u0430\u0441 \u0432 \u0445\u043e\u0434\u0435 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430. \u041c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u043e \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441\u043e\u043c \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u0438 \u043d\u043e\u0432\u044b\u043c\u0438, \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/cad\/a01\/c8d\/cada01c8dd59acd5a34521aef762766c.svg\" alt=\"$p(z)$\" data-tex=\"inline\"\/><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8f\/acb\/4d8\/f8facb4d8a5c44e211d28ecd17130ddc.svg\" alt=\"$p(D|z)$\" data-tex=\"inline\"\/><\/math> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/li>\n<\/ul>\n<\/li>\n<li><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/01c\/8fd\/00c\/01c8fd00cd3d50e06a308bafbcc6a66b.svg\" alt=\"$p(D)$\" data-tex=\"inline\"\/><\/math> \u2014 Evidence, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043e\u043e\u0431\u0449\u0435, \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043a\u0432\u0435\u0440\u043d\u043e.<\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"bayesovskiy-vyvod\">\u0411\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u044b\u0432\u043e\u0434<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0435\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8f\/acb\/4d8\/f8facb4d8a5c44e211d28ecd17130ddc.svg\" alt=\"$p(D|z)$\" data-tex=\"inline\"\/><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/cad\/a01\/c8d\/cada01c8dd59acd5a34521aef762766c.svg\" alt=\"$p(z)$\" data-tex=\"inline\"\/><\/math>, \u0438\u0441\u043a\u043e\u043c\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b02\/148\/54e\/b0214854e07408061c84a686da24bb64.svg\" alt=\"$\\large p(z|D) = \\frac{p(D|z)p(z)}{p(D)} = \\frac{p(D|z)p(z)}{\\int p(D|z)p(z) dz}$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u0434\u0432\u0435 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 \u2014 \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b \u0441\u043d\u0438\u0437\u0443?.. \u0425\u043c, \u043d\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0441\u043a\u0438\u0439 \u043a\u0443\u0440\u0441 \u043c\u0430\u0442\u0430\u043d\u0430\u043b\u0438\u0437\u0430\u2026 \u0412 \u043e\u0431\u0449\u0435\u043c \u0431\u0435\u0440\u0435\u043c, \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u0438 \u0433\u043e\u0442\u043e\u0432\u043e. \u0412\u043e\u043e\u0440\u0443\u0436\u0438\u0432\u0448\u0438\u0441\u044c \u044d\u0442\u0438\u043c \u0437\u043d\u0430\u043d\u0438\u0435\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0445 \u043a \u0436\u0438\u0437\u043d\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u0434\u0430\u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u043d\u0435 \u0441\u043f\u0430\u0441\u0435\u0442 \u0438 \u0432\u0437\u044f\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435 \u043f\u043e\u0434 \u0441\u0438\u043b\u0443.<\/p>\n<p>  <\/p>\n<h1 id=\"zachem-vse-eto\">\u0417\u0430\u0447\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u043e?<\/h1>\n<p>  <\/p>\n<p>\u041d\u0443 \u0440\u0430\u0437 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f72\/617\/a72\/f72617a72cf5def03fc363b2719b3682.svg\" alt=\"$p(z|D)$\" data-tex=\"inline\"\/><\/math>, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u043e\u0447\u0435\u0447\u043d\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u043e\u0439, \u0441\u043a\u0430\u0436\u0435\u043c, \u0433\u0434\u0435 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430? \u041d\u0443 \u0438\u043b\u0438 \u0432 \u043a\u0440\u0430\u0439\u043d\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0434\u0430\u0436\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8f\/acb\/4d8\/f8facb4d8a5c44e211d28ecd17130ddc.svg\" alt=\"$p(D|z)$\" data-tex=\"inline\"\/><\/math>, \u043c\u044b \u0436\u0435 \u043a\u0430\u043a \u043d\u0438\u043a\u0430\u043a \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>MAP<\/strong> (maximum a posterior) \u043e\u0446\u0435\u043d\u043a\u043e\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/200\/55a\/290\/20055a2904525c243a2bd335eaa2d4e0.svg\" alt=\"$z^{map} = argmax_z p(z|D) $\" data-tex=\"inline\"\/><\/math>, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 <strong>ML<\/strong> (maximum likelihood) <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/553\/cc1\/c7d\/553cc1c7d7cb61c149b20148757671e2.svg\" alt=\"$z^{ml} = argmax_z p(D|z)$\" data-tex=\"inline\"\/><\/math>. \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0447\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u0443\u0434\u0435\u043d\u0442 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u0443\u0437\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0432 \u043a\u0443\u0440\u0441\u0435 \u0442\u0435\u043e\u0440\u0438\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438. <\/p>\n<p>  <\/p>\n<p>\u0423 ML \u043e\u0446\u0435\u043d\u043a\u0438 \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432. \u0421\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f. \u0412\u0435\u0434\u044c \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. \u042d\u0442\u043e\u0442 \u0444\u0430\u043a\u0442 \u0432\u0432\u043e\u0434\u0438\u0442 \u0432 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u0430\u044f. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u0435 ML \u043e\u0446\u0435\u043d\u043a\u0443, \u043a\u0430\u043a MAP \u0441 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/118\/947\/41b\/11894741b0d535ea55885cfacc7c0f62.svg\" alt=\"$p(z) = Uniform[-\\infty, \\infty]$\" data-tex=\"inline\"\/><\/math>. \u0414\u0430, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b \u043d\u0435 \u0431\u0435\u0440\u0435\u0442\u0441\u044f, \u043d\u043e \u0443 \u043d\u0430\u0441 \u0442\u043e\u0447\u0435\u0447\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u0438 \u043d\u0430\u043c \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0448\u0430\u0435\u0442, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/cad\/a01\/c8d\/cada01c8dd59acd5a34521aef762766c.svg\" alt=\"$p(z)$\" data-tex=\"inline\"\/><\/math> \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439. <\/p>\n<p>  <\/p>\n<p><strong>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e<\/strong><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/edf\/716\/b8b\/edf716b8b31410e445eb7ee4b937ddda.svg\" alt=\"$\\large p(z|D) = \\frac{p(z, D)}{p(D)} = \\frac{p(D|z)p(z)}{p(D)} \\rightarrow max$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/698\/096\/651\/698096651b204d8f71ee9cb56eecd9a7.svg\" alt=\"$\\large \\log p(z|D) = \\log \\frac{p(z, D)}{p(D)} = \\log \\frac{p(D|z)p(z)}{p(D)} \\rightarrow max$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/183\/942\/faa\/183942faa47f0c4ef7096df42fad0cfc.svg\" alt=\"$\\large \\sim \\log {p(D|z)p(z)} - \\log{p(D)} \\rightarrow max$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fcb\/22c\/6ca\/fcb22c6ca66d500f1263d64fb805e95b.svg\" alt=\"$\\large \\sim \\log {p(D|z)} + \\log{p(z)} \\rightarrow max$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/28f\/202\/bdc\/28f202bdc60d8acf1630f65b182b0479.svg\" alt=\"$\\large \\sim \\log {p(D|z)} \\rightarrow max$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <strong>Improper Priors<\/strong>, \u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u044d\u0442\u043e \u2014 \u0435\u0449\u0435 \u0438 <strong>Uninformative<\/strong> (\u043d\u0435\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435).<br \/>  \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u043d\u0435 \u0438\u043c\u0435\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435. \u0422\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0414\u043b\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0437 \u0442\u0435\u043e\u0440\u0438\u0438 \u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math> \u0441\u0442\u0440\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043d\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u043d\u0430 <em>&quot;\u0441\u043a\u043e\u0440\u0435\u0435 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0443\u043b\u044f&quot;<\/em>, \u0442\u043e ML \u044d\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0443\u0447\u0435\u0441\u0442\u044c. <\/li>\n<li>\u0414\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u043e\u0440\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438 \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u0430 \u0432 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0432\u0430\u0436\u043d\u044b. \u0422\u043e\u0433\u0434\u0430 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math> (\u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b) \u043c\u043d\u043e\u0433\u043e \u043d\u0443\u043b\u0435\u0432\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. <\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0445\u043e\u0440\u043e\u0448 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438, \u043d\u043e MAP \u0431\u043e\u043b\u0435\u0435 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u0435\u043d \u0432 \u0440\u044f\u0434\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u043c\u043f\u043e\u0440\u0442 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">from theano import theano, tensor as tt import pymc3 as pm import pandas as pd from sklearn import datasets import numpy as np from numpy import random import pylab as plt import seaborn as sns import warnings import scipy.stats as stats warnings.filterwarnings('ignore') %matplotlib inline plt.mpl.style.use('ggplot')<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<h1 id=\"primer-s-monetkoy\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043c\u043e\u043d\u0435\u0442\u043a\u043e\u0439<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0435\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043d\u0435\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u0430\u0445 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0439 \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0435\u0441\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u044f prior <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/c0f\/a2d\/a07\/c0fa2da0757bc2fe5a573f63b75e7f58.svg\" alt=\"$Uniform[0, 1]$\" data-tex=\"inline\"\/><\/math>(\u0440\u0430\u0432\u043d\u043e\u0441\u0438\u043b\u044c\u043d\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/819\/ed6\/90a\/819ed690a7df83cf60edc5b6cfa2c478.svg\" alt=\"$Beta[\\alpha=1, \\beta=1]$\" data-tex=\"inline\"\/><\/math>) \u0434\u043b\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c &quot;\u043e\u0440\u043b\u0430&quot; <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6cb\/322\/9d6\/6cb3229d6f195e9a9e27404fa18612c1.svg\" alt=\"$r$\" data-tex=\"inline\"\/><\/math> \u0438 \u0438\u043c\u0435\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f &quot;\u043e\u0440\u0435\u043b&quot; <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9b6\/547\/e8d\/9b6547e8d3f9c2d6f92fbc781ac55660.svg\" alt=\"$t$\" data-tex=\"inline\"\/><\/math> \u0438 &quot;\u0440\u0435\u0448\u043a\u0430&quot; <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e27\/cf9\/8c7\/e27cf98c72717dbc7954c0aeea930c1a.svg\" alt=\"$f$\" data-tex=\"inline\"\/><\/math>, \u0432\u0441\u0435\u0433\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/644\/86c\/eab\/64486ceabd5fd2c0d8f3df3093ef55bc.svg\" alt=\"$N$\" data-tex=\"inline\"\/><\/math> \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a47\/83a\/8d5\/a4783a8d52b79ae546496c02c93821f7.svg\" alt=\"$Beta[\\alpha=t+1, \\beta=f+1]$\" data-tex=\"inline\"\/><\/math>.<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/552\/88b\/11e\/55288b11e2c92783daf3a63abb908136.svg\" alt=\"$\\large p(r|T=t, F=f) = \\frac{p(T=t, F=f|r)p(r)}{\\int p(T=t, F=f|r)p(r)dr}$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a46\/fbb\/3b3\/a46fbb3b3447f17eddaa4e20bd810036.svg\" alt=\"$\\large = \\frac{C_N^k r^t(1-r)^f}{\\int_0^1 C_N^k r^t(1-r)^fdf}= \\frac{r^t(1-r)^f}{B(t+1, f+1)}$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/471\/f1f\/f39\/471f1ff39ccbb952857ac3d7ee62de45.svg\" alt=\"$\\large = Beta(r\\;|\\alpha=t+1, \\beta=f+1)$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0439 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0443\u0436\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 def posterior(t, f):     &quot;&quot;&quot;     t : \u043e\u0440\u0435\u043b     f : \u0440\u0435\u0448\u043a\u0430     &quot;&quot;&quot;     return stats.beta(a=t+1, b=f+1)  # \u0432\u0442\u043e\u0440\u0430\u044f \u0440\u0438\u0441\u0443\u0435\u0442 \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 def plot_pdf(dist, ax, c):     space = np.linspace(0, 1)     pdf = dist.pdf(space)     ax.plot(space, pdf, c=c, alpha=.5)     return ax<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<pre><code class=\"python\"># \u0414\u0430\u043d\u043d\u044b\u0435 true_p = .3 # \u0418\u0441\u0442\u0438\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c &quot;\u041e\u0440\u043b\u0430&quot; random.seed(42) # \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 trials = np.random.uniform(size=100) &lt; true_p # \u0411\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0433\u0434\u0435 1 \u044d\u0442\u043e \u043e\u0440\u0435\u043b # \u0421\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u044b [t, f] observed = np.array(list(zip(np.cumsum(trials), np.arange(1, trials.size+1) - np.cumsum(trials)))) observed[:6]<\/code><\/pre>\n<p>  <\/p>\n<pre><code>array([[0, 1],        [0, 2],        [0, 3],        [0, 4],        [1, 4],        [2, 4]])<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0438\u0441\u0443\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">fig, ax = plt.subplots(figsize=(15, 5)) cmap = plt.get_cmap('cool') plot_pdf(posterior(0, 0), ax, cmap(0)) for (t, f), c in zip(observed, np.linspace(0, 1, num=observed.shape[0])):     plot_pdf(posterior(t, f), ax, cmap(c)) plt.title('\u042d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043e\u0440\u043b\u0430') plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/45d\/6a0\/2ad\/45d6a02adf984713a4ceca924e18f769.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0443\u0437\u043a\u0438\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u044d\u0442\u043e \u043f\u0440\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432 \u043d\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u043d\u0438\u044f\u0445. \u0427\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0442\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043c\u0430\u043b\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439: \u043e\u043d\u043e \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u043d\u0435\u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c. \u042d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0438 \u0438\u0441\u043a\u0430\u0442\u044c MLE \u043e\u0446\u0435\u043d\u043a\u0443. \u041c\u044b \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c 0 \u0434\u043b\u044f \u043e\u0440\u043b\u0430 \u043f\u0440\u0438 \u043c\u0430\u043b\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u0447\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0442\u0430\u043a.<\/p>\n<p>  <\/p>\n<h1 id=\"motivaciya\">\u041c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f<\/h1>\n<p>  <\/p>\n<p><strong>PyMC3<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u0443\u043b. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u043b\u044e\u0431\u044b\u0445 \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0441 \u0435\u0451 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u044b\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u2014 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u043e\u0436\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438.<br \/>  <img decoding=\"async\" src=\"https:\/\/ai2-s2-public.s3.amazonaws.com\/figures\/2016-11-08\/da6057368920585bcf2443295b98418840f1fc80\/1-Figure1-1.png\"\/><\/p>\n<p>  <\/p>\n<h1 id=\"nachalo-raboty-s-pymc3\">\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 PyMC3<\/h1>\n<p>  <\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <em>PyMC3<\/em> \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445 <em><a href=\"http:\/\/deeplearning.net\/software\/theano\/\">Theano<\/a><\/em> \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u0439. <em>Theano<\/em> \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0442\u0435\u043d\u0437\u043e\u0440\u043d\u043e\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u044b \u0438 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u0434\u0438\u0444\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>backprop<\/em>, \u043d\u043e \u0438 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0431\u0430\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u044b\u0432\u043e\u0434. <\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 <em>PyMC3<\/em> \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 <em>Theano<\/em>, \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 <a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/323272\/\">\u043f\u043e\u0441\u0442\u043e\u0432<\/a> \u043f\u0440\u043e \u043d\u0435\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0411\u0430\u0437\u043e\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c (<code>pm.Model<\/code>), \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430 \u043b\u0435\u0442\u0443 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u0443\u044e \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c (\u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0435 \u043d\u0435\u043e\u0442\u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c). \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0441 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c, \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u0430\u0433\u0438\u044f \u0441 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u043c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c. \u041b\u0430\u0442\u0435\u043d\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 <em>PyMC3<\/em> \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 <code>with model: ...<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0438 \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0441\u043c\u044b\u0441\u043b\u0435 <code>Theano<\/code>, \u0434\u043b\u044f \u043d\u0438\u0445 \u0432\u0435\u0440\u043d\u043e \u0432\u0441\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432 \u0432 <code>Theano<\/code>. \u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0431\u043e\u044f\u0442\u044c\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b MCMC \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0445\u0443\u0434\u0448\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u0443 \u0438\u043b\u0438, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>pm.sample<\/code>, \u043e\u043d\u0430 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043d\u043e \u0432 \u0446\u0435\u043b\u044f\u0445 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043e\u043d\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f MCMC \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043a\u0430\u043a \u0440\u0430\u0437 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u0432\u044b\u0448\u0435 \u0441\u0434\u0435\u043b\u0430\u043d import pymc3 as pm  with pm.Model() as simple_model:     # \u041f\u043e \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430     # \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0438\u043c\u0435\u043d\u0438     norm = pm.Normal('norm', 0, 1)      # \u043d\u0435 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f MCMC \u043c\u0435\u0442\u043e\u0434\u0430 NUTS     step = pm.NUTS()     trace = pm.sample(1000, step=step)     # \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443: \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438<\/code><\/pre>\n<p>  <\/p>\n<pre><code>WARNING (theano.tensor.blas): We did not found a dynamic library into the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library. 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1000\/1000 [00:00&lt;00:00, 1368.27it\/s]<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"trace-plot\">Trace Plot<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>TracePlot<\/strong>. \u042d\u0442\u043e \u0433\u0440\u0430\u0444\u0438\u043a \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0439 \u0446\u0435\u043f\u0438. \u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f \u0435\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043b\u0438 \u043e\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438. \u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0421\u0442\u0430\u0446\u0438\u043e\u043d\u0430\u0440\u043d\u043e\u0441\u0442\u044c. \u0421\u044d\u043c\u043f\u043b\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0448\u0443\u043c \u0432\u043e\u0433\u0440\u0443\u0433 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/li>\n<li>\u041d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u043d\u043e\u0439 \u0430\u0432\u0442\u043e\u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u0438. \u0418\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e(\u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0438\u0436\u0435), \u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0447\u0442\u043e\u0431\u044b \u0435\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e<\/li>\n<li>\u0412\u0441\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0439\u0441\u044f \u0442\u043e\u0447\u043a\u0438. \u0415\u0441\u043b\u0438 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043e\u0439, \u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a \u0432 \u043a\u043e\u0434\u0435 \u0441\u0430\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"python\">pm.traceplot(trace);<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d10\/22f\/00d\/d1022f00d5c74f83922aad575a947770.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">with pm.Model() as simple_model:     norm = pm.Normal('norm', 0, 1)     # \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435     laplace = pm.Laplace('lap', mu=norm, b=3)     step = pm.NUTS()     trace = pm.sample(1000, step=step)<\/code><\/pre>\n<p>  <\/p>\n<pre><code>100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1000\/1000 [00:36&lt;00:00, 27.10it\/s]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u043b\u0430 \u0437\u0430\u043c\u0435\u0442\u043d\u0430 \u0442\u0443\u0440\u0431\u0443\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0432 \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0439 \u0446\u0435\u043f\u0438 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">pm.traceplot(trace);<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/01b\/a4e\/c5a\/01ba4ec5a2884b409e5bd3cb82d20328.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439, \u0445\u043e\u0442\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u043b\u0430 \u0431\u044b\u0442\u044c \u0441 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043e\u0439. \u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0442\u044e\u043d\u0438\u0442\u044c ADVI \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0438 \u0441\u0440\u0435\u0434\u043d\u0438\u0435 \u043e\u0442\u0442\u0443\u0434\u0430 \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 NUTS. \u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e ADVI.<\/p>\n<p>  <\/p>\n<h2 id=\"advi\">ADVI<\/h2>\n<p>  <\/p>\n<p>ADVI \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a <em>Automatic Differentiation Variational Inference<\/em> (<a href=\"https:\/\/arxiv.org\/abs\/1603.00788\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e<\/a>). \u042d\u0442\u043e, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0434\u043b\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430. \u041a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0440\u0430\u0441\u0442\u0435\u0442, MCMC \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 (\u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442), \u043b\u0438\u0431\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0412 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0442\u0438, \u043c\u044b \u0443\u0431\u0435\u0434\u0438\u043b\u0438\u0441\u044c \u0432\u044b\u0448\u0435. \u0412\u043e\u0442 \u0442\u043e\u0433\u0434\u0430 \u0438 \u0432\u0441\u0442\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u044c \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043c, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0443\u043c\u0435\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<h3 id=\"teoriya\">\u0422\u0435\u043e\u0440\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0421\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0435\u0442 \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f72\/617\/a72\/f72617a72cf5def03fc363b2719b3682.svg\" alt=\"$p(z|D)$\" data-tex=\"inline\"\/><\/math> \u0434\u0440\u0443\u0433\u0438\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b8c\/897\/e26\/b8c897e2607ddf575ebad6daefd93ecd.svg\" alt=\"$q(z)$\" data-tex=\"inline\"\/><\/math>, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0443\u043c\u0435\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0438 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0412 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0442\u0430\u043a\u0438\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u043e\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0441 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8a8\/f08\/4ea\/8a8f084ea68b916183c39376b448e377.svg\" alt=\"$\\mathcal{N}(\\bar{0}, diag(\\bar{\\sigma}^2))$\" data-tex=\"inline\"\/><\/math>. \u042d\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0435\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c: \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b, \u043d\u043e \u044d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u0430\u043a. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0434\u0430\u0436\u0435 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u044b\u043b\u043a\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<p>  <\/p>\n<h4 id=\"postanovka-zadachi\">\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h4>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/551\/eac\/b7b\/551eacb7b94f37390078e633b1909277.svg\" alt=\"$\\mathcal{D}$\" data-tex=\"inline\"\/><\/math>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/19e\/be2\/690\/19ebe2690d0fd578a7290d72a2c6b8a5.svg\" alt=\"$z \\in \\mathcal{R}^n$\" data-tex=\"inline\"\/><\/math> \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0435\u0435 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8f\/acb\/4d8\/f8facb4d8a5c44e211d28ecd17130ddc.svg\" alt=\"$p(D|z)$\" data-tex=\"inline\"\/><\/math>. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/cad\/a01\/c8d\/cada01c8dd59acd5a34521aef762766c.svg\" alt=\"$p(z)$\" data-tex=\"inline\"\/><\/math>. \u041f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0443 \u0411\u0430\u0439\u0435\u0441\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0fd\/acd\/7f8\/0fdacd7f8ac0edae23d47065dbc95626.svg\" alt=\"$\\large p(z|D) = \\frac{p(D|z)p(z)}{\\int{p(D|z)p(z)dz}}$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0427\u0430\u0441\u0442\u044c \u0431\u0435\u0437 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0440\u0443\u0434\u0430:<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/dbc\/523\/b33\/dbc523b3314f1fb2bb06cf4bdd012fd6.svg\" alt=\"$\\large p(z|D) \\propto p(D|z)p(z)$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/c7c\/73a\/e39\/c7c73ae399a77bc43e3e9bd0800c2d31.svg\" alt=\"$q_{\\theta} \\in Q$\" data-tex=\"inline\"\/><\/math>, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p><em>\u041c\u0435\u0442\u0440\u0438\u043a\u0430.<\/em> \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u041a\u0443\u043b\u044c\u0431\u0430\u043a\u0430-\u041b\u0435\u0439\u0431\u043b\u0435\u0440\u0430<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ec8\/1d8\/210\/ec81d8210bfae78b09f632125df4a530.svg\" alt=\"$\\large KL(q||p) = \\mathbb{E}_{q(z)}[log q(z)-logp(z|D)]$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0442\u043e \u043c\u0430\u0442\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0443\u043b\u044e, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u0430\u0442\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0437\u0430\u0434\u0430\u0447\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/dbf\/fcd\/a89\/dbffcda897e8ae929b8510d699129f54.svg\" alt=\"$\\large q_{\\theta^*} = \\underset{q_{\\theta} \\in Q}{argmin}\\; KL(q_\\theta||p)$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<h4 id=\"reshenie-zadachi\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h4>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u043c \u0441\u043f\u0443\u0441\u043a\u043e\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0437\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0443\u044e \u043f\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a21\/ed4\/61f\/a21ed461f66aaee7817cacfb1a898860.svg\" alt=\"$\\theta$\" data-tex=\"inline\"\/><\/math>.<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/20b\/a8a\/2dc\/20ba8a2dc89e49a4346a905a9446f1d5.svg\" alt=\"$\\large \\mathbb{E}_{q_{\\theta}(z)}[log q_{\\theta}(z)-logp(z|D)]$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/078\/860\/889\/0788608891d5dc3d751f18d6c171f93a.svg\" alt=\"$\\large =\\mathbb{E}_{q_{\\theta}(z)}[log q_{\\theta}(z)]-\\mathbb{E}_{q_{\\theta}(z)}[logp(z|D)]$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d1e\/f09\/b6c\/d1ef09b6c5e5b40fd71ff29d5c9cec19.svg\" alt=\"$\\large =\\mathbb{E}_{q_{\\theta}(z)}[log q_{\\theta}(z)]-\\mathbb{E}_{q_{\\theta}(z)}[logp(D|z)] - \\mathbb{E}_{q_{\\theta}(z)}[logp(z)] + \\mathbb{E}_{q_{\\theta}(z)}[logp(D)]$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u043b\u0438 KL-\u043c\u0435\u0442\u0440\u0438\u043a\u0443, \u0438 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0435\u0435 \u043d\u0430\u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/83d\/ed6\/d62\/83ded6d626dded3232d85131e464aae3.svg\" alt=\"$\\mathbb{E}_{q_{\\theta}(z)}[logp(D)]$\" data-tex=\"inline\"\/><\/math> \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430, \u0442\u043e \u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0435 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u0422\u0430\u043a \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u2014 \u043d\u0435\u0431\u0435\u0440\u0443\u0449\u0435\u0433\u043e\u0441\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u0430. \u0412\u0441\u0435, \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c, \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f <math>$inline$-ELBO$inline$<\/math> (<em>Evidence Lower BOund<\/em>).<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u043d\u043e. \u0427\u0442\u043e\u0431\u044b \u0432\u0437\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0443\u044e \u043f\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u0437\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0443\u044e \u043f\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u044d\u0442\u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0415\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 MC \u0438 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u044d\u043c\u043f\u043b\u0430\u043c\u0438, \u0442\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u043c\u0441\u044f \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0438\u043c\u0435\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e. \u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c, \u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0435 \u043d\u0430\u043c\u0438 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0442\u0435\u043e\u0440\u0435\u043c\u0430 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u043f\u043e\u0434 \u0437\u043d\u0430\u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u0422\u0435\u043e\u0440\u0435\u043c\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e12\/dff\/45a\/e12dff45a7ed01bc64ba2aeb4d34a2bc.svg\" alt=\"$\\epsilon$\" data-tex=\"inline\"\/><\/math> \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u0441 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8e9\/56f\/6e0\/8e956f6e0f5e62c15f880ddfcaa16921.svg\" alt=\"$q(\\epsilon)$\" data-tex=\"inline\"\/><\/math> \u0438 \u043f\u0443\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/25e\/eac\/7db\/25eeac7dba728b2fe93d6a7b722df46c.svg\" alt=\"$z = t(\\theta, \\epsilon)$\" data-tex=\"inline\"\/><\/math>, \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9b6\/547\/e8d\/9b6547e8d3f9c2d6f92fbc781ac55660.svg\" alt=\"$t$\" data-tex=\"inline\"\/><\/math> \u2014 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0441\u0442\u0441\u043a\u0430\u044f \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u041f\u0443\u0441\u0442\u044c \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math> \u044d\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e2c\/01a\/b64\/e2c01ab64d4b8bf3846e3a3372d8720d.svg\" alt=\"$q(z|\\theta)$\" data-tex=\"inline\"\/><\/math>. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0434\u0430\u043b\u0435\u0435, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9dc\/b7c\/985\/9dcb7c985cb7384158f586a0f7069198.svg\" alt=\"$q(\\epsilon)d\\epsilon = q(z|\\theta)dz$\" data-tex=\"inline\"\/><\/math>.<br \/>  \u0422\u043e\u0433\u0434\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e27\/cf9\/8c7\/e27cf98c72717dbc7954c0aeea930c1a.svg\" alt=\"$f$\" data-tex=\"inline\"\/><\/math> \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0439 \u043f\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ef5\/db0\/e64\/ef5db0e6412bfaac0ae8c30f2cf2b8e0.svg\" alt=\"$z$\" data-tex=\"inline\"\/><\/math> \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/046\/eca\/a2e\/046ecaa2e05729d4ee608a41192914a9.svg\" alt=\"$\\large \\frac{\\partial}{\\partial\\theta} \\mathbb{E}_{q(z|\\theta)}[f(z, \\theta)] = \\mathbb{E}_{q(\\epsilon)}[\\frac{\\partial f(z, \\theta)}{\\partial z}\\frac{\\partial z}{\\partial \\theta} + \\frac{f(z, \\theta)}{\\partial \\theta}] $\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fb5\/44d\/ddc\/fb544dddc3447a1beb2c3f2f1f6cdc04.svg\" alt=\"$z \\sim \\mathcal{N}(\\mu, exp(w)^2)$\" data-tex=\"inline\"\/><\/math> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c\u0430 \u0432 \u0432\u0438\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/726\/17c\/708\/72617c708dddd89ca7a50a689f2b0e19.svg\" alt=\"$z = t(\\mu, w, \\epsilon) = \\epsilon*exp(w) + \\mu$\" data-tex=\"inline\"\/><\/math>, \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/68b\/327\/b90\/68b327b90ab9aa1cb47e9153cd856bfa.svg\" alt=\"$\\epsilon \\sim \\mathcal{N}(0, 1)$\" data-tex=\"inline\"\/><\/math>. \u041f\u0443\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0ad\/ca1\/fa7\/0adca1fa78462337e5eba3a598fb8d0f.svg\" alt=\"$\\theta = (\\mu, w)$\" data-tex=\"inline\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <em>Reparametrization Trick<\/em>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0433\u043e, \u0443\u0436\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0432\u0437\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0443\u044e \u043e\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1f1\/46d\/9ac\/1f146d9ac59d4053a47c32203476ef0f.svg\" alt=\"$ELBO$\" data-tex=\"inline\"\/><\/math>.<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/57a\/852\/cdd\/57a852cdda631ba153eb0a669938c0c7.svg\" alt=\"$\\large -\\nabla ELBO = \\mathbb{E}_{\\mathcal{N}(0, 1)}[\\nabla_{\\theta}log q_{\\theta}(t(\\theta, \\epsilon))-\\nabla_{\\theta}logp(D|t(\\theta, \\epsilon)) - \\nabla_{\\theta}logp(t(\\theta, \\epsilon))] $\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>C\u0434\u0435\u043b\u0430\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0440\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0430\u0446\u0438\u044e, \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>theano.grad<\/code> \u043d\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0432\u044b\u0448\u0435, \u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0433\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043e\u044b\u0439 \u0441\u044d\u043c\u043f\u043b, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u0438\u043c\u044b\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">with pm.Model() as simple_model:     norm = pm.Normal('norm', 0, 1)     laplace = pm.Laplace('lap', mu=norm, b=3)     trace = pm.sample(1000, init='advi', n_init=10000)<\/code><\/pre>\n<p>  <\/p>\n<pre><code>Auto-assigning NUTS sampler... Initializing NUTS using advi... Average ELBO = -0.11837: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 10000\/10000 [00:00&lt;00:00, 13764.87it\/s] Finished [100%]: Average ELBO = -0.1085 Evidence of divergence detected, inspect ELBO. 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1000\/1000 [00:01&lt;00:00, 974.36it\/s]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423\u0436\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>  <\/p>\n<p><strong>HINT:<\/strong> \u043d\u0430 \u0442\u0440\u0435\u0439\u0441\u043f\u043b\u043e\u0442\u0435 \u0432\u0430\u0436\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u0443\u044e \u0446\u0435\u043f\u044c, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0441\u0442\u0430\u0446\u0438\u043e\u043d\u0430\u0440\u043d\u043e\u0439, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u043a \u0437\u0434\u0435\u0441\u044c, \u0438 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0442\u0443\u0440\u0431\u0443\u043b\u0435\u043d\u0442\u043d\u043e\u0439, \u043a\u0430\u043a \u0432\u044b\u0448\u0435<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">pm.traceplot(trace);<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/a65\/440\/a8c\/a65440a8c803463eb574fd2affb5b387.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<pre><code class=\"python\">with pm.Model() as simple_model:     norm = pm.Normal('norm', 0, 1)     laplace = pm.Laplace('lap', mu=norm, b=3)     # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (\u0434\u0430\u0436\u0435 \u0442\u0430\u043a\u0438\u0445 \u044d\u043a\u0437\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445) \u0442\u043e\u0436\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e     lognorm = pm.Lognormal('lognorm', sd=norm**2 + 1e-7, testval=1)     trace = pm.sample(10000, n_init=40000)<\/code><\/pre>\n<p>  <\/p>\n<pre><code>Auto-assigning NUTS sampler... Initializing NUTS using advi... Average ELBO = -7.4197e+05: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 40000\/40000 [00:03&lt;00:00, 11614.15it\/s] Finished [100%]: Average ELBO = -1.221e+08 Evidence of divergence detected, inspect ELBO. 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 10000\/10000 [01:06&lt;00:00, 150.87it\/s]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0442\u043d\u0430\u044f \u0430\u0432\u0442\u043e\u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u044f \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u0430\u0440\u043a\u043e\u0432\u0441\u043a\u043e\u0439 \u0446\u0435\u043f\u0438. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0435\u0434\u044c \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435, NUTS \u0437\u0430\u0441\u0442\u0440\u0435\u0432\u0430\u043b \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0430\u0445 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u043f\u0435\u0440\u0432\u044b\u0435 100 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u043e\u0440\u0442\u044f\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 pm.traceplot(trace[100:]);<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e4f\/6a5\/5af\/e4f6a55af9794c2bb3910ce3cf29ee97.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">random.seed(42) obs = random.normal(0, 1, size=10) + random.normal(0, 10, size=10) with pm.Model() as model:     hc = pm.HalfCauchy('hc', beta=1) # your code with model:     # \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0442\u043e \u043e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e     norm = pm.Normal('norm', 0, hc, observed=obs)  with model:     trace = pm.sample(1000, tune=200, n_init=1000) pm.traceplot(trace[10:]);<\/code><\/pre>\n<p>  <\/p>\n<pre><code>Auto-assigning NUTS sampler... Initializing NUTS using advi... Average ELBO = -1,954.7: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1000\/1000 [00:00&lt;00:00, 8967.46it\/s] Finished [100%]: Average ELBO = -1,402.2 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1000\/1000 [00:00&lt;00:00, 1464.22it\/s]<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d70\/124\/1bb\/d701241bb8e94d5ea58057f70fc687e9.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u0418\u0434\u0435\u043e\u043b\u043e\u0433\u0438\u044f PyMC3 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0445\u043e\u0434\u0443 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f: \u0442\u0430\u043a \u0438\u0437\u0431\u0435\u0433\u0430\u044e\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u0440\u0430\u043d\u043d\u0435\u043c \u044d\u0442\u0430\u043f\u0435. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>test_value<\/code><\/p>\n<p>  <\/p>\n<pre><code class=\"python\">norm.tag.test_value<\/code><\/pre>\n<p>  <\/p>\n<pre><code>array([ -4.13746262,  -4.79556179,   3.06731129, -17.60977173,        -17.48333168,  -5.85701227,  -8.54909801,   3.90990806,         -9.54971504, -13.58047676], dtype=float32)<\/code><\/pre>\n<p>  <\/p>\n<p><code>Theano<\/code> \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u0432\u044b\u0431\u043e\u0440, \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u0447\u0435\u0440\u0435\u0437 \u0446\u0438\u043a\u043b \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0442\u043e\u0440\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u2014 \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">with pm.Model() as model:     vectorized_p = pm.Uniform('p', shape=(4,)) vectorized_p.tag.test_value<\/code><\/pre>\n<p>  <\/p>\n<pre><code>array([ 0.5,  0.5,  0.5,  0.5], dtype=float32)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0432\u043e\u044e.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">with pm.Model() as model:     vectorized_p = pm.Uniform('p',                                shape=(4,),                                testval=np.ones((4,), 'float64') * .3,                                dtype='float64') vectorized_p.tag.test_value<\/code><\/pre>\n<p>  <\/p>\n<pre><code>array([ 0.3,  0.3,  0.3,  0.3])<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"bayesovskaya-lineynaya-regressiya\">\u0411\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0430\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/h1>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u043d\u0435\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e \u0446\u0435\u043d\u044b \u043d\u0430 \u0431\u043e\u0441\u0442\u043e\u043d\u0441\u043a\u0438\u0435 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">data_ = datasets.load_boston() data = pd.DataFrame(data=data_['data'], columns=data_['feature_names']) y = data_['target']<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">print('\\n'.join(data_.DESCR.splitlines()[13:28]))<\/code><\/pre>\n<p>  <\/p>\n<pre><code>    :Attribute Information (in order):         - CRIM     per capita crime rate by town         - ZN       proportion of residential land zoned for lots over 25,000 sq.ft.         - INDUS    proportion of non-retail business acres per town         - CHAS     Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)         - NOX      nitric oxides concentration (parts per 10 million)         - RM       average number of rooms per dwelling         - AGE      proportion of owner-occupied units built prior to 1940         - DIS      weighted distances to five Boston employment centres         - RAD      index of accessibility to radial highways         - TAX      full-value property-tax rate per $10,000         - PTRATIO  pupil-teacher ratio by town         - B        1000(Bk - 0.63)^2 where Bk is the proportion of blacks by town         - LSTAT    % lower status of the population         - MEDV     Median value of owner-occupied homes in $1000's<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">data.head()<\/code><\/pre>\n<p>  <\/p>\n<table border=\"1\">\n<thead>\n<tr>\n<th><\/th>\n<th>CRIM<\/th>\n<th>ZN<\/th>\n<th>INDUS<\/th>\n<th>CHAS<\/th>\n<th>NOX<\/th>\n<th>RM<\/th>\n<th>AGE<\/th>\n<th>DIS<\/th>\n<th>RAD<\/th>\n<th>TAX<\/th>\n<th>PTRATIO<\/th>\n<th>B<\/th>\n<th>LSTAT<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>0.00632<\/td>\n<td>18.0<\/td>\n<td>2.31<\/td>\n<td>0.0<\/td>\n<td>0.538<\/td>\n<td>6.575<\/td>\n<td>65.2<\/td>\n<td>4.0900<\/td>\n<td>1.0<\/td>\n<td>296.0<\/td>\n<td>15.3<\/td>\n<td>396.90<\/td>\n<td>4.98<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>0.02731<\/td>\n<td>0.0<\/td>\n<td>7.07<\/td>\n<td>0.0<\/td>\n<td>0.469<\/td>\n<td>6.421<\/td>\n<td>78.9<\/td>\n<td>4.9671<\/td>\n<td>2.0<\/td>\n<td>242.0<\/td>\n<td>17.8<\/td>\n<td>396.90<\/td>\n<td>9.14<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>0.02729<\/td>\n<td>0.0<\/td>\n<td>7.07<\/td>\n<td>0.0<\/td>\n<td>0.469<\/td>\n<td>7.185<\/td>\n<td>61.1<\/td>\n<td>4.9671<\/td>\n<td>2.0<\/td>\n<td>242.0<\/td>\n<td>17.8<\/td>\n<td>392.83<\/td>\n<td>4.03<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>0.03237<\/td>\n<td>0.0<\/td>\n<td>2.18<\/td>\n<td>0.0<\/td>\n<td>0.458<\/td>\n<td>6.998<\/td>\n<td>45.8<\/td>\n<td>6.0622<\/td>\n<td>3.0<\/td>\n<td>222.0<\/td>\n<td>18.7<\/td>\n<td>394.63<\/td>\n<td>2.94<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>0.06905<\/td>\n<td>0.0<\/td>\n<td>2.18<\/td>\n<td>0.0<\/td>\n<td>0.458<\/td>\n<td>7.147<\/td>\n<td>54.2<\/td>\n<td>6.0622<\/td>\n<td>3.0<\/td>\n<td>222.0<\/td>\n<td>18.7<\/td>\n<td>396.90<\/td>\n<td>5.33<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0443\u044e \u043b\u0438\u043d\u0435\u0439\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/961\/290\/e84\/961290e846c5037b01c4b2691da75909.svg\" alt=\"$ PRICE \\sim CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+PTRATIO+B+LSTAT$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Prior \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u2014 <code>Normal(mu=0, tau=1.0E-6)<\/code>, \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u2014 <code>Flat<\/code>.<br \/>  \u041e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/arxiv.org\/abs\/1608.04471\">SVGD<\/a> \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from functools import partial with pm.Model() as lm_model:      lm_model = pm.GLM(x=data, y=y)     # \u0434\u043b\u044f \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0435\u0441\u0442\u044c \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u043e\u0440\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0447\u0435\u0440\u0435\u0437 pm.fit     histogram = pm.fit(200, method='svgd', obj_optimizer=partial(pm.adagrad, learning_rate=.7))<\/code><\/pre>\n<p>  <\/p>\n<pre><code>100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 200\/200 [00:05&lt;00:00, 35.31it\/s]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0432\u043e\u0442, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435! \u041f\u043e \u043d\u0435\u043c\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b, \u0447\u0442\u043e \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043b\u044f \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438 \u043d\u0430\u0448\u0438\u0445 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u043e\u0440\u0430\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># sample_vp \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pn.sample.  # \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u0438\u0437 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f pm.forestplot(histogram.sample_vp(300), varnames=data.columns);<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d86\/b40\/602\/d86b40602bb440eaac56de7d0c5cc26a.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<h1 id=\"bayesovskie-neyronnye-seti\">\u0411\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438<\/h1>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/ai2-s2-public.s3.amazonaws.com\/figures\/2016-11-08\/da6057368920585bcf2443295b98418840f1fc80\/1-Figure1-1.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0431\u044d\u043a\u0435\u043d\u0434 <code>PyMC3<\/code> \u2014 <code>Theano<\/code>, \u0442\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0436\u0435\u043b\u0430\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u044b\u0432\u043e\u0434 \u0434\u043b\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439. \u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Lasagne<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043e\u0441\u0442\u044c\u044e \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432\u0435\u0441\u0430. \u0412 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0435\u0441\u043e\u0432 \u0431\u0435\u0440\u0443\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430. <\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e \u0432\u0441\u0435 \u0438\u043d\u0430\u0447\u0435. \u0412\u0435\u0441\u0430 \u0441\u0435\u0442\u0438 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043d\u0435\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441 \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c. \u0412 \u0438\u0434\u0435\u0430\u043b\u0435 \u043d\u0430 \u043d\u0438\u0445 \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0441\u0442\u043d\u044b\u0439 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u044b\u0432\u043e\u0434, \u043d\u043e \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438, \u0447\u0442\u043e \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 \u0434\u0430\u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u0430 \u0442\u0443\u0442 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0438\u043d\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c. \u041e\u0431\u044b\u0447\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u043f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0445 \u0441\u0435\u0442\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0439 ADVI. \u0418\u043c \u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0443\u0442.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from lasagne.layers import * import lasagne from sklearn import datasets from sklearn.preprocessing import scale from sklearn.cross_validation import train_test_split from sklearn.datasets import make_moons<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0442 <code>sklearn<\/code><\/p>\n<p>  <\/p>\n<pre><code class=\"python\">X, Y = make_moons(noise=0.2, random_state=0, n_samples=1000) X = scale(X) # \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0438\u043f, \u0438\u043d\u0430\u0447\u0435 X \u0438 Y float64 X = X.astype(theano.config.floatX) Y = Y.astype(theano.config.floatX) X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=.5)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">fig, ax = plt.subplots() ax.scatter(X[Y==0, 0], X[Y==0, 1], color='b', label='Class 0') ax.scatter(X[Y==1, 0], X[Y==1, 1], color='r', label='Class 1') sns.despine(); ax.legend() ax.set(xlabel='X', ylabel='Y', title='Toy binary classification data set');<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/802\/625\/664\/8026256649d64ad280666aebd6eb0d85.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f <code>Lasagne<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>theano<\/code>. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 <code>PyMC3<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0430\u0434\u0430\u043f\u0442\u0435\u0440.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import itertools class RandomWeight(object):     counter = itertools.count(0)     def __init__(self, mu=0, sd=1):         self.mu = mu         self.sd = sd      def __call__(self, shape):         name = 'auto_%s' % next(self.counter)         return pm.Normal(name, self.mu, self.sd,                        testval=lasagne.init.GlorotUniform()(shape),                       shape=shape, dtype=theano.config.floatX)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0435\u0441\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">input_var = theano.shared(X_train) out_var = theano.shared(Y_train) with pm.Model() as nnet:     inp = InputLayer((None, 2), input_var)     # \u0431\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0441\u0435\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u043d\u0435\u0435 \u0442\u0443\u0442 \u0437\u0430\u0431\u0438\u0442\u044c     z = DenseLayer(inp, 5, W=RandomWeight(), b=None, nonlinearity=tt.tanh)     z = DenseLayer(z, 5, W=RandomWeight(), b=None, nonlinearity=tt.tanh)     p = DenseLayer(z, 1, W=RandomWeight(), b=None, nonlinearity=tt.nnet.sigmoid)     # \u0432\u043c\u0435\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u0442\u0435\u043f\u0435\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u0430\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430, \u0435\u0435 -p(D|z) \u0431\u0443\u0434\u0435\u0442 \u0438\u0433\u0440\u0430\u0442\u044c \u0440\u043e\u043b\u044c \u043f\u043e\u0442\u0435\u0440\u044c     pm.Bernoulli('observed', p=get_output(p).flatten(), observed=out_var)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0439 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u044b\u0432\u043e\u0434 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e ADVI<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">with nnet:     inference = pm.ADVI()     approx = inference.fit(30000)<\/code><\/pre>\n<p>  <\/p>\n<pre><code>Average Loss = 132.78: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 30000\/30000 [00:35&lt;00:00, 847.38it\/s]  Finished [100%]: Average Loss = 132.78<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">plt.figure(figsize=(12, 6)) plt.plot(inference.hist, alpha=.3) plt.legend() plt.ylabel('-ELBO') plt.xlabel('iteration');<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/db4\/f71\/70e\/db4f7170eb7d4c84bcd53f2394608d2b.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0432\u0445\u043e\u0434 x = tt.matrix('X') # \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u044d\u043c\u043f\u043b\u043e\u0432 n = tt.iscalar('n') # \u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 \u0442\u0435\u0430\u043d\u043e \u0441\u0442\u043e\u0438\u0442 compute_test_value='raise', \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043d\u0435 \u0440\u0443\u0433\u0430\u043b\u0441\u044f, \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 x.tag.test_value = np.empty_like(X_train[:10]) n.tag.test_value = 100 # \u0423 \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b sample_node \u0438 apply_replacements # \u041e\u043d\u0438 \u0443\u0431\u0438\u0440\u0430\u044e\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0433\u0440\u0430\u0444\u0430 \u043e\u0442 \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 pymc3 \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442 \u0438\u0445 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0435\u0439 _sample_proba = approx.sample_node(get_output(p).flatten(), size=n,                                    more_replacements={input_var:x}) # \u0412\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e # \u0423 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0439 \u043d\u0435\u0442 \u0430\u043f\u0434\u0435\u0439\u0442\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e  sample_proba = theano.function([x, n], _sample_proba)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u0432\u044b\u0437\u0432\u0430\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">pred = sample_proba(X_test, 500).mean(0) &gt; 0.5<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">fig, ax = plt.subplots() ax.scatter(X_test[pred==0, 0], X_test[pred==0, 1], color='b') ax.scatter(X_test[pred==1, 0], X_test[pred==1, 1], color='r') sns.despine() ax.set(title='Predicted labels in testing set', xlabel='X', ylabel='Y');<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/39d\/0e2\/208\/39d0e22082114f0892e1eb5d50f52ae2.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<h1 id=\"razdelyayuschaya-granica\">\u0420\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430<\/h1>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0443\u0434\u0430 \u0432\u0441\u0435 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438 \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">grid = np.mgrid[-3:3:100j,-3:3:100j].astype('float32') grid_2d = grid.reshape(2, -1).T ppc = sample_proba(grid_2d ,500)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">cmap = sns.diverging_palette(250, 12, s=85, l=25, as_cmap=True) fig, ax = plt.subplots(figsize=(16, 9)) contour = ax.contourf(grid[0], grid[1], ppc.mean(axis=0).reshape(100, 100), cmap=cmap) ax.scatter(X_test[pred==0, 0], X_test[pred==0, 1], color='b') ax.scatter(X_test[pred==1, 0], X_test[pred==1, 1], color='r') cbar = plt.colorbar(contour, ax=ax) _ = ax.set(xlim=(-3, 3), ylim=(-3, 3), xlabel='X', ylabel='Y'); cbar.ax.set_ylabel('Posterior predictive mean probability of class label = 0');<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/088\/96e\/76e\/08896e76e47a4dd39b0ebfa811d97de1.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<h1 id=\"uverennost-modeli\">\u0423\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438<\/h1>\n<p>  <\/p>\n<p>\u0423\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u0445 \u2014 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430. \u041e\u0431\u044b\u0447\u043d\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044f\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u0435\u0447\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0435 \u043d\u0430\u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041e\u043d\u0430 \u0441\u0430\u043c\u0430 \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u043d\u0435\u0441\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0439 \u043c\u0438\u0440: \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0446\u0435\u043d\u043a\u0438. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e, \u0438, \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 <code>PyMC3<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">cmap = sns.cubehelix_palette(light=1, as_cmap=True) fig, ax = plt.subplots(figsize=(16, 9)) contour = ax.contourf(grid[0], grid[1], ppc.std(axis=0).reshape(100, 100), cmap=cmap) ax.scatter(X_test[pred==0, 0], X_test[pred==0, 1], color='b') ax.scatter(X_test[pred==1, 0], X_test[pred==1, 1], color='r') cbar = plt.colorbar(contour, ax=ax) _ = ax.set(xlim=(-3, 3), ylim=(-3, 3), xlabel='X', ylabel='Y'); cbar.ax.set_ylabel('Uncertainty (posterior predictive standard deviation)');<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/2d1\/d1b\/300\/2d1d1b3001a14819a83adcfad83a4070.png\" alt=\"png\"\/><\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0432\u0435\u0449\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PyMC3. \u0417\u0430 \u043a\u0430\u0434\u0440\u043e\u043c \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f, \u0433\u0430\u0443\u0441\u0441\u043e\u0432\u0441\u043a\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, LDA \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 PyMC3 \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0443 \u0441\u0435\u0431\u044f. \u0412\u0441\u0435 \u043e\u043d\u0438 \u0432 \u0432\u0438\u0434\u0435 <em>jupyter<\/em> \u0442\u0435\u0442\u0440\u0430\u0434\u043e\u043a <a href=\"https:\/\/github.com\/pymc-devs\/pymc3\/blob\/master\/docs\/source\/notebooks\/\">\u0432\u043e\u0442 \u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<p>  <\/p>\n<h1 id=\"ssylki-na-ispolzuemye-istochniki\">\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/h1>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/CamDavidsonPilon\/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers\">Bayesian Methods for Hackers<\/a><\/li>\n<li><a href=\"https:\/\/arxiv.org\/abs\/1505.05424\">Weight Uncertainty in Neural Networks<\/a><\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Checking_whether_a_coin_is_fair\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043c\u043e\u043d\u0435\u0442\u043a\u043e\u0439<\/a><\/li>\n<li><a href=\"https:\/\/arxiv.org\/abs\/1603.00788\">Automatic Differentiation Variational Inference<\/a><\/li>\n<li><a href=\"https:\/\/arxiv.org\/abs\/1610.09033\">Operator Variational Inference<\/a><\/li>\n<li><a href=\"https:\/\/arxiv.org\/abs\/1608.04471\">Stein Variational Gradient Descent<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/ferrine\/pymc3\/blob\/master\/docs\/source\/notebooks\/bayesian_neural_network_opvi-advi.ipynb\">\u041f\u043e\u043b\u043d\u0430\u044f \u0442\u0435\u0442\u0440\u0430\u0434\u043a\u0430 \u0441 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e<\/a><\/li>\n<li><a href=\"https:\/\/gist.github.com\/ferrine\/acefc31ff4f688011e94d3db285e1f83\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a> \u043d\u0430 jupyter \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u0441 \u044d\u0442\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"blagodarnosti\">\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/h1>\n<p>  <\/p>\n<p>\u0425\u043e\u0447\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e <a href=\"https:\/\/habrahabr.ru\/users\/mephistopheies\/\" class=\"user_link\">mephistopheies<\/a> \u0438 <a href=\"https:\/\/habrahabr.ru\/users\/bauchgefuehl\/\" class=\"user_link\">bauchgefuehl<\/a> \u0437\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0432 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p> \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:\/\/habrahabr.ru\/post\/322716\/\"> https:\/\/habrahabr.ru\/post\/322716\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<h1 id=\"pymc3---msms-i-ne-tolko\">PyMC3 \u2014 \u041c\u0421\u041c\u0421 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e<\/h1>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/pymc-devs\/pymc3\/master\/docs\/pymc3_logo.jpg\"\/><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440!<\/p>\n<p>  <\/p>\n<p>\u0412 <a href=\"https:\/\/habrahabr.ru\/company\/wunderfund\/blog\/279545\/\">\u044d\u0442\u043e\u043c<\/a> \u043f\u043e\u0441\u0442\u0435 \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0441\u044f PyMC3. \u0422\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e \u043e\u0441\u043d\u043e\u0432\u044b MCMC-\u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0417\u0434\u0435\u0441\u044c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 (<a href=\"https:\/\/arxiv.org\/abs\/1603.00788\">ADVI<\/a>), \u043f\u0440\u043e \u0442\u043e, \u0437\u0430\u0447\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0438 \u043f\u043e\u043a\u0430\u0436\u0443 \u043d\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0437 \u0433\u0430\u043b\u0435\u0440\u0435\u0438 PyMC3, \u0447\u0435\u043c \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0430\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043d\u043e \u044d\u0442\u043e \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435. \u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c!<\/p>\n<p>  <\/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-285611","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285611","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=285611"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285611\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}