-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfpotential.py
114 lines (83 loc) · 3.25 KB
/
tfpotential.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import sys
import printer
import plotter
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import datetime as time
import argumentparser as ap
import filefinder as ff
import neuralnetwork as nn
import networktrainer as nt
import datagenerator as gen
import checkpointsaver as ckps
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
#tf.set_random_seed(2)
class TFPotential :
def __init__(self) :
self.argumentParser = ap.ArgumentParser(self)
self.fileFinder = ff.FileFinder(self)
self.inputs = 1
self.nLayers = self.argumentParser.nLayers()
self.nNodes = self.argumentParser.nNodes()
self.outputs = 1
self.networkType = self.argumentParser.type()
self.network = nn.NeuralNetwork(self)
self.network.constructNetwork(inputs = self.inputs,
nNodes = self.nNodes,
nLayers = self.nLayers,
outputs = self.outputs,
networkType = self.networkType)
self.saver = ckps.CheckpointSaver(self,
self.argumentParser().save)
self.networkTrainer = nt.NetworkTrainer(self, self.saver)
self.function = lambda r: r/r*np.random.normal(0,1)# +np.sin(7.0*np.pi*r)
self.function = lambda r: 1/r**12 - 1/r**6
self.function = lambda r: 4*(1.0/(r**12) - 1.0/(r**6)) - 4*(1.0/(2.5**12) - 1.0/(2.5**6))
self.dataGenerator = gen.DataGenerator(0.87, 2.5, self)
self.dataGenerator.setFunction(self.function)
if not self.argumentParser().file == None :
self.dataGenerator.setGeneratorType("file");
else :
self.dataGenerator.setGeneratorType("function")
#self.dataGenerator.setGeneratorType("VMC")
#self.dataGenerator.setGeneratorType("noise")
self.dataSize = int(9987)
self.numberOfEpochs = int(100)
self.batchSize = int(500)
self.testSize = self.dataSize #int(600)
self.testInterval = 5000
self.printer = printer.Printer(self)
self.printer.printSetup()
self.plotter = plotter.Plotter(self)
def variableSummaries(self, name, variable) :
with tf.name_scope('Summaries'):
mean = tf.reduce_mean(variable)
tf.summary.scalar('Mean/' + name, mean)
with tf.name_scope('StandardDeviation'):
stddev = tf.sqrt(tf.reduce_mean(tf.square(variable - mean)))
tf.summary.scalar('StandardDeviation/' + name, stddev)
tf.summary.scalar('Max/' + name, tf.reduce_max(variable))
tf.summary.scalar('Min/' + name, tf.reduce_min(variable))
tf.summary.histogram(name, variable)
def __call__(self, inputData, expectedOutput=None) :
if expectedOutput == None :
expectedOutput = inputData
return self.sess.run(self.networkTrainer.prediction,
feed_dict={self.networkTrainer.x : inputData,
self.networkTrainer.y : expectedOutput})
def train(self, epochs=-1) :
numberOfEpochs = self.numberOfEpochs if epochs == -1 else epochs
self.numberOfEpochs = numberOfEpochs
self.networkTrainer.trainNetwork(numberOfEpochs)
self.sess = self.networkTrainer.sess
def setNetworkType(self, typeString) :
self.network.parseTypeString(typeString)
if __name__ == "__main__" :
tfpot = TFPotential()
#tfpot.inputs = 2
#tfpot.dataGenerator.a = 0.45
#tfpot.dataGenerator.b = 1.8
#tfpot.dataGenerator.generatorType = "SW"
tfpot.train(tfpot.argumentParser().epochs)