(xyData, epochs, learningRate)
| 163 | // yMean: Arithmetic mean of y. |
| 164 | // yStddev: Standard deviation of y. |
| 165 | async function fitModel(xyData, epochs, learningRate) { |
| 166 | const batchSize = xyData.length; |
| 167 | const outputs = toNormalizedTensors(xyData, order); |
| 168 | const xPowerMeans = outputs[0]; |
| 169 | const xPowerStddevs = outputs[1]; |
| 170 | const xData = outputs[2]; |
| 171 | const yMean = outputs[3]; |
| 172 | const yStddev = outputs[4]; |
| 173 | const yData = outputs[5]; |
| 174 | const input = tf.input({shape: [order + 1]}); |
| 175 | const linearLayer = |
| 176 | tf.layers.dense({units: 1, kernelInitializer: 'Zeros', useBias: false}); |
| 177 | const output = linearLayer.apply(input); |
| 178 | const model = tf.model({inputs: input, outputs: output}); |
| 179 | const sgd = tf.train.sgd(learningRate); |
| 180 | model.compile({optimizer: sgd, loss: 'meanSquaredError'}); |
| 181 | await model.fit(xData, yData, { |
| 182 | batchSize: batchSize, |
| 183 | epochs: epochs, |
| 184 | }); |
| 185 | console.log( |
| 186 | 'Model weights (normalized):', |
| 187 | model.trainableWeights[0].read().dataSync()); |
| 188 | return [model, xPowerMeans, xPowerStddevs, yMean, yStddev]; |
| 189 | } |
| 190 | |
| 191 | // Render the predictions made by the model. |
| 192 | function renderModelPredictions( |
no test coverage detected