Published
Edited
Apr 15, 2018
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
inputData = {
const data = tf.tidy(() => {
const numPoints = 200;
const [a, b, c, d] = coeff.map(i => tf.scalar(i)); // a = tf.scalar(coeff[0]), and so on

const x = tf.randomUniform([numPoints], -1, 1);
const y = a.mul(x.pow(tf.scalar(3)))
.add(b.mul(x.square()))
.add(c.mul(x))
.add(d)
.add(tf.randomNormal([numPoints], 0, sd));

return {x, y};
});
yield data;
// This cell is re-evaluated and creates new tensors as we interact with the sliders to adjust parameters.
// We need to manually dispose them to avoid memory leak.
// See: https://beta.observablehq.com/@nsthorat/clean-up-deeplearn-js-tensor-generator-cells
try {
yield invalidation;
} finally {
data.x.dispose();
data.y.dispose();
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more