{"id":308127,"date":"2020-08-07T09:00:18","date_gmt":"2020-08-07T09:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308127"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-08-07T09:00:18","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308127","title":{"rendered":"TensorFlow.js: \u0427\u0430\u0441\u0442\u044c 1: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Low-Level API \u0434\u043b\u044f \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/513172\/\">\u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f Python \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0434\u043b\u044f \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u044f\u0432\u043b\u044f\u0435\u0442\u0435\u0441\u044c JS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0438 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u044b \u043e\u043a\u0443\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u0442 \u043c\u0438\u0440, \u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0439 \u0430\u0440\u0441\u0435\u043d\u0430\u043b \u043d\u043e\u0432\u044b\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/www.tensorflow.org\/js\" rel=\"nofollow\">TensorFlow.js<\/a><br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  <b>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f TensorFlow.js \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435<\/b><br \/>   \u2014 <i>\u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c<\/i> \u2014 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0438\u043c\u0435\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 (\u0433\u0440\u0430\u0444\u0438\u043a\u0438, \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u0438 \u0434\u0440.);<br \/>   \u2014 <i>\u0441\u0435\u043d\u0441\u043e\u0440\u044b<\/i> \u2014 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0435\u043d\u0441\u043e\u0440\u0430\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (\u043a\u0430\u043c\u0435\u0440\u0430, GPS, \u0430\u043a\u0441\u0435\u043b\u0435\u0440\u043e\u043c\u0435\u0442\u0440 \u0438 \u0434\u0440.);<br \/>  &#8212;<i> \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/i> \u2014 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440;<br \/>   \u2014 <i>\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 Python<\/i>.<\/p>\n<p>  <b>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/b><br \/>  \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u0441\u0442\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. <br \/>  \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u043e-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u0442\u0435\u043d\u0437\u043e\u0440\u0430\u043c\u0438), \u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 WebGL. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0431\u044b \u0442\u0435 \u0436\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u043b\u0438\u0441\u044c \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c JS. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 fallback \u043d\u0430 \u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 WebGL \u043f\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 (\u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/caniuse.com\/#feat=webgl\" rel=\"nofollow\">caniuse<\/a> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 WebGL \u0435\u0441\u0442\u044c \u0443 97.94% \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439).<br \/>  \u0414\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 Node.js \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f native-binding \u0441 TensorFlow. \u0422\u0443\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043a\u0441\u0435\u043b\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c CPU, GPU \u0438 TPU (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Tensor_processing_unit\" rel=\"nofollow\">Tensor Processing Unit<\/a>)<\/p>\n<p>  <b>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 TensorFlow.js<\/b><br \/>  1. <b>Lowest Layer<\/b> \u2014 \u044d\u0442\u043e\u0442 \u0441\u043b\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u0435\u043d \u0437\u0430 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0434 \u0442\u0435\u043d\u0437\u043e\u0440\u0430\u043c\u0438. <br \/>  2. <b>The Ops API<\/b> \u2014 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0410\u041f\u0418 \u0434\u043b\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0434 \u0442\u0435\u043d\u0437\u043e\u0440\u0430\u043c\u0438.<br \/>  3. <b>Layers API<\/b> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0441\u043b\u043e\u0435\u0432 (dense, convolutional). \u042d\u0442\u043e\u0442 \u0441\u043b\u043e\u0439 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 API Keras \u043d\u0430 Python \u0438 \u0438\u043c\u0435\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 Keras Python.  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/k-\/rg\/up\/k-rgupjbjhzrftn28uz7bqkhqae.png\" width=\"500\"><\/div>\n<p>  <b>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/b><br \/>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043a\u0443\u044e \u043b\u0438\u043d\u0435\u0439\u043d\u0443\u044e \u043a\u0440\u0438\u0432\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043b\u0435\u0436\u0430\u043b\u0430 \u0431\u044b \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u043e\u0447\u043a\u0430\u043c.   <\/p>\n<div style=\"text-align:center;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/z7\/ip\/md\/z7ipmdjxz4hw288krhooefuci78.png\" width=\"300\" height=\"300\"><\/div>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/b><br \/>  \u042f\u0434\u0440\u043e\u043c \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6f6\/339\/8e3\/6f63398e31b94f974ef050608c8fce6a.svg\" alt=\"$y=kx+b$\" data-tex=\"display\"><\/math><\/p>\n<p>  \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a:  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d93\/d98\/679\/d93d986792dd1dba86e931bc55669d21.svg\" alt=\"$(x^{(0)}_{t},y^{(0)}_{t} ), (x^{(1)}_{t}, y^{(1)}_{t}), ...(x^{(N)}_{t},y^{(N)}_{t})$\" data-tex=\"display\"><\/math><\/p>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b82\/8e2\/475\/b828e2475a3a56280b895f35eb250ea2.svg\" alt=\"$j$\" data-tex=\"inline\"><\/math>-\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u044b\u043b\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0a5\/f6d\/99a\/0a5f6d99a01ecc948ae9f89ca92a2a7a.svg\" alt=\"$k^{(j)}, b^{(j)}$\" data-tex=\"inline\"><\/math>. \u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u043d\u044b \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 (loss), \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u043c\u0443 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044e. Tensorflow.js \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 loss \u0444\u0443\u043d\u043a\u0446\u0438\u0439: <a href=\"https:\/\/js.tensorflow.org\/api\/latest\/#metrics.meanAbsoluteError\" rel=\"nofollow\">tf.metrics.meanAbsoluteError<\/a>, <a href=\"https:\/\/js.tensorflow.org\/api\/latest\/#metrics.meanSquaredError\" rel=\"nofollow\">tf.metrics.meanSquaredError<\/a> \u0438 \u0434\u0440.  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bda\/cb1\/0d0\/bdacb10d0c8d63b3daab44274f23e1d8.svg\" alt=\"$L(k^{(j)},b^{(j)})=\\sum_{i=1}^{N} (y^{(i)}_{predicted} - y^{(i)}_{t})^{2}=\\sum_{i=1}^{N}((k^{(j)}\\cdot x^{(i)}+b^{(j)})-y^{(i)}_{t})$\" data-tex=\"display\"><\/math><\/p>\n<p>  \u0426\u0435\u043b\u044c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u2014 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a5a\/4e0\/afa\/a5a4e0afaec84939dbfda220172b2be0.svg\" alt=\"$L$\" data-tex=\"inline\"><\/math>. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e:<br \/>   \u2014 \u043d\u0430\u0439\u0442\u0438 \u0432\u0435\u043a\u0442\u043e\u0440-\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044f \u0447\u0430\u0441\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u043f\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0a5\/f6d\/99a\/0a5f6d99a01ecc948ae9f89ca92a2a7a.svg\" alt=\"$k^{(j)}, b^{(j)}$\" data-tex=\"inline\"><\/math>;<br \/>   \u2014 \u043e\u0442\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0432 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0432\u0435\u043a\u0442\u043e\u0440\u0430-\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0448\u0438\u0431\u043a\u0438:  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/193\/e87\/6f2\/193e876f27716fa7c06c28123f2862fb.svg\" alt=\"$k^{(j+1)}=k^{(j)} - \\mu \\bigtriangledown_{k^{(j)}} L(k^{(j)},b^{(j)})=k^{(j)} - \\mu\\frac{\\partial L(k^{(j)},b^{(j)}) }{\\partial k^{(j)}};$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/764\/e61\/e7d\/764e61e7dabe63c37e04da454a1f867e.svg\" alt=\"$b^{(j+1)}=b^{(j)} - \\mu \\bigtriangledown_{b^{(j)}} L(k^{(j)},b^{(j)})=b^{(j)} - \\mu\\frac{\\partial L(k^{(j)},b^{(j)}) }{\\partial b^{(j)}};$\" data-tex=\"display\"><\/math><\/p>\n<p>  \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1ec\/36e\/4ef\/1ec36e4efef9e67482ea2b86700b82f2.svg\" alt=\"$\\mu$\" data-tex=\"inline\"><\/math> \u2014 \u0448\u0430\u0433 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (learning rate) \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438. \u0414\u043b\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430 \u043e\u043d \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 learning rate \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u0434\u043e\u043b\u0433\u043e\u0439 \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u043c\u0443 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044e \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c (\u0440\u0438\u0441\u0443\u043d\u043e\u043a 2), \u0430 \u0441\u0438\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u2014 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0440\u0438\u0441\u0443\u043d\u043e\u043a 1.  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<th><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sk\/kl\/0v\/skkl0vwhcmf1lafm_58m8ycvjwq.jpeg\"><br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yx\/qe\/z1\/yxqez1hgx_uszg82kh1s5n3k_pq.jpeg\">   <\/th>\n<th><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/rw\/88\/02\/rw8802eddghim38c6rskz34bgfa.jpeg\"><br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wb\/af\/hi\/wbafhie-ag5zqjde9moh407_fus.jpeg\">  <\/th>\n<\/tr>\n<tr>\n<td>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1: \u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0448\u0430\u0433\u0430 (learning-rate)<\/td>\n<td>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2: \u041c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u0448\u0430\u0433\u0430 (learning-rate)<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>  <b>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 Tensorflow.js<\/b><br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f loss-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435) \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0431\u044b \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">function loss(ysPredicted, ysReal) {     const squaredSum = ysPredicted.reduce(         (sum, yPredicted, i) =&gt; sum + (yPredicted - ysReal[i]) ** 2,         0);     return squaredSum \/ ysPredicted.length; } <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0435\u043b\u0438\u043a\u043e. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 loss-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u2014 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c tensorflow, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f WebGL. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435, \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435:  <\/p>\n<pre><code class=\"javascript\">    function loss(ysPredicted, ysReal) =&gt; {         const ysPredictedTensor = tf.tensor(ysPredicted);         const ysRealTensor = tf.tensor(ysReal);         const loss = ysPredictedTensor.sub(ysRealTensor).square().mean();         return loss.dataSync()[0];     }; <\/code><\/pre>\n<p>  <b>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e TensorFlow.js<\/b><br \/>  \u0425\u043e\u0440\u043e\u0448\u0430\u044f \u043d\u043e\u0432\u043e\u0441\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 (loss), \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043d\u044b\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445, \u0437\u0430 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 (backpropogation). \u041d\u0430\u043c \u043b\u0438\u0448\u044c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<br \/>   \u2014 \u0437\u0430\u0434\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c (\u043b\u0438\u043d\u0435\u0439\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435);<br \/>   \u2014 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0448\u0438\u0431\u043a\u0438 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044d\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435)<br \/>   \u2014 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 (\u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439)<\/p>\n<p>  <b>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0442\u0435\u043d\u0437\u043e\u0440<\/b><br \/>  \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0441 \u0442\u0435\u043d\u0437\u043e\u0440\u0430\u043c\u0438 \u0432 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0435 \u2014 \u044d\u0442\u043e \u0441\u043a\u0430\u043b\u044f\u0440, \u0432\u0435\u043a\u0442\u043e\u0440, 2D \u2014 \u043c\u0430\u0442\u0440\u0438\u0446\u0430, 3D \u2014 \u043c\u0430\u0442\u0440\u0438\u0446\u0430. \u0422\u0435\u043d\u0437\u043e\u0440 \u2014 \u044d\u0442\u043e \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e. \u042d\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0435 \u043f\u043e \u0442\u0438\u043f\u0443 \u0434\u0430\u043d\u043d\u044b\u0435 (tensorflow \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 int32, float32, bool, complex64, string) \u0438 \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0441\u0435\u0439 (\u0440\u0430\u043d\u043a) \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043e\u0441\u0435\u0439). \u041d\u0438\u0436\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e 3D-\u043c\u0430\u0442\u0440\u0438\u0446, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0441\u0435\u0439 \u0443 \u0442\u0435\u043d\u0437\u043e\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e: 5D, 6D,&#8230;ND.<br \/>  TensorFlow \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0410\u041f\u0418 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0435\u043d\u0437\u043e\u0440\u0430:  <\/p>\n<pre><code class=\"javascript\">tf.tensor\u00a0(values, shape?, dtype?)<\/code><\/pre>\n<p>  \u0433\u0434\u0435 <b>shape<\/b> \u2014 \u0444\u043e\u0440\u043c\u0430 \u0442\u0435\u043d\u0437\u043e\u0440\u0430 \u0438 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0441\u0435\u0439, \u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0434\u043e\u043b\u044c \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043e\u0441\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 4&#215;2 (4 \u0441\u0442\u0440\u043e\u043a\u0438, 2 \u043a\u043e\u043b\u043e\u043d\u043a\u0438), \u0444\u043e\u0440\u043c\u0430 \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434 [4, 2].  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<th width=\"280\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<\/tr>\n<tr>\n<td> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bg\/_d\/-k\/bg_d-kamlfchijwfrbnnxhkj0-w.jpeg\">    <\/td>\n<td> <b>\u0421\u043a\u0430\u043b\u044f\u0440<\/b><br \/>   \u0420\u0430\u043d\u043a: 0<br \/>   \u0424\u043e\u0440\u043c\u0430: []<br \/>   JS \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430:   <\/p>\n<pre><code class=\"javascript\">2<\/code><\/pre>\n<p>   TensorFlow API:   <\/p>\n<pre><code class=\"javascript\">tf.scalar(2); tf.tensor(2, []); <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<tr>\n<td> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vj\/uh\/aj\/vjuhaj-8ahjvn9884juercnymtw.jpeg\">    <\/td>\n<td> <b> \u0412\u0435\u043a\u0442\u043e\u0440<\/b><br \/>   \u0420\u0430\u043d\u043a: 1<br \/>   \u0424\u043e\u0440\u043c\u0430: [4]<br \/>   JS \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430:   <\/p>\n<pre><code class=\"javascript\">[1, 2, 3, 4]<\/code><\/pre>\n<p>   TensorFlow API:  <\/p>\n<pre><code class=\"javascript\">tf.tensor([ 1, 2, 3, 4]); tf.tensor([1, 2, 3, 4], [4]); tf.tensor1d([1, 2, 3, 4]); <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/s6\/x6\/hh\/s6x6hhfm9w8ie22dkwerkta7ngq.jpeg\"><\/td>\n<td><b>\u041c\u0430\u0442\u0440\u0438\u0446\u0430<\/b><br \/>  \u0420\u0430\u043d\u043a: 2<br \/>  \u0424\u043e\u0440\u043c\u0430: [4,2]<br \/>  JS \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430:   <\/p>\n<pre><code class=\"javascript\">[     [1, 2],      [3, 4],      [5, 6],      [7, 8] ]<\/code><\/pre>\n<p>   TensorFlow API:  <\/p>\n<pre><code class=\"javascript\">tf.tensor([[1, 2],[3, 4],[5,6],[7,8]]); tf.tensor([1, 2, 3, ... 7, 8], [4,2]);  tf.tensor2d([[1, 2],[3, 4]...[7,8]]); tf.tensor2d([1, 2, 3, ... 7, 8], [4,2]);<\/code><\/pre>\n<p>  <\/td>\n<\/tr>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/_k\/zx\/yz\/_kzxyzx5ru3nknvqhg4fes04zjs.jpeg\"><\/td>\n<td><b>\u041c\u0430\u0442\u0440\u0438\u0446\u0430<\/b><br \/>  \u0420\u0430\u043d\u043a: 3<br \/>  \u0424\u043e\u0440\u043c\u0430:[4,2,3]<br \/>  JS \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430:   <\/p>\n<pre><code class=\"javascript\">[     [ [ 1,  2], [ 3,  4], [ 5,  6] ],     [ [ 7,  8], [ 9, 10], [11, 12] ],     [ [13, 14], [15, 16], [17, 18] ],     [ [19, 20], [21, 22], [23, 24] ] ]<\/code><\/pre>\n<p>   TensorFlow API:  <\/p>\n<pre><code class=\"javascript\">tf.tensor([      [ [ 1,  2], [ 3,  4], [ 5,  6] ],     ....     [ [19, 20], [21, 22], [23, 24] ]  ]); tf.tensor([1, 2, 3, .... 24], [4, 2 ,3]) <\/code><\/pre>\n<p>  <\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>  <b>\u041b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e TensorFlow.js<\/b><br \/>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u044b\u043c. \u041b\u0438\u043d\u0435\u0439\u043d\u0443\u044e \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a \u043f\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0432\u0438\u0434\u0430. \u0418\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ch\/ju\/qb\/chjuqbhfl5gypp3ckyaeciwfe4c.png\"><\/p>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445, \u0430 \u0442\u0443\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043b\u0438\u0448\u044c \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0438 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435.<\/p>\n<pre><code class=\"javascript\">import * as tf from '@tensorflow\/tfjs';  export default class AbstractRegressionModel {     constructor(         width,         height,         optimizerFunction = tf.train.sgd,         maxEpochPerTrainSession = 100,         learningRate = 0.1,         expectedLoss = 0.001     ) {         this.width = width;         this.height = height;         this.optimizerFunction = optimizerFunction;         this.expectedLoss = expectedLoss;         this.learningRate = learningRate;         this.maxEpochPerTrainSession = maxEpochPerTrainSession;          this.initModelVariables();          this.trainSession = 0;         this.epochNumber = 0;         this.history = [];     } }<\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 width \u0438 height \u2014 \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0448\u0438\u0440\u0438\u043d\u0430 \u0438 \u0432\u044b\u0441\u043e\u0442\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0422.\u0435. \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d4d\/e33\/141\/d4de33141a26f88a8605959cd024ab1a.svg\" alt=\"$x\\in[0, width], y\\in[0, height]$\" data-tex=\"inline\"><\/math>, \u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u043c\u0435\u0442\u044c: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e5b\/48a\/d41\/e5b48ad4117741a1da15cbdac22e2556.svg\" alt=\"$x_{norm}\\in[0, 1], y_{norm}\\in[0, 1]$\" data-tex=\"inline\"><\/math><br \/>  <i>optimizerFunction<\/i> \u2014 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0433\u0438\u0431\u043a\u0438\u043c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u044b, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043c\u044b \u0437\u0430\u0434\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430 <a href=\"https:\/\/js.tensorflow.org\/api\/latest\/#train.sgd\" rel=\"nofollow\">tf.train.sgd<\/a>. \u041f\u043e\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043b \u0431\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0434\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c learningRate \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u044b: <a href=\"https:\/\/js.tensorflow.org\/api\/latest\/#train.momentum\" rel=\"nofollow\">tf.train.momentum<\/a>, <a href=\"https:\/\/js.tensorflow.org\/api\/latest\/#train.adam\" rel=\"nofollow\">tf.train.adam<\/a>. <br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u0431\u044b\u043b \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u0435\u043d \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <i>maxEpochPerTrainSesion<\/i> \u0438 <i>expectedLoss<\/i> \u2014 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u0440\u0435\u043a\u0440\u0430\u0442\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439, \u0438\u043b\u0438 \u043a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0438\u0436\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 (\u0432\u0441\u0435 \u0443\u0447\u0442\u0435\u043c \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <i>train<\/i> \u043d\u0438\u0436\u0435).<br \/>  \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <i>initModelVariables<\/i> \u2014 \u043d\u043e \u043a\u0430\u043a \u0438 \u0434\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c, \u043c\u044b \u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0433\u043e \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043f\u043e\u0437\u0436\u0435.   <\/p>\n<pre><code class=\"javascript\">initModelVariables() {     throw Error('Model variables should be defined') } <\/code><\/pre>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438 train:   <\/p>\n<pre><code class=\"javascript\">\/**      * Train model until explicitly stop process via invocation of stop method      * or loss achieve necessary accuracy, or train achieve max epoch value      *      * @param x - array of x coordinates      * @param y - array of y coordinates      * @param callback - optional, invoked after each training step      *\/     async train(x, y, callback) {         const currentTrainSession = ++this.trainSession;         this.lossVal = Number.POSITIVE_INFINITY;         this.epochNumber = 0;         this.history = [];          \/\/ convert array into tensors         const input = tf.tensor1d(this.xNormalization(x));         const output = tf.tensor1d(this.yNormalization(y));          while (             currentTrainSession === this.trainSession             &amp;&amp; this.lossVal &gt; this.expectedLoss             &amp;&amp; this.epochNumber &lt;= this.maxEpochPerTrainSession             ) {             const optimizer = this.optimizerFunction(this.learningRate);             optimizer.minimize(() =&gt; this.loss(this.f(input), output));             this.history = [...this.history, {                 epoch: this.epochNumber,                 loss: this.lossVal             }];             callback &amp;&amp; callback();             this.epochNumber++;             await tf.nextFrame();         }     } <\/code><\/pre>\n<p>  <i>trainSession<\/i> \u2014 \u044d\u0442\u043e \u043f\u043e \u0441\u0443\u0442\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u0435\u0441\u0441\u0438\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0410\u041f\u0418 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c train \u043c\u0435\u0442\u043e\u0434, \u043f\u0440\u0438 \u0442\u043e\u043c \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0441\u0435\u0441\u0441\u0438\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c. <br \/>  \u0418\u0437 \u043a\u043e\u0434\u0430 \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0435\u043c tensor1d, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0443\u0442:  <\/p>\n<pre><code class=\"javascript\">xNormalization = xs =&gt; xs.map(x =&gt; x \/ this.width); yNormalization = ys =&gt; ys.map(y =&gt; y \/ this.height); yDenormalization = ys =&gt; ys.map(y =&gt; y * this.height); <\/code><\/pre>\n<p>  \u0412 \u0446\u0438\u043a\u043b\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c loss \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u041a\u0430\u043a \u0438 \u0434\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c, loss-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u0430 \u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435\u043c. \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c \u0410\u041f\u0418 tensorflow.js \u0438\u043c\u0435\u0435\u043c:  <\/p>\n<pre><code class=\"javascript\">    \/**      * Calculate loss function as mean-square deviation      *      * @param predictedValue - tensor1d - predicted values of calculated model      * @param realValue - tensor1d - real value of experimental points      *\/     loss = (predictedValue, realValue) =&gt; {         \/\/ L = sum ((x_pred_i - x_real_i)^2) \/ N         const loss = predictedValue.sub(realValue).square().mean();         this.lossVal = loss.dataSync()[0];         return loss;     }; <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043a\u0430 <br \/>   \u2014 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043b\u0438\u043c\u0438\u0442 \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439<br \/>   \u2014 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438<br \/>   \u2014 \u043d\u0435 \u043d\u0430\u0447\u0430\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441<br \/>  \u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u0430\u043a \u0432\u044b\u0437\u0432\u0430\u043d\u0430 loss-\u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f <i>predictedValue<\/i> \u2014 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <i>f<\/i> \u2014 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0441\u0443\u0442\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f, \u0430 \u0432 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u0430\u043a \u0438 \u0434\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u2014 \u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0443:  <\/p>\n<pre><code class=\"javascript\">  f(x) {         throw Error('Model should be defined')   } <\/code><\/pre>\n<p>  \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 history \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u044d\u043f\u043e\u0445\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b \u0431\u044b \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u0432\u044b\u0434\u0430\u0432\u0430\u043b \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0410\u041f\u0418 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 <i>predict<\/i> \u043c\u0435\u0442\u043e\u0434 \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">\/**      * Predict value basing on trained model      *  @param x - array of x coordinates      *  @return Array({x: integer, y: integer}) - predicted values associated with input      *      * *\/     predict(x) {         const input = tf.tensor1d(this.xNormalization(x));         const output = this.yDenormalization(this.f(input).arraySync());         return output.map((y, i) =&gt; ({ x: x[i], y }));     } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 <i>arraySync<\/i>, \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u043a\u0430\u043a node.js, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c <i>arraySync<\/i> \u043c\u0435\u0442\u043e\u0434, \u0442\u043e \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0435\u0441\u0442\u044c \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <i>array<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Promise. Promise \u0442\u0443\u0442 \u043d\u0443\u0436\u0435\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0430\u043a \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u0432\u0441\u0435 \u043c\u0438\u0433\u0440\u0438\u0440\u0443\u044e\u0442 \u0432 WebGL \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 WebGL \u0432 JS \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<br \/>  \u041c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u043f\u043e\u043b\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u0434\u0430 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442:  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">AbstractRegressionModel.js<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import * as tf from '@tensorflow\/tfjs';  export default class AbstractRegressionModel {          constructor(         width,         height,         optimizerFunction = tf.train.sgd,         maxEpochPerTrainSession = 100,         learningRate = 0.1,         expectedLoss = 0.001     ) {         this.width = width;         this.height = height;         this.optimizerFunction = optimizerFunction;         this.expectedLoss = expectedLoss;         this.learningRate = learningRate;         this.maxEpochPerTrainSession = maxEpochPerTrainSession;          this.initModelVariables();          this.trainSession = 0;         this.epochNumber = 0;         this.history = [];     }      initModelVariables() {         throw Error('Model variables should be defined')     }      f() {         throw Error('Model should be defined')     }      xNormalization = xs =&gt; xs.map(x =&gt; x \/ this.width);     yNormalization = ys =&gt; ys.map(y =&gt; y \/ this.height);     yDenormalization = ys =&gt; ys.map(y =&gt; y * this.height);      \/**      * Calculate loss function as mean-squared deviation      *      * @param predictedValue - tensor1d - predicted values of calculated model      * @param realValue - tensor1d - real value of experimental points      *\/     loss = (predictedValue, realValue) =&gt; {         const loss = predictedValue.sub(realValue).square().mean();         this.lossVal = loss.dataSync()[0];         return loss;     };      \/**      * Train model until explicitly stop process via invocation of stop method      * or loss achieve necessary accuracy, or train achieve max epoch value      *      * @param x - array of x coordinates      * @param y - array of y coordinates      * @param callback - optional, invoked after each training step      *\/     async train(x, y, callback) {         const currentTrainSession = ++this.trainSession;         this.lossVal = Number.POSITIVE_INFINITY;         this.epochNumber = 0;         this.history = [];          \/\/ convert data into tensors         const input = tf.tensor1d(this.xNormalization(x));         const output = tf.tensor1d(this.yNormalization(y));          while (             currentTrainSession === this.trainSession             &amp;&amp; this.lossVal &gt; this.expectedLoss             &amp;&amp; this.epochNumber &lt;= this.maxEpochPerTrainSession             ) {             const optimizer = this.optimizerFunction(this.learningRate);             optimizer.minimize(() =&gt; this.loss(this.f(input), output));             this.history = [...this.history, {                 epoch: this.epochNumber,                 loss: this.lossVal             }];             callback &amp;&amp; callback();             this.epochNumber++;             await tf.nextFrame();         }     }      stop() {         this.trainSession++;     }      \/**      * Predict value basing on trained model      *  @param x - array of x coordinates      *  @return Array({x: integer, y: integer}) - predicted values associated with input      *      * *\/     predict(x) {         const input = tf.tensor1d(this.xNormalization(x));         const output = this.yDenormalization(this.f(input).arraySync());         return output.map((y, i) =&gt; ({ x: x[i], y }));     } } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0414\u043b\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d \u043e\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0433\u0434\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <i>initModelVariables<\/i> \u0438 <b>f<\/b>. <br \/>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0434 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0435\u0439, \u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 k, b \u2014 \u0438 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0442\u0435\u043d\u0437\u043e\u0440\u0430\u043c\u0438-\u0441\u043a\u0430\u043b\u044f\u0440\u0430\u043c\u0438. \u0414\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u043c\u0438 (\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438), \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430.   <\/p>\n<pre><code class=\"javascript\">initModelVariables() {    this.k = tf.scalar(Math.random()).variable();    this.b = tf.scalar(Math.random()).variable(); }<\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0410\u041f\u0418 \u0434\u043b\u044f <a href=\"https:\/\/js.tensorflow.org\/api\/latest\/#variable\" rel=\"nofollow\">variable<\/a>:  <\/p>\n<pre><code class=\"javascript\">tf.variable (initialValue, trainable?, name?, dtype?)<\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <i>trainable<\/i> \u2014 \u0431\u0443\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d\u0430 <i>true<\/i>. \u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u043c\u0438, \u0447\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0438\u043c \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043b\u0438 \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 loss-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u0442\u0440\u043e\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0437\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0439 \u0441 Keras Python, \u0438 \u043c\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0438 \u0432 \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<br \/>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0439 tensorflow API, \u0432\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u043a\u043e\u0434 \u0438 \u0432\u044b \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u0439\u043c\u0435\u0442\u0435 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e:  <\/p>\n<pre><code class=\"javascript\">f(x) {    \/\/ y = kx + b    return  x.mul(this.k).add(this.b); }<\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u0443\u044e \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"javascript\">initModelVariables() {    this.a = tf.scalar(Math.random()).variable();    this.b = tf.scalar(Math.random()).variable();    this.c = tf.scalar(Math.random()).variable(); }  f(x) {     \/\/ y = ax^2 + bx + c     return this.a.mul(x.square()).add(this.b.mul(x)).add(this.c); }<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0434\u043b\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0438 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0439:  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">LinearRegressionModel.js<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import * as tf from '@tensorflow\/tfjs'; import AbstractRegressionModel from &quot;.\/AbstractRegressionModel&quot;;  export default class LinearRegressionModel extends AbstractRegressionModel {     initModelVariables() {         this.k = tf.scalar(Math.random()).variable();         this.b = tf.scalar(Math.random()).variable();     }      f = x =&gt; x.mul(this.k).add(this.b); } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">QuadraticRegressionModel.js<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import * as tf from '@tensorflow\/tfjs'; import AbstractRegressionModel from &quot;.\/AbstractRegressionModel&quot;;  export default class QuadraticRegressionModel extends AbstractRegressionModel {     initModelVariables() {         this.a = tf.scalar(Math.random()).variable();         this.b = tf.scalar(Math.random()).variable();         this.c = tf.scalar(Math.random()).variable();     }      f = x =&gt; this.a.mul(x.square()).add(this.b.mul(x)).add(this.c); } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u0434, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 React, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 UX \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">Regression.js<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import React, { useState, useEffect } from 'react';  import Canvas from '.\/components\/Canvas'; import LossPlot from '.\/components\/LossPlot_v3'; import LinearRegressionModel from '.\/model\/LinearRegressionModel';  import '.\/RegressionModel.scss';  const WIDTH = 400; const HEIGHT = 400; const LINE_POINT_STEP = 5;  const predictedInput = Array.from({ length: WIDTH \/ LINE_POINT_STEP + 1 })     .map((v, i) =&gt; i * LINE_POINT_STEP);  const model = new LinearRegressionModel(WIDTH, HEIGHT);  export default () =&gt; {     const [points, changePoints] = useState([]);     const [curvePoints, changeCurvePoints] = useState([]);     const [lossHistory, changeLossHistory] = useState([]);      useEffect(() =&gt; {         if (points.length &gt; 0) {             const input = points.map(({ x }) =&gt; x);             const output = points.map(({ y }) =&gt; y);              model.train(input, output, () =&gt; {                 changeCurvePoints(() =&gt; model.predict(predictedInput));                 changeLossHistory(() =&gt; model.history);             });         }     }, [points]);      return (         &lt;div className=&quot;regression-low-level&quot;&gt;             &lt;div className=&quot;regression-low-level__top&quot;&gt;                 &lt;div className=&quot;regression-low-level__workarea&quot;&gt;                     &lt;div className=&quot;regression-low-level__canvas&quot;&gt;                         &lt;Canvas                             width={WIDTH}                             height={HEIGHT}                             points={points}                             curvePoints={curvePoints}                             changePoints={changePoints}                         \/&gt;                     &lt;\/div&gt;                     &lt;div className=&quot;regression-low-level__toolbar&quot;&gt;                         &lt;button                             className=&quot;btn btn-red&quot;                             onClick={() =&gt; model.stop()}&gt;Stop                         &lt;\/button&gt;                         &lt;button                             className=&quot;btn btn-yellow&quot;                             onClick={() =&gt; {                                 model.stop();                                 changePoints(() =&gt; []);                                 changeCurvePoints(() =&gt; []);                             }}&gt;Clear                         &lt;\/button&gt;                     &lt;\/div&gt;                 &lt;\/div&gt;                 &lt;div className=&quot;regression-low-level__loss&quot;&gt;                     &lt;LossPlot                               loss={lossHistory}\/&gt;                 &lt;\/div&gt;              &lt;\/div&gt;         &lt;\/div&gt;     ) }<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:  <\/p>\n<div class=\"oembed\">\n<div>\n<div style=\"left: 0; width: 100%; height: 0; position: relative; padding-bottom: 66.6667%;\"><iframe src=\"https:\/\/embed.plnkr.co\/plunk\/drSP0Nayk7UhsMuD?autoCloseSidebar&amp;deferRun&amp;show=preview\" style=\"border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;\" allowfullscreen scrolling=\"no\"><\/iframe><\/div>\n<\/div>\n<\/div>\n<p>  \u042f \u0431\u044b \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f:<br \/>   \u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<br \/>   \u2014 \u0434\u043b\u044f tf.train.sgd \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 learningRate \u0438 \u043f\u043e\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 learningRate, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u0443, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 2<br \/>   \u2014 \u0437\u0430\u0434\u0430\u0439\u0442\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 tf.train.adam. \u0423\u043b\u0443\u0447\u0448\u0438\u043b\u0441\u044f \u043b\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u0417\u0430\u0432\u0438\u0441\u0438\u0442 \u043b\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 learningRate \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043c\u043e\u0434\u0435\u043b\u0438.<\/div>\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:\/\/habr.com\/ru\/post\/513172\/\"> https:\/\/habr.com\/ru\/post\/513172\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/513172\/\">\u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f Python \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043e\u043c\u0438\u043d\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0434\u043b\u044f \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u044f\u0432\u043b\u044f\u0435\u0442\u0435\u0441\u044c JS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0438 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u044b \u043e\u043a\u0443\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u0442 \u043c\u0438\u0440, \u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0439 \u0430\u0440\u0441\u0435\u043d\u0430\u043b \u043d\u043e\u0432\u044b\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/www.tensorflow.org\/js\" rel=\"nofollow\">TensorFlow.js<\/a>  <\/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-308127","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308127","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=308127"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308127\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}