Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. const model = tf.sequential();
  2. model.add(tf.layers.dense({ units: 5, activation: 'sigmoid', inputShape: [1]}));
  3. model.add(tf.layers.dense({ units: 1, activation: 'sigmoid'}));
  4. model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
  5. const xs = tf.tensor2d([[1], [2], [3], [4], [6], [7], [8], [9]]);
  6. const ys = tf.tensor2d([[0], [0], [0], [0], [1], [1], [1], [1]]);
  7. model.fit(xs, ys);
  8. model.predict(xs).print();
  9.  
  10. const model = tf.sequential();
  11. model.add(tf.layers.dense({ units: 1, activation: 'sigmoid', inputShape: [1]}));
  12. model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
  13. const xs = tf.tensor2d([[1], [2], [3], [4], [6], [7], [8], [9]]);
  14. const ys = tf.tensor2d([[0], [0], [0], [0], [1], [1], [1], [1]]);
  15. model.fit(xs, ys);
  16. model.predict(xs).print();
  17.  
  18. const AdadeltaOptimizer = tf.train.adadelta();
  19.  
  20. const model = tf.sequential();
  21. model.add(tf.layers.dense({ units: 5, activation: 'sigmoid', inputShape: [1]}));
  22. model.add(tf.layers.dense({ units: 1, activation: 'sigmoid'}));
  23. model.compile({loss: 'meanSquaredError', optimizer: AdadeltaOptimizer});
  24. const xs = tf.tensor1d([1, 2, 3, 4, 5, 6, 7, 8, 9]);
  25. const ys = tf.tensor1d([0, 0, 0, 0, 0, 1, 1, 1, 1]);
  26. model.fit(xs, ys, {
  27. epochs: 2000,
  28. });
  29. model.predict(xs).print();
  30.  
  31. tf.losses.meanSquaredError(ys, model.predict(xs)).print();
  32.  
  33. sgd = keras.optimizers.SGD(lr=1)
  34. model.compile(sgd, 'mse')
  35.  
  36. model.fit(xs, ys, epochs=200)
  37.  
  38. model.compile('adadelta', 'mse')
  39. model.fit(xs, ys, epochs=2000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement