The following network was trained with available bank balance as input , and pulse rate obtained using a DFit Fitbit as output.
The bank balance x was normalised by dividing by 1000 so that the values fell
between 0 and 1. Similarly pulse rate was divided by 100.
The function y= mx + c = 0 was used to measure the gradient of the data.
Algorithm ref: Tensorflow for dummies by Mathew Scarpino, page 109 listing 6.3:
The code from this program can be saved as filename.py
The network can be run from a terminal by typing:
python3 filename.py
Here is the code:
import tensorflow as tf
# values of x = [0.0805, 0.0805, 0.04103, 0.06484, 0.30885, 0.24347, 0.2113, 0.32899,
# 0.18724, 0.15731, 0.12432, 0.12432, 0.3872, 0.32124, 0.26415, 0.2073, 0.17515, 0.16939]
# values of y = [0.094, 0.076, 0.1, 0.088, 0.083, 0.074, 0.083, 0.087, 0.079,
# 0.081, 0.080, 0.081, 0.072, 0.078, 0.078, 0.077, 0.087, 0.084]
x_train = [0.0805, 0.0805, 0.04103, 0.06484, 0.30885, 0.24347, 0.2113, 0.32899, 0.18724, 0.15731] #0.12432, 0.12432, 0.3872, 0.32124, 0.26415, 0.2073, 0.17515, 0.16939]
y_train = [0.094, 0.076, 0.1, 0.088, 0.083, 0.074, 0.083, 0.087, 0.079, 0.081]
#0.080, 0.081, 0.072, 0.078, 0.078, 0.077, 0.087, 0.084]
m = tf.Variable(0.)
c = tf.Variable(0.)
x = tf.compat.v1.placeholder(dtype=tf.float32)
y = tf.compat.v1.placeholder(dtype=tf.float32)
# using sigmoid function y = mx + c
model = tf.nn.sigmoid(tf.add(tf.multiply(x, m),c))
cost = -1. * tf.reduce_sum(tf.convert_to_tensor(y) * tf.math.log(model) + (1. - tf.convert_to_tensor(y)) * (1. - tf.math.log(model)))
#cost = tf.sigmoid(model)
learn_rate = 0.005
num_epochs = 350
#using Gradient Descent with learning rate 0.005
train = tf.compat.v1.train.GradientDescentOptimizer(learn_rate).minimize(cost)
session = tf.compat.v1.Session()
init = tf.compat.v1.global_variables_initializer()
session.run(init)
#training model for 350 iterations
for epoch in range(num_epochs):
session.run(train, {x:x_train, y:y_train})
#final values of m and c
print('')
print('m =', session.run(m))
print('c =', session.run(c))
Here is the output:
david@debian:~/tensorflow$ python3 balancepulseii.py
2019-12-19 01:30:16.678368: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1497190000 Hz
2019-12-19 01:30:16.678837: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x557cb1618e10 executing computations on platform Host. Devices:
2019-12-19 01:30:16.678887: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): <undefined>, <undefined>
2019-12-19 01:30:16.717659: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set. If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU. To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
m = -2.3215976
c = -13.5563755
david@debian:~/tensorflow$
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
0 = -2.3215976x -13.5563755
13.5563755 = -2.3215976x
x = 13.5563755 / (-2.3215976)
x = −5.839244277
To get the available balance at which my pulse rate starts to change I scale up by 1000 to arrive at the figure £-5839.24428
My available balance ranges from 0 to about £400 maximum. I think the
minus value for x indicates that my pulse rate is dependant on financial support in the form of financial gifts in the way of Turkish duty free tobacco,
catering sized containers of Nescafe Original, DVDs and yes, cash from
my family.
Enjoy!
Cross referencing the above value after scaling up x of £-5839.24428 with the neural network and Tensorflow described in post http://pythonprediction.blogspot.com/2019/07/tensorflow-and-sigmoid-function.html
which give a value of increasing spending at x = -£5166.7 suggests that comfort spending in an attempt to deal with the fear reactions of schizophrenia and Post Traumatic Stress disorder falls within the range of £-5166.7 to £-5839.24428.
No comments:
Post a Comment