Created
April 18, 2018 01:31
-
-
Save llSourcell/09b8cb0c5e878a7bdf5cdd3629bdd1cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define function | |
| function predict(input) { | |
| // y = a * x ^ 2 + b * x + c | |
| // More on tf.tidy in the next section | |
| return tf.tidy(() => { | |
| const x = tf.scalar(input); | |
| const ax2 = a.mul(x.square()); | |
| const bx = b.mul(x); | |
| const y = ax2.add(bx).add(c); | |
| return y; | |
| }); | |
| } | |
| // Define constants: y = 2x^2 + 4x + 8 | |
| const a = tf.scalar(2); | |
| const b = tf.scalar(4); | |
| const c = tf.scalar(8); | |
| // Predict output for input of 2 | |
| const result = predict(2); | |
| result.print() // Output: 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment