Skip to content

Instantly share code, notes, and snippets.

@llSourcell
Created April 18, 2018 01:31
Show Gist options
  • Select an option

  • Save llSourcell/09b8cb0c5e878a7bdf5cdd3629bdd1cd to your computer and use it in GitHub Desktop.

Select an option

Save llSourcell/09b8cb0c5e878a7bdf5cdd3629bdd1cd to your computer and use it in GitHub Desktop.
// 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