import * as tf from
"@tensorflow/tfjs"
const Model = tf.sequential( ) ;
const config = {units: 4, inputShape: [2],
activation :
"sigmoid"
}
const x = tf.layers.dense(config);
Model.add(x);
const config2 = {units: 3,
activation :
"sigmoid"
}
const y = tf.layers.dense(config2);
Model.add(y);
const sgdOpt = tf.train.sgd(0.6)
const config3 = {optimizer:
'sgd'
, loss:
'meanSquaredError'
}
Model.compile(config3);
const xs = tf.tensor2d([ [0.3, 0.24],
[0.12, 0.73],
[0.9, 0.54]
]);
const ys = tf.tensor2d([ [0.43, 0.5, 0.92],
[0.1, 0.39, 0.12],
[0.76, 0.4, 0.92]
]);
for
( let i = 0; i < 5; i++){
const config = { shuffle :
true
, epoch : 10 }
const Tm = await Model.fit(xs, ys, config);
console.log(
"Loss "
+
" : "
+ Tm.history.loss[0]);
}