The following network was trained with available bank balance as input , and time spent at a cafe as output.
The bank balance x was normalised by dividing by 1000 so that the values fell
between 0 and 1. Similarly, y the time spent at a location was divided by 1000.
The function y= mx + c = 0 was used to measure the gradient of the data.
REF: Algorithm for calculating mean squared error (MSE) from
Pro Deep Learning with Tensorflow by Santanu Pattanayak, page 144:
This model computes loss using MSE.
The code from this program can be saved as filename.py
The network can be run from a terminal by typing:
python filename.py
(virtualenvironment.) david@debian:~/pythonvirenv$ python tftimeii.py
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:455: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:456: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:457: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:458: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:459: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:462: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
2020-11-16 19:17:06.884453: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2020-11-16 19:17:06.884550: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2020-11-16 19:17:06.884579: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
Iter: 0 MSE in training: [0.002089466]
Iter: 1 MSE in training: [0.0020533486]
Iter: 2 MSE in training: [0.0020179658]
Iter: 3 MSE in training: [0.001983303]
Iter: 4 MSE in training: [0.0019493455]
Iter: 5 MSE in training: [0.0019160783]
Iter: 6 MSE in training: [0.001883488]
Iter: 7 MSE in training: [0.0018515604]
Iter: 8 MSE in training: [0.0018202825]
Iter: 9 MSE in training: [0.0017896408]
Iter: 10 MSE in training: [0.0017596222]
.
The network can be run from a terminal by typing:
python filename.py
Here is the code:
import tensorflow as tf
# values of x = [0.14569, 0.17944, 0.15496, 0.07607, 0.01223, 0.00873, 0.26456, 0.19928, 0.01417, 0.00220, 0.16451, 0.09408, 0.23073, 0.13403, 0.11177, 0.29657, 0.21266, 0.11302, 0.29185, 0.24873, 0.15997, 0.09582, 0.30616, 0.11861, 0.18292, 0.12121, 0.08206]
# values of y = [0.381, 0.96, 0.385, 0.369, 0.3225, 0.28, 0.2776, 0.2641, 0.3415,0.6881, 0.4925, 0.5263, 0.2965, 0.8622, 0.4678, 0.3493, 0.3008, 0.2553, 0.178, 0.3826, 0.3378, 0.4217, 0.42, 0.4197, 0.3938, 0.5988, 0.5358]
x_train = [0.14569, 0.17944, 0.15496, 0.07607, 0.01223, 0.00873, 0.26456, 0.19928, 0.01417, 0.00220, 0.16451, 0.09408, 0.23073, 0.13403, 0.11177, 0.29657, 0.21266, 0.11302, 0.29185, 0.24873, 0.15997, 0.09582, 0.30616, 0.11861, 0.18292, 0.12121, 0.08206]
y_train = [0.381, 0.96, 0.385, 0.369, 0.3225, 0.28, 0.2776, 0.2641, 0.3415, 0.6881, 0.4925, 0.5263, 0.2965, 0.8622, 0.4678, 0.3493, 0.3008, 0.2553, 0.178,
0.3826, 0.3378, 0.4217, 0.42, 0.4197, 0.3938, 0.5988, 0.5358]
m = tf.Variable(0.)
c = tf.Variable(0.)
x = tf.placeholder(dtype = tf.float32)
y = tf.placeholder(dtype=tf.float32)
# using sigmoid function y = mx + c
model = tf.nn.sigmoid(tf.add(tf.multiply(x, m),c))
pred = tf.add(tf.multiply(x, m),c)
error = pred - y
loss = tf.reduce_mean(tf.square(error))
learn_rate = 0.005
num_epochs = 350
#using Gradient Descent with learning rate 0.005
train = tf.train.GradientDescentOptimizer(learn_rate).minimize(loss)
session = tf.Session()
init = tf.global_variables_initializer()
loss_trace = []
session.run(init)
#training model for 350 iterations
for epoch in range(num_epochs):
session.run([train], {x:x_train, y:y_train})
# lossval = session.run([loss], {x:x_train, y:y_train})
loss_trace.append(session.run([loss], {x:x_train, y:y_train}))
pred = tf.add(tf.multiply(x, m),c)
error = pred - y
error = session.run([error], {x:x_train, y:y_train})
prediction = session.run([pred],{x:x_train, y:y_train})
print('Iter: ', epoch, 'MSE in training: ', loss_trace[-1])
#final values of m and c
print('')
print('m =', session.run(m))
print('c =', session.run(c))
print('Final loss: ', loss_trace[-1])
print('Prediction :' , prediction)
print('Error: ', error)
import matplotlib.pyplot as plt
plt.xlabel('Number of epochs --------->')
plt.ylabel('Error (MSE) --------->')
plt.plot(loss_trace)
plt.show()
# values of x = [0.14569, 0.17944, 0.15496, 0.07607, 0.01223, 0.00873, 0.26456, 0.19928, 0.01417, 0.00220, 0.16451, 0.09408, 0.23073, 0.13403, 0.11177, 0.29657, 0.21266, 0.11302, 0.29185, 0.24873, 0.15997, 0.09582, 0.30616, 0.11861, 0.18292, 0.12121, 0.08206]
# values of y = [0.381, 0.96, 0.385, 0.369, 0.3225, 0.28, 0.2776, 0.2641, 0.3415,0.6881, 0.4925, 0.5263, 0.2965, 0.8622, 0.4678, 0.3493, 0.3008, 0.2553, 0.178, 0.3826, 0.3378, 0.4217, 0.42, 0.4197, 0.3938, 0.5988, 0.5358]
x_train = [0.14569, 0.17944, 0.15496, 0.07607, 0.01223, 0.00873, 0.26456, 0.19928, 0.01417, 0.00220, 0.16451, 0.09408, 0.23073, 0.13403, 0.11177, 0.29657, 0.21266, 0.11302, 0.29185, 0.24873, 0.15997, 0.09582, 0.30616, 0.11861, 0.18292, 0.12121, 0.08206]
y_train = [0.381, 0.96, 0.385, 0.369, 0.3225, 0.28, 0.2776, 0.2641, 0.3415, 0.6881, 0.4925, 0.5263, 0.2965, 0.8622, 0.4678, 0.3493, 0.3008, 0.2553, 0.178,
0.3826, 0.3378, 0.4217, 0.42, 0.4197, 0.3938, 0.5988, 0.5358]
m = tf.Variable(0.)
c = tf.Variable(0.)
x = tf.placeholder(dtype = tf.float32)
y = tf.placeholder(dtype=tf.float32)
# using sigmoid function y = mx + c
model = tf.nn.sigmoid(tf.add(tf.multiply(x, m),c))
pred = tf.add(tf.multiply(x, m),c)
error = pred - y
loss = tf.reduce_mean(tf.square(error))
learn_rate = 0.005
num_epochs = 350
#using Gradient Descent with learning rate 0.005
train = tf.train.GradientDescentOptimizer(learn_rate).minimize(loss)
session = tf.Session()
init = tf.global_variables_initializer()
loss_trace = []
session.run(init)
#training model for 350 iterations
for epoch in range(num_epochs):
session.run([train], {x:x_train, y:y_train})
# lossval = session.run([loss], {x:x_train, y:y_train})
loss_trace.append(session.run([loss], {x:x_train, y:y_train}))
pred = tf.add(tf.multiply(x, m),c)
error = pred - y
error = session.run([error], {x:x_train, y:y_train})
prediction = session.run([pred],{x:x_train, y:y_train})
print('Iter: ', epoch, 'MSE in training: ', loss_trace[-1])
#final values of m and c
print('')
print('m =', session.run(m))
print('c =', session.run(c))
print('Final loss: ', loss_trace[-1])
print('Prediction :' , prediction)
print('Error: ', error)
import matplotlib.pyplot as plt
plt.xlabel('Number of epochs --------->')
plt.ylabel('Error (MSE) --------->')
plt.plot(loss_trace)
plt.show()
Here is the output:
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:455: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:456: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:457: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:458: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:459: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/david/pythonvirenv/virtualenvironment./lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:462: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
2020-11-16 19:17:06.884453: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2020-11-16 19:17:06.884550: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2020-11-16 19:17:06.884579: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
Iter: 0 MSE in training: [0.002089466]
Iter: 1 MSE in training: [0.0020533486]
Iter: 2 MSE in training: [0.0020179658]
Iter: 3 MSE in training: [0.001983303]
Iter: 4 MSE in training: [0.0019493455]
Iter: 5 MSE in training: [0.0019160783]
Iter: 6 MSE in training: [0.001883488]
Iter: 7 MSE in training: [0.0018515604]
Iter: 8 MSE in training: [0.0018202825]
Iter: 9 MSE in training: [0.0017896408]
Iter: 10 MSE in training: [0.0017596222]
.
.
.
.
Iter: 340 MSE in training: [0.00031488354]
Iter: 341 MSE in training: [0.0003148476]
Iter: 342 MSE in training: [0.00031481232]
Iter: 343 MSE in training: [0.00031477772]
Iter: 344 MSE in training: [0.0003147438]
Iter: 345 MSE in training: [0.0003147105]
Iter: 346 MSE in training: [0.00031467783]
Iter: 347 MSE in training: [0.0003146458]
Iter: 348 MSE in training: [0.0003146143]
Iter: 349 MSE in training: [0.00031458342]
m = 0.0048132725
c = 0.040683668
Final loss: [0.00031458342]
Prediction : [array([0.04138491, 0.04154736, 0.04142953, 0.04104981, 0.04074254,
0.04072569, 0.04195707, 0.04164286, 0.04075187, 0.04069426,
0.0414755 , 0.0411365 , 0.04179423, 0.04132879, 0.04122165,
0.04211114, 0.04170726, 0.04122766, 0.04208842, 0.04188087,
0.04145365, 0.04114488, 0.0421573 , 0.04125457, 0.04156411,
0.04126709, 0.04107865], dtype=float32)]
Error: [array([ 0.00328491, -0.05445264, 0.00292953, 0.00414981, 0.00849254,
0.01272569, 0.01419707, 0.01523286, 0.00660187, -0.02811574,
-0.0077745 , -0.0114935 , 0.01214423, -0.04489121, -0.00555835,
0.00718114, 0.01162726, 0.01569767, 0.02428842, 0.00362087,
0.00767365, -0.00102512, 0.0001573 , -0.00071543, 0.00218411,
-0.01861291, -0.01250136], dtype=float32)]
(virtualenvironment.) david@debian:~/pythonvirenv$
Iter: 341 MSE in training: [0.0003148476]
Iter: 342 MSE in training: [0.00031481232]
Iter: 343 MSE in training: [0.00031477772]
Iter: 344 MSE in training: [0.0003147438]
Iter: 345 MSE in training: [0.0003147105]
Iter: 346 MSE in training: [0.00031467783]
Iter: 347 MSE in training: [0.0003146458]
Iter: 348 MSE in training: [0.0003146143]
Iter: 349 MSE in training: [0.00031458342]
m = 0.0048132725
c = 0.040683668
Final loss: [0.00031458342]
Prediction : [array([0.04138491, 0.04154736, 0.04142953, 0.04104981, 0.04074254,
0.04072569, 0.04195707, 0.04164286, 0.04075187, 0.04069426,
0.0414755 , 0.0411365 , 0.04179423, 0.04132879, 0.04122165,
0.04211114, 0.04170726, 0.04122766, 0.04208842, 0.04188087,
0.04145365, 0.04114488, 0.0421573 , 0.04125457, 0.04156411,
0.04126709, 0.04107865], dtype=float32)]
Error: [array([ 0.00328491, -0.05445264, 0.00292953, 0.00414981, 0.00849254,
0.01272569, 0.01419707, 0.01523286, 0.00660187, -0.02811574,
-0.0077745 , -0.0114935 , 0.01214423, -0.04489121, -0.00555835,
0.00718114, 0.01162726, 0.01569767, 0.02428842, 0.00362087,
0.00767365, -0.00102512, 0.0001573 , -0.00071543, 0.00218411,
-0.01861291, -0.01250136], dtype=float32)]
(virtualenvironment.) david@debian:~/pythonvirenv$
Results
-------------
For y= m*x + c
as we have a value for m and a value for c, we can calculate the value of X when 0 = mx + c for the gradient at which the neural network starts to learn.
These are the steps:
y = m*x + c
0 = m*x + c
as we have a value for m and a value for c, we can calculate the value of X when 0 = mx + c for the gradient at which the neural network starts to learn.
These are the steps:
y = m*x + c
0 = m*x + c
0 = 0.0048132725x + 0.040683668
-0.040683668 = 0.0048132725x
x = -0.040683668 / 0.0048132725
x = −8452.392421165
To scale up after normalising at the start we multiply by 1000.
The available bank balance at which a time spent at a location starts to change is
£ −8452.392421165
Conclusion
-------------------
The pattern that I infer from the results is that I am fixated in my time from
a) In 1983 I received a sum of £8,700 received for a comminuted fracture of the left patella together with severed anterior and posterior cruciate ligaments and a tendon.
b) At the time of receiving this compensation I had a £700 pound overdraft from living expenses during my final year at Bristol university.
c) After receiving this compensation I bought a Honda CB400/4 F2 for £550
d) I earned two weekly salaries of £250 each while dispatch riding.
e) After being knocked off of this motorbike I received another £1100 pounds in compensation.
f) I bough a replacement motorbike of a Honda CB750 F2 for £350.
g) I had a blow out of the front tyre, and later the gearbox needed a new layshaft and I also put new tyres on it.
h) When coming down from an LSD trip I allowed someone into talking me into swapping my bike for a 550cc motorbike that was not as tidy and later got arrested for drinking and driving.
i) I was later stabbed and unable to hold down a job for any great length of time due to Post-traumatic stress disorder (PTSD).
j) My monetary situation has not changed since the balance of £8700. The deficit of £248 for that year was for beer, amphetamines, mushrooms, one line of cocaine, weed, cannabis, takeaways, petrol and a bottle of Smirnoff Blue Label vodka.


No comments:
Post a Comment