cubicPredictions = {
if (!inputData_a) return html``;
const predictions = tf.tidy(() => {
const a = tf.variable(tf.zeros([1]));
const b = tf.variable(tf.zeros([1]));
const c = tf.variable(tf.zeros([1]));
const d = tf.variable(tf.zeros([1]));
const f = (x) =>
a.mul(x.pow(tf.scalar(3)))
.add(b.mul(x.square()))
.add(c.mul(x))
.add(d);
const optimizer = tf.train.sgd(0.8);
for (let i = 0; i < numIterations; i++) {
optimizer.minimize(() => loss(f(inputData_a.x), inputData_a.y));
}
const predTensor = f(inputData_a.x);
[a, b, c, d].forEach(x => {
x.dispose();
});
return predTensor;
});
yield predictions;
try {
yield invalidation;
} finally {
predictions.dispose();
}
}