|
| 1 | +jsoniq version "1.0"; |
| 2 | + |
| 3 | +(: |
| 4 | + : بسم الله الرحمن الرحيم |
| 5 | + : |
| 6 | + : In the name of Allah, the Most Compassionate, the Most Merciful |
| 7 | + : |
| 8 | + : This file is part of Unity DGMS <https://www.dgms.io/> |
| 9 | + : |
| 10 | + : Unity DGMS is free software; redistribution and use in source and binary |
| 11 | + : forms, with or without modification, are permitted provided that the |
| 12 | + : following conditions are met: |
| 13 | + : |
| 14 | + : 1. Redistributions of source code must retain the above notice, this list of |
| 15 | + : conditions and the following disclaimer. |
| 16 | + : |
| 17 | + : 2. Redistributions in binary form must reproduce the above notice, this list |
| 18 | + : of conditions and the following disclaimer in the documentation and/or |
| 19 | + : other materials provided with the distribution. |
| 20 | + : |
| 21 | + : THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
| 22 | + : WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | + : MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY |
| 24 | + : SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 25 | + : WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 26 | + : OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 27 | + : CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 28 | + :) |
| 29 | + |
| 30 | +import module namespace ml = "http://dgms.io/modules/learning"; |
| 31 | +import module namespace n = "http://dgms.io/modules/numerics"; |
| 32 | +import module namespace r = "http://dgms.io/modules/random"; |
| 33 | +import module namespace s = "http://dgms.io/modules/symbolics"; |
| 34 | + |
| 35 | +s:set-mode("tensorflow"); |
| 36 | + |
| 37 | +variable $x := n:linspace(0, 100, 100) + r:uniform(-5, 5, 100); |
| 38 | +variable $y := n:linspace(0, 100, 100) + r:uniform(-5, 5, 100); |
| 39 | + |
| 40 | +variable $X := s:placeholder(); |
| 41 | +variable $Y := s:placeholder(); |
| 42 | + |
| 43 | +variable $W := s:variable(r:randn(), { name: "W" }); |
| 44 | +variable $b := s:variable(r:randn(), { name: "b" }); |
| 45 | + |
| 46 | +variable $y_pred := $X * $W + $b; |
| 47 | + |
| 48 | +variable $loss := n:reduce-sum(n:pow($y_pred - $Y, 2)) div (2 * count($x)); |
0 commit comments