summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2016-02-11 10:52:13 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2016-02-11 10:52:13 +0100
commit46a5609a6c92b8620b36419e0cc029450053895c (patch)
tree0b5d284f5742a57e641a72ad26b7ad6515be8df4
parentd79e43b4355a8b646073a53485fe08d0273d9966 (diff)
downloadboston-neuralnet-46a5609a6c92b8620b36419e0cc029450053895c.tar.gz
boston-neuralnet-46a5609a6c92b8620b36419e0cc029450053895c.zip
vor rewrite2: vielleicht besser nicht Tensor fitten
-rw-r--r--boston.py73
1 files changed, 38 insertions, 35 deletions
diff --git a/boston.py b/boston.py
index 5996d59..ecf35c2 100644
--- a/boston.py
+++ b/boston.py
@@ -19,34 +19,39 @@ x_train, x_test, y_train, y_test = train_test_split(
with tf.device('/cpu:0'):
sess = tf.InteractiveSession()
- vecUnfittedInput = tf.placeholder(tf.float32, [13], name="input")
- numTarget = tf.placeholder(tf.float32, [1], name="target")
+ vecInput = tf.placeholder(tf.float32, [13], name="input")
+ # 'unfitted' means not squeezed between 0 and 1, but real values
+ numUnfittedTarget = tf.placeholder(tf.float32, [1], name="target")
# numbers to scale the output between 0-1 and back to prices
numFactor = tf.placeholder(tf.float32, [1], name="factor")
- # ^ max(input_matrix) - min(input_matrix)
numOffset = tf.placeholder(tf.float32, [1], name="offset")
- # ^ min(input_matrix)
- # scale the unscaled input
- vecInput = tf.div(tf.sub(vecUnfittedInput, numOffset), numFactor)
-
- vecBias = tf.Variable(tf.truncated_normal([13], stddev=0.1), name="bias")
- vecWeights = tf.Variable(tf.truncated_normal([1, 13], stddev=0.1), name="weight")
+ vecBias = tf.Variable(tf.random_uniform([13], minval=0, maxval=1), name="bias")
+ vecBias = tf.Print(vecBias, [vecBias], "vecbias")
+ # vecWeights is not a true vector, it is turned by 90 degrees
+ vecWeights = tf.Variable(tf.random_uniform([1, 13], minval=0, maxval=1), name="weight")
+ vecWeights = tf.Print(vecWeights, [vecWeights], "vecweights")
+ # sum((i + b) * w)
matWeighted = tf.mul(tf.add(vecInput, vecBias), vecWeights)
- vecNetinput = tf.reduce_sum(matWeighted)
+ matWeighted = tf.Print(matWeighted, [matWeighted], "matweighted: ") # DEBUG
+ vecNetinput = tf.reduce_sum(matWeighted, 1)
vecNetinput = tf.Print(vecNetinput, [vecNetinput], "netinput: ") # DEBUG
+ vecLayerOutput = tf.sigmoid(vecNetinput)
+ vecLayerOutput = tf.Print(vecLayerOutput, [vecLayerOutput], "vecLayerOutput: ") # DEBUG
- vecUnfittedOutput = tf.sigmoid(vecNetinput)
-
- # unscale the output
- vecOutput = tf.add(tf.mul(vecUnfittedOutput, numFactor), numOffset)
# since this is the last layer, vecOutput is a numOutput
- numOutput = vecOutput
+ numOutput = tf.reduce_sum(vecLayerOutput)
+ # unscale the output
+ numUnfittedOutput = tf.add(tf.mul(numOutput, numFactor), numOffset)
+ numUnfittedOutput = tf.Print(numUnfittedOutput, [numUnfittedOutput], "unfitted output: ") # DEBUG
- numDifference = tf.sub(numOutput, numTarget)
- numMSE = tf.reduce_mean(tf.square(numDifference))
+ numUnfittedTarget = tf.Print(numUnfittedTarget, [numUnfittedTarget], "numUnfittedTarget: ") # DEBUG
+ numDifference = tf.sub(numUnfittedOutput, numUnfittedTarget)
+ numDifference = tf.Print(numDifference, [numDifference], "numDifference: ")
+ numMSE = tf.reduce_sum(tf.square(numDifference))
+ numMSE = tf.Print(numMSE, [numMSE], "MSE: ")
summaryMSE = tf.scalar_summary("MSE", numMSE)
summaryDifference = tf.scalar_summary("Mean difference", numDifference)
@@ -55,35 +60,33 @@ with tf.device('/cpu:0'):
# all variables have to be specified here
sess.run(tf.initialize_all_variables())
-
- # mse = tf.Print(mse, [mse], "mse: ")
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(numMSE)
-factor = 0 #max(target) - min(target)
-offset = 0 #min(target)
+factor = max(target) - min(target)
+offset = min(target)
for count in range(0, len(x_train)):
trainsteps = 100
+ print("count " + str(count))
for i in range(0, trainsteps): # 100 epochs
- #if i % 10 == 9:
- #feed = {
- #"input": x_test[testcount], # x_test,
- #"target": y_test[testcount], # [y_test],
- #"factor": factor,
- #"offset": offset
- #}
- #result = sess.run([summaries, numMSE], feed_dict=feed)
+ if i % 10 == 9:
+ feed = {
+ vecInput: x_test[0],
+ numUnfittedTarget: [y_test[0]],
+ numFactor: [factor],
+ numOffset: [offset]
+ }
+ result = sess.run([summaries, numMSE], feed_dict=feed)
+ #print("test " + result[0])
#writer.add_summary(result[0], count * trainsteps + i)
- y_t = 1 #float(y_train[count].tolist())
- print(y_t)
sess.run(train_step,
feed_dict={
- "input": 1, #x_train[count].tolist(),
- "target": 1, #y_t,
- "factor": 1, #[[factor]],
- "offset": 1, #[[offset]]
+ vecInput: x_train[count],
+ numUnfittedTarget: [y_train[count]],
+ numFactor: [factor],
+ numOffset: [offset]
})
print("finished training")