result = {
yield html`<p>Predicting...</p>`
const m = tf.sequential()
m.add(tf.layers.dense({ units: 1, inputShape: [1] }))
m.compile({ loss: 'meanSquaredError', optimizer: 'sgd' })
yield m.fit(
tf.tensor2d(testXs, [testXs.length, 1]),
tf.tensor2d(testYs, [testYs.length, 1]),
{ epochs: 500 }
)
.then(() => {
const toCheck = R.uniq(Array.from(Array(8)).map(() => Math.round(Math.random() * 10)))
return html`<table
<tr>
<th>Input</th><th>Output</th><th>Expected</th><th>Difference</th>
</tr>
${toCheck.map(x => {
const result = m.predict(tf.tensor2d([x], [1,1])).dataSync()
return html`<tr>
<td>${x}</td>
<td>${result}</td>
<td>${testFunction(x)}</td>
<td>${Math.abs(testFunction(x) - result)}</td>
</tr>`
})}
</table>`
})
}