Last active
January 14, 2020 18:19
-
-
Save hchasestevens/4fdc6dbef04f7fa42b116a627d20b7d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| # 1000 * 1.07 ** X = 2000 | |
| # p * r ** X = y | |
| p = tf.constant(1000.) | |
| r = tf.constant(1.07) | |
| X = tf.Variable(1., constraint=tf.keras.constraints.non_neg()) | |
| y = tf.constnat(2000.) | |
| lhs = p * tf.pow(r, X) | |
| err = tf.abs(lhs - y) | |
| train_step = tf.train.AdamOptimizer(0.01).minimize(err) | |
| init = tf.global_variables_initializer() | |
| with tf.Session() as sess: | |
| sess.run(init) | |
| print() | |
| for i in range(1000): | |
| sess.run(train_step) | |
| if not (i % 100): | |
| _X = sess.run(X) | |
| print(f"{i}:\tX: {_X},\terr: {sess.run(err)},\ty: {sess.run(p * r ** _X)}") | |
| print(f"X: {sess.run(X)}, y: {sess.run(p * r ** _X)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment