Created
August 17, 2017 19:37
-
-
Save gavin/d4162e68a9d1973bd1b056f43b2584fb to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env hy | |
(import [tensorflow :as tf]) | |
(def W (tf.Variable [.3] tf.float32)) | |
(def b (tf.Variable [-0.3] tf.float32)) | |
(def x (tf.placeholder tf.float32)) | |
(def linear-model (* W (+ x b))) | |
(def y (tf.placeholder tf.float32)) | |
(def loss (tf.reduce_sum (tf.square (- linear-model y)))) | |
(def loss (tf.reduce_sum (tf.square (- linear-model y)))) | |
(def optimizer (tf.train.GradientDescentOptimizer 0.01)) | |
(def train (optimizer.minimize loss)) | |
(def x-train [1 2 3 4]) | |
(def y-train [0 -1 -2 -3]) | |
(def init (tf.global_variables_initializer)) | |
(def sess (tf.Session)) | |
(sess.run init) | |
(for [i (range 1000)] (sess.run train {x x-train y y-train})) | |
(sess.run [W b loss] {x x-train y y-train}) | |
(def results (sess.run [W b loss] {x x-train y y-train})) | |
(print (.format "W: {0} b: {1} loss: {2}" (first results) (second results) (last results))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment