Commit 973d98aa authored by Margret A. Riegert's avatar Margret A. Riegert
Browse files

Remove unnecessary passes


Former-commit-id: 9167cadc5b6914f059d28f2b5213bd8b9a2f0075 [formerly 4442f8d631a0037422d7b3b778dc2ed6420897c3]
Former-commit-id: 3128a7e62921a039b2f60a4421cb74071329112f
parent f3f00efe
......@@ -17,7 +17,7 @@ class bcolors:
def printUsage():
print("Usage: python qos.py <original file> <nn file>")
exit(1)
pass;
if(len(sys.argv) != 3):
......@@ -54,6 +54,6 @@ for i in range(len(origLines)):
e = nominator / denominator
absError += e
pass;
print(bcolors.FAIL + "*** Error: %1.8f" % (absError/float(len(origLines))) + bcolors.ENDC)
......@@ -17,7 +17,7 @@ class bcolors:
def printUsage():
print("Usage: python qos.py <original file> <nn file>")
exit(1)
pass;
if(len(sys.argv) != 3):
......@@ -61,6 +61,6 @@ for i in range(len(origLines)):
e = nominator / denominator
absError += e
pass;
print(bcolors.FAIL + "*** Error: %1.8f" % (absError/float(len(origLines))) + bcolors.ENDC)
......@@ -17,7 +17,7 @@ class bcolors:
def printUsage():
print("Usage: python qos.py <original file> <nn file>")
exit(1)
pass;
if(len(sys.argv) != 3):
......@@ -61,6 +61,6 @@ for i in range(len(origLines)):
e = nominator / denominator
absError += e
pass;
print(bcolors.FAIL + "*** Error: %1.8f" % (absError/len(origLines)) + bcolors.ENDC)
......@@ -17,7 +17,7 @@ class bcolors:
def printUsage():
print("Usage: python qos.py <original file> <nn file>")
exit(1)
pass;
if(len(sys.argv) != 3):
......@@ -43,6 +43,6 @@ for i in range(len(origLines)):
if(origItem != nnItem):
missPred += 1
pass;
print(bcolors.FAIL + "*** Error: %1.8f" % (missPred/float(len(origLines))) + bcolors.ENDC)
......@@ -9,16 +9,16 @@ import json
class JsonCloak(object):
def __init__(self):
self.data = {}
pass
def put(self, field, value):
self.data[field] = value
pass
def get(self, field):
try: return self.data[field]
except: return None
pass
def load(self, filePath):
try: inFile = open(filePath)
......@@ -26,11 +26,11 @@ class JsonCloak(object):
inFile = None
print(('Error! Oops! Cannot open ' + str(filePath) + '!'))
return
pass
self.data = json.loads(inFile.read())
inFile.close()
pass
def save(self, filePath):
try: outFile = open(filePath, 'w')
......@@ -38,18 +38,18 @@ class JsonCloak(object):
outFile = None
print(('Error! Oops! Cannot open ' + filePath + '!'))
return
pass
outFile.write(str(self) + '\n')
outFile.close()
pass
def __str__(self):
return json.dumps(self.data, sort_keys=True, indent=2)
pass
pass
if (__name__ == '__main__'):
j = JsonCloak()
......@@ -62,7 +62,7 @@ if (__name__ == '__main__'):
j.save('Kooft.json')
j.load('Kooft.json')
pass
......@@ -13,7 +13,7 @@ class FannNet(object):
self.params = JsonCloak()
self.nNeurons = []
pass
def load(self, path):
try:
......@@ -21,7 +21,7 @@ class FannNet(object):
except:
print('Error: Oops! Cannot open ' + path +'!')
return False
pass
for i, l in enumerate(f):
l = l.replace('\n', '')
......@@ -30,17 +30,17 @@ class FannNet(object):
if (i == 0):
self.params.put('version', l)
continue
pass
e = l.split('=')
self.params.put(e[0], e[1])
pass
self.extract()
f.close()
pass
def extract(self):
layers = self.params.get('layer_sizes')
......@@ -59,7 +59,7 @@ class FannNet(object):
p = re.match('\((.+),(.+),(.+)\)', m.group(1))
neurons.append((int(p.group(1)), int(p.group(2)), float(p.group(3))))
m = re.match('\s*(\([^\)]+\))(.+)', nnStr)
pass
j = 0
i = 0
......@@ -72,8 +72,8 @@ class FannNet(object):
if (i == len(self.nn.neurons[j])):
i = 0
j += 1
pass
pass
sStr = self.params.get('connections (connected_to_neuron, weight)')
synapses = []
......@@ -83,7 +83,7 @@ class FannNet(object):
p = re.match('\((.+),(.+)\)', m.group(1))
synapses.append((int(p.group(1)), float(p.group(2))))
m = re.match('\s*(\([^\)]+\))(.+)', sStr)
pass
i = 0;
for l in self.nn.neurons:
......@@ -92,27 +92,27 @@ class FannNet(object):
print(synapses[i])
n.w[j] = synapses[i][1]
i += 1
pass
pass
pass
pass
def saveJson(self, path):
self.params.save(path)
pass
def saveEssence(self, path):
try: f = open(path, 'w')
except:
print('Error: Oops! Cannot open ' + path +'!')
return False
pass
f.write(str(self.nn))
f.close()
pass
activation = [
'LINEAR',
......@@ -147,7 +147,7 @@ class FannNet(object):
#LAYER = _libfann.LAYER
#SHORTCUT = _libfann.SHORTCUT
pass
if __name__ == '__main__':
fannNet = FannNet()
......@@ -183,7 +183,7 @@ if __name__ == '__main__':
print(x, y)
exit(0)
pass
......
......@@ -9,16 +9,16 @@ import json
class JsonCloak(object):
def __init__(self):
self.data = {}
pass
def put(self, field, value):
self.data[field] = value
pass
def get(self, field):
try: return self.data[field]
except: return None
pass
def load(self, filePath):
try: inFile = open(filePath)
......@@ -26,11 +26,11 @@ class JsonCloak(object):
inFile = None
print(('Error! Oops! Cannot open ' + str(filePath) + '!'))
return
pass
self.data = json.loads(inFile.read())
inFile.close()
pass
def save(self, filePath):
try: outFile = open(filePath, 'w')
......@@ -38,18 +38,18 @@ class JsonCloak(object):
outFile = None
print(('Error! Oops! Cannot open ' + filePath + '!'))
return
pass
outFile.write(str(self) + '\n')
outFile.close()
pass
def __str__(self):
return json.dumps(self.data, sort_keys=True, indent=2)
pass
pass
if (__name__ == '__main__'):
j = JsonCloak()
......@@ -62,7 +62,7 @@ if (__name__ == '__main__'):
j.save('Kooft.json')
j.load('Kooft.json')
pass
......@@ -8,11 +8,11 @@ import math
def linear(x, m):
return m * x
pass
def dLinear(x, y, m):
return m
pass
def sigmoid(x, m):
x = x * m
......@@ -24,11 +24,11 @@ def sigmoid(x, m):
return 1./(1. + math.exp(-2. * x))
return math.tanh(x)#((1 - math.exp(-x))/(1 + math.exp(-x)))
pass
def dSigmoid(x, y, m):
return (2. * m * y * (1. - y));
pass
def sigmoidSymmetric(x, m):
x = x * m
......@@ -39,11 +39,11 @@ def sigmoidSymmetric(x, m):
x = -xLimit;
return (2./(1. + math.exp(-2. * x)) - 1.0)
pass
def dSigmoidSymmetric(x, y, m):
return m * (1. - (y * y))
pass
f = {
'LINEAR': (linear, dLinear),
......@@ -69,7 +69,7 @@ if __name__ == '__main__':
print(f['sigmoid'][1](-100, f['sigmoid'][0](-100, 10), 10))
exit(0)
pass
......@@ -17,10 +17,10 @@ class NeuralNet(object):
for j in range(nNeurons[i]):
currLayer.append(Neuron(nNeurons[i - 1]))
self.neurons.append(currLayer)
pass
# self.randomize()
pass
def toDict(self):
d = {}
......@@ -29,11 +29,11 @@ class NeuralNet(object):
d['l' + str(i + 1)] = [n.toDict() for n in l]
return d
pass
def __str__(self):
return str(json.dumps(self.toDict(), sort_keys=True, indent=2))
pass
def fromDict(self, d):
self.nNeurons = d['nNeurons']
......@@ -45,21 +45,21 @@ class NeuralNet(object):
n = Neuron(0)
n.fromDict(dN)
currLayer.append(n)
pass
self.neurons.append(currLayer)
pass
pass
def fromStr(self, s):
self.fromDict(json.loads(str(s)))
pass
def randomize(self, r = (-1.0, 1.0)):
for l in self.neurons:
for n in l:
n.randomize(r)
pass
def compute(self, x):
x = x[:]
......@@ -69,17 +69,17 @@ class NeuralNet(object):
for n in l:
o.append(n.compute(x))
x = o
pass
return x
pass
def load(self, path):
try: f = open(path)
except:
print('Error: Oops! Cannot open ' + path +'!')
return False
pass
self.fromStr(f.read())
......@@ -90,12 +90,12 @@ class NeuralNet(object):
except:
print('Error: Oops! Cannot open ' + path +'!')
return False
pass
f.write(str(self.nn))
f.close()
pass
# def backProp(self, (x, y, d), eta):
......@@ -108,11 +108,11 @@ class NeuralNet(object):
# h.append(o)
#
# n.deltaIn = []
# pass
#
# for n in self.outputLayer:
# n.compute(h)
# pass
#
# err = 0
# for i, n in enumerate(self.outputLayer):
......@@ -123,15 +123,15 @@ class NeuralNet(object):
#
# for j, delta in enumerate(n.deltaOut):
# self.hiddenLayer[j].deltaIn.append(delta)
# pass
# pass
#
# for n in self.hiddenLayer:
# n.backProp(eta, d)
# pass
#
# return err
# pass
#
# def train(self, (x, y, d), eta, epsilon, nEpoch):
# eta = eta / max(d)
......@@ -142,8 +142,8 @@ class NeuralNet(object):
# err += self.backProp((x[i], y[i], d[i]), eta)
# print k, err
# if (err < epsilon): break
# pass
# pass
#
# def test(self, (x, y)):
# rmse = 0.
......@@ -157,28 +157,28 @@ class NeuralNet(object):
# mse = mse / n
#
# rmse += mse ** 0.5
# pass
# n = len(y)
# rmse = rmse / n
#
# return rmse
# pass
def dump(self):
for i, n in enumerate(self.hiddenLayer):
print(i, 'h'*64)
print(n.w)
pass
for i, n in enumerate(self.outputLayer):
print(i, 'o'*64)
print(n.w)
pass
print('o'*64)
pass
pass
if __name__ == '__main__':
mode = 'WEIGHTED_AND'
......@@ -220,10 +220,10 @@ if __name__ == '__main__':
o = nn.compute(x[i])
print('x[i]:', x[i])
print('y[i]:', y[i], 'o:', o)
pass
# print 'rmse', nn.test((x, y))
pass
if (mode == 'AND'):
nn = NeuralNet(2, 2, 1)
......@@ -274,8 +274,8 @@ if __name__ == '__main__':
o = nn.compute(x[i])
print(x[i])
print(y[i], o)
pass
exit(0)
pass
......@@ -20,29 +20,29 @@ class Neuron(object):
self.activationFn = activationFn
self.activationMeta = activationMeta
self.f = f[activationFn]
pass
def toDict(self):
return {'w': self.w, 'activationFn': self.activationFn, 'activationMeta': self.activationMeta}
pass
def __str__(self):
return str(json.dumps(self.toDict(), sort_keys=True, indent=2))
pass
def fromDict(self, d):
self.__init__(len(d['w']), d['activationFn'], d['activationMeta'])
self.w = d['w']
pass
def fromStr(self, s):
self.fromDict(json.loads(s))
pass
def randomize(self, r = (-1.0, 1.0)):
for i in range(len(self.w)):
self.w[i] = r[0] + random() * (r[1] - r[0])
pass
def compute(self, x):
self.x = x[0:len(self.w)]
......@@ -57,7 +57,7 @@ class Neuron(object):
self.df = self.f[1](n, o, self.activationMeta)
return o
pass
# d is the distribution of training data and
# needs to be 1 unless backprop is boosted
......@@ -74,15 +74,15 @@ class Neuron(object):
for i in range(len(self.w)):
self.w[i] = self.w[i] + eta * delta * (d * self.x[i])
self.deltaOut[i] = delta * self.w[i]
pass
pass
def calcDelta(self, y):
self.deltaIn = [y - self.y]
return self.deltaIn[0]
pass
pass
if __name__ == '__main__':
mode = 'AND'
......@@ -117,10 +117,10 @@ if __name__ == '__main__':
err += 0.5 * delta ** 2
n.backProp(eta, 1)
pass