summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/codebox/hellopy.py
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-12-27 03:02:58 +0000
committerNorbert Preining <norbert@preining.info>2021-12-27 03:02:58 +0000
commit790995b7e79697514364450bf9c04f1b8d500838 (patch)
treea59b89b3cfb2e5def88455fa463f95e9a2aaea5f /macros/latex/contrib/codebox/hellopy.py
parent4a2abb95db9b87c04422a05174b2606b2c8e1d2b (diff)
CTAN sync 202112270302
Diffstat (limited to 'macros/latex/contrib/codebox/hellopy.py')
-rwxr-xr-xmacros/latex/contrib/codebox/hellopy.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/macros/latex/contrib/codebox/hellopy.py b/macros/latex/contrib/codebox/hellopy.py
new file mode 100755
index 0000000000..af687ef384
--- /dev/null
+++ b/macros/latex/contrib/codebox/hellopy.py
@@ -0,0 +1,32 @@
+import tensorflow as tf
+import numpy as np
+import os
+os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
+
+# Create 100 phony x, y data points in Numpy, y = x * 0.1 + 0.3
+x_data = np.random.random(100).astype("float32")
+y_data = x_data * 0.1 + 0.3
+
+# Try to find values for W and b that compute y_data = W * x_data + b
+W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
+b = tf.Variable(tf.zeros([1]))
+y = W * x_data + b
+
+# Minimize the mean squared errors.
+loss = tf.reduce_mean(tf.square(y -y_data))
+optimizer = tf.train.GradientDescentOptimizer(0.5)
+train = optimizer.minimize(loss)
+
+# Before starting, initialize the variables. We will 'run' this first
+init = tf.global_variables_initializer()
+
+# Launch the graph.
+sess = tf.Session()
+sess.run(init)
+
+# Fit the line.
+for step in range(201):
+ sess.run(train)
+ if step % 20 == 0:
+ print(step, sess.run(W), sess.run(b))
+