code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
self.log = 1 self.logFile = fileName self._logPtr = open(fileName, "w") if writeName: self._namePtr = open(fileName + ".name", "w")
def setLog(self, fileName, writeName=False)
Opens a log file with name fileName.
3.753624
3.795694
0.988916
self._logPtr.close() if self._namePtr: self._namePtr.close() self.log = 0
def closeLog(self)
Closes the log file.
7.413503
6.697528
1.106901
if self.log: writeArray(self._logPtr, self.activation) if self._namePtr: self._namePtr.write(network.getWord(self.activation)) self._namePtr.write("\n")
def writeLog(self, network)
Writes to the log file.
8.52209
8.281719
1.029024
string = "Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)\n" % ( self.name, self.kind, self.size, self.active, self.frozen) if (self.type == 'Output'): string += toStringArray('Target ', self.target, self.displayWidth) string += toStringArray('Activa...
def toString(self)
Returns a string representation of Layer instance.
3.153685
3.019557
1.04442
if self.displayWidth == 0: return print("=============================") print("Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)" % ( self.name, self.kind, self.size, self.active, self.frozen)) if (self.type == 'Output'): displayArray('Target '...
def display(self)
Displays the Layer instance to the screen.
3.429385
3.351904
1.023116
#if self.verify and not self.activationSet == 0: # raise LayerError, \ # ('Activation flag not reset. Activations may have been set multiple times without any intervening call to propagate().', self.activationSet) Numeric.put(self.activation, Numeric.arange(len(self....
def setActivations(self, value)
Sets all activations to the value of the argument. Value should be in the range [0,1].
9.711465
9.060555
1.07184
array = Numeric.array(arr) if not len(array) == self.size: raise LayerError('Mismatched activation size and layer size in call to copyActivations()', \ (len(array), self.size)) if self.verify and not self.activationSet == 0: if not reckless: ...
def copyActivations(self, arr, reckless = 0)
Copies activations from the argument array into layer activations.
5.883564
5.634982
1.044114
# Removed this because both propagate and backprop (via compute_error) set targets #if self.verify and not self.targetSet == 0: # if not self.warningIssued: # print 'Warning! Targets have already been set and no intervening backprop() was called.', \ # ...
def setTargets(self, value)
Sets all targets the the value of the argument. This value must be in the range [min,max].
7.321119
7.184808
1.018972
array = Numeric.array(arr) if not len(array) == self.size: raise LayerError('Mismatched target size and layer size in call to copyTargets()', \ (len(array), self.size)) # Removed this because both propagate and backprop (via compute_error) set targets ...
def copyTargets(self, arr)
Copies the targets of the argument array into the self.target attribute.
5.773539
5.536612
1.042793
self.randomize() self.dweight = Numeric.zeros((self.fromLayer.size, \ self.toLayer.size), 'f') self.wed = Numeric.zeros((self.fromLayer.size, \ self.toLayer.size), 'f') self.wedLast = Numeric.zeros((self.fro...
def initialize(self)
Initializes self.dweight and self.wed to zero matrices.
3.541173
2.477596
1.429278
if toLayerSize <= 0 or fromLayerSize <= 0: raise LayerError('changeSize() called with invalid layer size.', \ (fromLayerSize, toLayerSize)) dweight = Numeric.zeros((fromLayerSize, toLayerSize), 'f') wed = Numeric.zeros((fromLayerSize, toLayerSi...
def changeSize(self, fromLayerSize, toLayerSize)
Changes the size of the connection depending on the size change of either source or destination layer. Should only be called through Network.changeLayerSize().
2.700445
2.675365
1.009374
if self.toLayer._verbosity > 4: print("wed: from '" + self.fromLayer.name + "' to '" + self.toLayer.name +"'") for j in range(self.toLayer.size): print(self.toLayer.name, "[", j, "]", end=" ") print('') for i in range(self.fromLayer.size):...
def display(self)
Displays connection information to the screen.
1.741864
1.71866
1.013501
string = "" if self.toLayer._verbosity > 4: string += "wed: from '" + self.fromLayer.name + "' to '" + self.toLayer.name +"'\n" string += " " for j in range(self.toLayer.size): string += " " + self.toLayer.name + "[" + str(j...
def toString(self)
Connection information as a string.
1.81451
1.811505
1.001659
# first clear the old cached values self.cacheConnections = [] self.cacheLayers = [] if val: for layer in self.layers: if layer.active and not layer.frozen: self.cacheLayers.append( layer ) for connection in self.connec...
def setCache(self, val = 1)
Sets cache on (or updates), or turns off
3.250793
3.301904
0.984521
next = {startLayer.name : startLayer} visited = {} while next != {}: for item in list(next.items()): # item[0] : name, item[1] : layer reference # add layer to visited dict and del from next visited[item[0]] = item[1] ...
def path(self, startLayer, endLayer)
Used in error checking with verifyArchitecture() and in prop_from().
3.58305
3.499677
1.023823
for i in range(len(self.layers)): if layer == self.layers[i]: # shallow cmp return i return -1 # not in list
def getLayerIndex(self, layer)
Given a reference to a layer, returns the index of that layer in self.layers.
6.267767
5.848995
1.071597
layer._verbosity = verbosity layer._maxRandom = self._maxRandom layer.minTarget = 0.0 layer.maxTarget = 1.0 layer.minActivation = 0.0 layer.maxActivation = 1.0 if position == None: self.layers.append(layer) else: self.layer...
def add(self, layer, verbosity = 0, position = None)
Adds a layer. Layer verbosity is optional (default 0).
2.953656
2.846718
1.037565
for c in self.connections: if (c.fromLayer.name == fromName and c.toLayer.name == toName): return 1 return 0
def isConnected(self, fromName, toName)
Are these two layers connected this way?
3.017599
2.358615
1.279394
fromName, toName, rest = names[0], names[1], names[2:] self.connectAt(fromName, toName) if len(rest) != 0: self.connect(toName, *rest)
def connect(self, *names)
Connects a list of names, one to the next.
3.522999
3.000835
1.174006
fromLayer = self.getLayer(fromName) toLayer = self.getLayer(toName) if self.getLayerIndex(fromLayer) >= self.getLayerIndex(toLayer): raise NetworkError('Layers out of order.', (fromLayer.name, toLayer.name)) if (fromLayer.type == 'Output'): fromLayer.ty...
def connectAt(self, fromName, toName, position = None)
Connects two layers by instantiating an instance of Connection class. Allows a position number, indicating the ordering of the connection.
2.281813
2.177569
1.047872
netType = "serial" if "type" in kw: netType = kw["type"] self.addLayer('input', arg[0]) hiddens = [] if len(arg) > 3: hcount = 0 for hidc in arg[1:-1]: name = 'hidden%d' % hcount self.addLayer(name, hidc...
def addLayers(self, *arg, **kw)
Creates an N layer network with 'input', 'hidden1', 'hidden2',... and 'output' layers. Keyword type indicates "parallel" or "serial". If only one hidden layer, it is called "hidden".
2.801404
2.479959
1.129617
# first, construct an array of all of the weights # that won't be deleted: gene = [] for layer in self.layers: if layer.type != 'Input': for i in range(layer.size): if layer.name == layername and i == nodeNum: ...
def deleteLayerNode(self, layername, nodeNum)
Removes a particular unit/node from a layer.
3.700994
3.764171
0.983216
self.changeLayerSize(layerName, self[layerName].size + 1) if bias != None: self[layerName].weight[-1] = bias for name in list(weights.keys()): for c in self.connections: if c.fromLayer.name == name and c.toLayer.name == layerName: ...
def addLayerNode(self, layerName, bias = None, weights = {})
Adds a new node to a layer, and puts in new weights. Adds node on the end. Weights will be random, unless specified. bias = the new node's bias weight weights = dict of {connectedLayerName: [weights], ...} Example: >>> net = Network() # doctest: +ELLIPSIS Conx using ...
2.563605
2.70731
0.94692
# for all connection from to this layer, change matrix: if self.sharedWeights: raise AttributeError("shared weights broken") for connection in self.connections: if connection.fromLayer.name == layername: connection.changeSize( newsize, connection...
def changeLayerSize(self, layername, newsize)
Changes layer size. Newsize must be greater than zero.
4.803629
4.841828
0.992111
print("Initializing '%s' weights..." % self.name, end=" ", file=sys.stderr) if self.sharedWeights: raise AttributeError("shared weights broken") self.count = 0 for connection in self.connections: connection.initialize() for layer in self.layers: ...
def initialize(self)
Initializes network by calling Connection.initialize() and Layer.initialize(). self.count is set to zero.
5.699436
4.259496
1.338054
for name in dict: self.layersByName[name].copyActivations( dict[name] )
def putActivations(self, dict)
Puts a dict of name: activations into their respective layers.
8.777266
5.664796
1.549441
retval = {} for name in nameList: retval[name] = self.layersByName[name].getActivationsList() return retval
def getActivationsDict(self, nameList)
Returns a dictionary of layer names that map to a list of activations.
3.988672
3.380132
1.180034
self.seed = value random.seed(self.seed) if self.verbosity >= 0: print("Conx using seed:", self.seed)
def setSeed(self, value)
Sets the seed to value.
6.607796
6.217268
1.062813
for connection in self.connections: if connection.fromLayer.name == lfrom and \ connection.toLayer.name == lto: return connection raise NetworkError('Connection was not found.', (lfrom, lto))
def getConnection(self, lfrom, lto)
Returns the connection instance connecting the specified (string) layer names.
3.739953
3.616097
1.034251
self._verbosity = value for layer in self.layers: layer._verbosity = value
def setVerbosity(self, value)
Sets network self._verbosity and each layer._verbosity to value.
5.549171
2.277388
2.436638
self._maxRandom = value for layer in self.layers: layer._maxRandom = value
def setMaxRandom(self, value)
Sets the maxRandom Layer attribute for each layer to value.Specifies the global range for randomly initialized values, [-max, max].
5.303014
4.363204
1.215394
for connection in self.connections: if connection.fromLayer.name == fromName and \ connection.toLayer.name == toName: return connection.weight raise NetworkError('Connection was not found.', (fromName, toName))
def getWeights(self, fromName, toName)
Gets the weights of the connection between two layers (argument strings).
3.526367
3.164948
1.114195
for connection in self.connections: if connection.fromLayer.name == fromName and \ connection.toLayer.name == toName: connection.weight[fromPos][toPos] = value return value raise NetworkError('Connection was not found.', (fromName, toNa...
def setWeight(self, fromName, fromPos, toName, toPos, value)
Sets the weight of the connection between two layers (argument strings).
3.903016
3.600243
1.084098
self.orderedInputs = value if self.orderedInputs: self.loadOrder = [0] * len(self.inputs) for i in range(len(self.inputs)): self.loadOrder[i] = i
def setOrderedInputs(self, value)
Sets self.orderedInputs to value. Specifies if inputs should be ordered and if so orders the inputs.
2.523868
2.408971
1.047696
for l in arg: if not type(l) == list and \ not type(l) == type(Numeric.array([0.0])) and \ not type(l) == tuple and \ not type(l) == dict: return 0 if type(l) == dict: for i in l: if...
def verifyArguments(self, arg)
Verifies that arguments to setInputs and setTargets are appropriately formatted.
2.678951
2.594142
1.032693
if not self.verifyArguments(inputs) and not self.patterned: raise NetworkError('setInputs() requires [[...],[...],...] or [{"layerName": [...]}, ...].', inputs) self.inputs = inputs self.loadOrder = [0] * len(self.inputs) for i in range(len(self.inputs)): ...
def setInputs(self, inputs)
Sets self.input to inputs. Load order is by default random. Use setOrderedInputs() to order inputs.
6.87915
5.950742
1.156016
if not self.verifyArguments(targets) and not self.patterned: raise NetworkError('setTargets() requires [[...],[...],...] or [{"layerName": [...]}, ...].', targets) self.targets = targets
def setTargets(self, targets)
Sets the targets.
18.639322
18.541338
1.005285
if data2 == None: # format #1 inputs = [x[0] for x in data1] targets = [x[1] for x in data1] else: # format 2 inputs = data1 targets = data2 self.setInputs(inputs) self.setTargets(targets)
def setInputsAndTargets(self, data1, data2=None)
Network.setInputsAndTargets() Sets the corpus of data for training. Can be in one of two formats: Format 1: setInputsAndTargets([[input0, target0], [input1, target1]...]) Network.setInputsAndTargets([[[i00, i01, ...], [t00, t01, ...]], [[i10, i11, ...], [t10...
2.52532
2.184158
1.156199
flag = [0] * len(self.inputs) self.loadOrder = [0] * len(self.inputs) for i in range(len(self.inputs)): pos = int(random.random() * len(self.inputs)) while (flag[pos] == 1): pos = int(random.random() * len(self.inputs)) flag[pos] = 1 ...
def randomizeOrder(self)
Randomizes self.loadOrder, the order in which inputs set with self.setInputs() are presented.
2.274006
1.983799
1.146288
vector2 = self.replacePatterns(vec2) length = min(len(vector1), len(vector2)) if self.verbosity > 4: print("Copying Vector: ", vector2[start:start+length]) p = 0 for i in range(start, start + length): vector1[p] = vector2[i] p += 1
def copyVector(self, vector1, vec2, start)
Copies vec2 into vector1 being sure to replace patterns if necessary. Use self.copyActivations() or self.copyTargets() instead.
3.383491
3.074591
1.100468
vector = self.replacePatterns(vec, layer.name) if self.verbosity > 4: print("Copying Activations: ", vector[start:start+layer.size]) layer.copyActivations(vector[start:start+layer.size])
def copyActivations(self, layer, vec, start = 0)
Copies activations in vec to the specified layer, replacing patterns if necessary.
4.733831
3.835621
1.234176
set = {} if type(self.inputs[pos]) == dict: set.update(self.inputs[pos]) else: set["input"] = self.inputs[pos] if self.targets: if type(self.targets[pos]) == dict: set.update(self.targets[pos]) else: ...
def getDataCrossValidation(self, pos)
Returns the inputs/targets for a pattern pos, or assumes that the layers are called input and output and uses the lists in self.inputs and self.targets.
2.366688
2.029571
1.166103
if intype == "input": vector = self.inputs elif intype == "target": vector = self.targets else: raise AttributeError("invalid map type '%s'" % intype) return vector[pos][offset:offset+self[name].size]
def getDataMap(self, intype, pos, name, offset = 0)
Hook defined to lookup a name, and get it from a vector. Can be overloaded to get it from somewhere else.
4.042145
3.92911
1.028769
retval = {} if pos >= len(self.inputs): raise IndexError('getData() pattern beyond range.', pos) if self.verbosity >= 1: print("Getting input", pos, "...") if len(self.inputMap) == 0: if type(self.inputs[pos]) == dict: # allow inputs to be a dict ...
def getData(self, pos)
Returns dictionary with input and target given pos.
3.12065
2.975226
1.048878
if len(self.cacheLayers) != 0 or len(self.cacheConnections) != 0: return # flags for layer type tests hiddenInput = 1 hiddenOutput = 1 outputLayerFlag = 1 inputLayerFlag = 1 # must have layers and connections if len(self.layers) == 0: ...
def verifyArchitecture(self)
Check for orphaned layers or connections. Assure that network architecture is feed-forward (no-cycles). Check connectivity. Check naming.
2.270205
2.23267
1.016812
for layer in self.layers: if (layer.verify and layer.type == 'Input' and layer.kind != 'Context' and layer.active and not layer.activationSet): raise LayerError("Inputs are not set and verifyInputs() was called ...
def verifyInputs(self)
Used in propagate() to verify that the network input activations have been set.
7.749248
5.918747
1.309272
for layer in self.layers: if layer.verify and layer.type == 'Output' and layer.active and not layer.targetSet: raise LayerError('Targets are not set and verifyTargets() was called.',\ (layer.name, layer.type)) else: ...
def verifyTargets(self)
Used in backprop() to verify that the network targets have been set.
9.301382
7.018334
1.325298
tss = 0.0 size = 0 for layer in self.layers: if layer.type == 'Output': tss += layer.TSSError() size += layer.size return math.sqrt( tss / size )
def RMSError(self)
Returns Root Mean Squared Error for all output layers in this network.
5.626673
3.625951
1.551779
if self.verbosity > 0: print("Network.step() called with:", args) # First, copy the values into either activations or targets: retargs = self.preStep(**args) if retargs: args = retargs # replace the args # Propagate activation through network: self.pr...
def step(self, **args)
Network.step() Does a single step. Calls propagate(), backprop(), and change_weights() if learning is set. Format for parameters: <layer name> = <activation/target list>
4.354535
3.946701
1.103335
self.preSweep() if self.loadOrder == []: raise NetworkError('No loadOrder for the inputs. Make sure inputs are properly set.', self.loadOrder) if len(self.targets) != 0 and len(self.targets) != len(self.inputs): raise NetworkError("Number of inputs does not equal...
def sweep(self)
Runs through entire dataset. Returns TSS error, total correct, total count, pcorrect (a dict of layer data)
4.731277
4.202988
1.125694
# get learning value and then turn it off oldLearning = self.learning self.learning = 0 tssError = 0.0; totalCorrect = 0; totalCount = 0; totalPCorrect = {} self._cv = True # in cross validation if self.autoCrossValidation: for i in range(len(self.inp...
def sweepCrossValidation(self)
sweepCrossValidation() will go through each of the crossvalidation input/targets. The crossValidationCorpus is a list of dictionaries of input/targets referenced by layername. Example: ({"input": [0.0, 0.1], "output": [1.0]}, {"input": [0.5, 0.9], "output": [0.0]})
3.463199
3.378297
1.025132
count = 0 if self[layerName].active: count += 1 # 1 = bias for connection in self.connections: if connection.active and connection.fromLayer.active and connection.toLayer.name == layerName: count += connection.fromLayer.size r...
def numConnects(self, layerName)
Number of incoming weights, including bias. Assumes fully connected.
5.326702
4.749633
1.121497
if self.verbosity > 2: print("Partially propagating network:") # find all the layers involved in the propagation propagateLayers = [] # propagateLayers should not include startLayers (no loops) for startLayer in startLayers: for layer in self.layers: ...
def prop_from(self, startLayers)
Start propagation from the layers in the list startLayers. Make sure startLayers are initialized with the desired activations. NO ERROR CHECKING.
4.876056
4.746204
1.027359
self.prePropagate(**args) for key in args: layer = self.getLayer(key) if layer.kind == 'Input': if self[key].verify and not self[key].activationSet == 0: raise AttributeError("attempt to set activations on input layer '%s' without res...
def propagate(self, **args)
Propagates activation through the network. Optionally, takes input layer names as keywords, and their associated activations. If input layer(s) are given, then propagate() will return the output layer's activation. If there is more than one output layer, then a dictionary is returned. E...
4.295707
4.230118
1.015505
for layerName in args: self[layerName].activationSet = 0 # force it to be ok self[layerName].copyActivations(args[layerName]) # init toLayer: self[toLayer].netinput = (self[toLayer].weight).copy() # for each connection, in order: for connection i...
def propagateTo(self, toLayer, **args)
Propagates activation to a layer. Optionally, takes input layer names as keywords, and their associated activations. Returns the toLayer's activation. Examples: >>> net = Network() # doctest: +ELLIPSIS Conx using seed: ... >>> net.addLayers(2, 5, 1) >>> len(net.propagat...
5.793977
5.87167
0.986768
for layerName in args: self[layerName].copyActivations(args[layerName]) # initialize netinput: started = 0 for layer in self.layers: if layer.name == startLayer: started = 1 continue # don't set this one if not ...
def propagateFrom(self, startLayer, **args)
Propagates activation through the network. Optionally, takes input layer names as keywords, and their associated activations. If input layer(s) are given, then propagate() will return the output layer's activation. If there is more than one output layer, then a dictionary is returned. E...
3.549366
3.485392
1.018355
def act(v): if v < -15.0: return 0.0 elif v > 15.0: return 1.0 else: return 1.0 / (1.0 + Numeric.exp(-v)) return Numeric.array(list(map(act, x)), 'f')
def activationFunctionASIG(self, x)
Determine the activation of a node based on that nodes net input.
3.343799
3.275915
1.020722
def act(v): if v < -15.0: return 0.0 elif v > 15.0: return 1.0 else: return 1.0 / (1.0 + Numeric.exp(-v)) return (act(x) * (1.0 - act(x))) + self.sigmoid_prime_offset
def actDerivASIG(self, x)
Only works on scalars.
4.386049
4.255604
1.030653
self.activationFunction = self.activationFunctionTANH self.ACTPRIME = self.ACTPRIMETANH self.actDeriv = self.actDerivTANH for layer in self: layer.minTarget, layer.minActivation = -1.7159, -1.7159 layer.maxTarget, layer.maxActivation = 1.7159, 1.7159
def useTanhActivationFunction(self)
Change the network to use the hyperbolic tangent activation function for all layers. Must be called after all layers have been added.
4.324133
4.088301
1.057685
self.activationFunction = self.activationFunctionFahlman self.ACTPRIME = self.ACTPRIME_Fahlman self.actDeriv = self.actDerivFahlman for layer in self: layer.minTarget, layer.minActivation = -0.5, -0.5 layer.maxTarget, layer.maxActivation = 0.5, 0.5
def useFahlmanActivationFunction(self)
Change the network to use Fahlman's default activation function for all layers. Must be called after all layers have been added.
4.726653
4.406635
1.072622
retval = self.compute_error(**args) if self.learning: self.compute_wed() return retval
def backprop(self, **args)
Computes error and wed for back propagation of error.
14.008018
5.650739
2.478971
#print "WEIGHT = ", w shrinkFactor = self.mu / (1.0 + self.mu) if self.splitEpsilon: e /= float(n) if self._quickprop: nextStep = Numeric.zeros(len(dweightLast), 'f') for i in range(len(dweightLast)): s = wed[i] ...
def deltaWeight(self, e, wed, m, dweightLast, wedLast, w, n)
e - learning rate wed - weight error delta vector (slope) m - momentum dweightLast - previous dweight vector (slope) wedLast - only used in quickprop; last weight error delta vector w - weight vector n - fan-in, number of connections coming in (counts bias, too)
3.102102
3.043586
1.019226
dw_count, dw_sum = 0, 0.0 if len(self.cacheLayers) != 0: changeLayers = self.cacheLayers else: changeLayers = self.layers for layer in changeLayers: if layer.active and layer.type != 'Input': if not layer.frozen: ...
def change_weights(self)
Changes the weights according to the error values calculated during backprop(). Learning must be set.
3.140409
3.113398
1.008676
def difference(v): if not self.hyperbolicError: #if -0.1 < v < 0.1: return 0.0 #else: return v else: if v < -0.9999999: return -17.0 elif v > 0.9999999: return 17.0 else: return m...
def errorFunction(self, t, a)
Using a hyperbolic arctan on the error slightly exaggerates the actual error non-linearly. Return t - a to just use the difference. t - target vector a - activation vector
4.570711
4.317435
1.058664
retval = 0.0; correct = 0; totalCount = 0 for layer in self.layers: if layer.active: if layer.type == 'Output': layer.error = self.errorFunction(layer.target, layer.activation) totalCount += layer.size retv...
def ce_init(self)
Initializes error computation. Calculates error for output layers and initializes hidden layer error to zero.
4.667273
3.984853
1.171254
for key in args: layer = self.getLayer(key) if layer.kind == 'Output': self.copyTargets(layer, args[key]) self.verifyTargets() # better have targets set error, correct, total = self.ce_init() pcorrect = {} # go backwards through ea...
def compute_error(self, **args)
Computes error for all non-output layers backwards through all projections.
7.813644
7.455156
1.048086
if len(self.cacheConnections) != 0: changeConnections = self.cacheConnections else: changeConnections = self.connections for connect in reverse(changeConnections): if connect.active and connect.fromLayer.active and connect.toLayer.active: ...
def compute_wed(self)
Computes weight error derivative for all connections in self.connections starting with the last connection.
4.173933
3.387254
1.232247
output = "" for layer in reverse(self.layers): output += layer.toString() return output
def toString(self)
Returns the network layers as a string.
6.46934
4.140639
1.562401
print("Display network '" + self.name + "':") size = list(range(len(self.layers))) size.reverse() for i in size: if self.layers[i].active: self.layers[i].display() if self.patterned and self.layers[i].type != 'Hidden': ...
def display(self)
Displays the network to the screen.
2.924464
2.851573
1.025561
gene = [] for layer in self.layers: if layer.type != 'Input': for i in range(layer.size): gene.append( layer.weight[i] ) for connection in self.connections: for i in range(connection.fromLayer.size): for j in ra...
def arrayify(self)
Returns an array of node bias values and connection weights for use in a GA.
2.786719
2.374938
1.173386
g = 0 # if gene is too small an IndexError will be thrown for layer in self.layers: if layer.type != 'Input': for i in range(layer.size): layer.weight[i] = float( gene[g]) g += 1 for connection in self.connectio...
def unArrayify(self, gene)
Copies gene bias values and weights to network bias values and weights.
3.827153
3.657962
1.046253
self.saveWeights(filename, mode, counter)
def saveWeightsToFile(self, filename, mode='pickle', counter=None)
Deprecated. Use saveWeights instead.
5.608176
3.431507
1.634319
# modes: pickle/conx, plain, tlearn if "?" in filename: # replace ? pattern in filename with epoch number import re char = "?" match = re.search(re.escape(char) + "+", filename) if match: num = self.epoch if counter...
def saveWeights(self, filename, mode='pickle', counter=None)
Saves weights to file in pickle, plain, or tlearn mode.
2.955677
2.84632
1.03842
self.saveNetworkToFile(filename, makeWrapper, mode, counter)
def saveNetwork(self, filename, makeWrapper = 1, mode = "pickle", counter = None)
Saves network to file using pickle.
5.121316
3.813132
1.343073
if "?" in filename: # replace ? pattern in filename with epoch number import re char = "?" match = re.search(re.escape(char) + "+", filename) if match: num = self.epoch if counter != None: num = counter ...
def saveNetworkToFile(self, filename, makeWrapper = 1, mode = "pickle", counter = None)
Deprecated.
2.975024
2.958533
1.005574
return self.loadVectorsFromFile(filename, cols, everyNrows, delim, checkEven, patterned)
def loadVectors(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1, patterned = 0)
Load a set of vectors from a file. Takes a filename, list of cols you want (or None for all), get every everyNrows (or 1 for no skipping), and a delimeter.
2.796693
3.672297
0.761565
fp = open(filename, "r") line = fp.readline() lineno = 0 lastLength = None data = [] while line: if lineno % everyNrows == 0: if patterned: linedata1 = [x for x in line.strip().split(delim)] else: ...
def loadVectorsFromFile(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1, patterned = 0)
Deprecated.
2.553171
2.569296
0.993724
self.loadInputPatternsFromFile(filename, cols, everyNrows, delim, checkEven)
def loadInputPatterns(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1)
Loads inputs as patterns from file.
3.261273
3.028318
1.076926
self.inputs = self.loadVectors(filename, cols, everyNrows, delim, checkEven, patterned = 1) self.loadOrder = [0] * len(self.inputs) for i in range(len(self.inputs)): self.loadOrder[i] = i
def loadInputPatternsFromFile(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1)
Deprecated.
3.447868
3.323411
1.037449
self.loadInputsFromFile(filename, cols, everyNrows, delim, checkEven)
def loadInputs(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1)
Loads inputs from file. Patterning is lost.
3.478043
3.179086
1.094039
fp = open(filename, 'w') for input in self.inputs: vec = self.replacePatterns(input) for item in vec: fp.write("%f " % item) fp.write("\n")
def saveInputsToFile(self, filename)
Deprecated.
4.011614
4.063489
0.987234
self.loadTargetsFromFile(filename, cols, everyNrows, delim, checkEven)
def loadTargets(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1)
Loads targets from file.
3.432257
3.056506
1.122935
self.targets = self.loadVectors(filename, cols, everyNrows, delim, checkEven)
def loadTargetsFromFile(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1)
Loads targets from file.
4.242649
3.891349
1.090277
self.loadTargetPatternssFromFile(filename, cols, everyNrows, delim, checkEven)
def loadTargetPatterns(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1)
Loads targets as patterns from file.
5.495135
5.083567
1.080961
self.targets = self.loadVectors(filename, cols, everyNrows, delim, checkEven, patterned=1)
def loadTargetPatternsFromFile(self, filename, cols = None, everyNrows = 1, delim = ' ', checkEven = 1)
Deprecated.
7.078886
6.394175
1.107084
fp = open(filename, 'w') for target in self.targets: vec = self.replacePatterns(target) for item in vec: fp.write("%f " % item) fp.write("\n")
def saveTargetsToFile(self, filename)
Deprecated.
4.131644
4.17554
0.989487
fp = open(filename, 'w') for i in range(len(self.inputs)): try: vec = self.replacePatterns(self.inputs[i]) for item in vec: fp.write("%f " % item) except: pass try: vec = self...
def saveDataToFile(self, filename)
Deprecated.
2.426016
2.424046
1.000813
if ocnt == -1: ocnt = int(self.layers[len(self.layers) - 1].size) fp = open(filename, 'r') line = fp.readline() self.targets = [] self.inputs = [] while line: data = list(map(float, line.split())) cnt = len(data) ic...
def loadDataFromFile(self, filename, ocnt = -1)
Deprecated.
2.522768
2.489645
1.013304
if (name, layer) in self.patterns: return self.patterns[(name, layer)] else: return self.patterns[name]
def lookupPattern(self, name, layer)
See if there is a name/layer pattern combo, else return the name pattern.
3.00954
2.240391
1.34331
if not self.patterned: return vector if type(vector) == str: return self.replacePatterns(self.lookupPattern(vector, layer), layer) elif type(vector) != list: return vector # should be a vector if we made it here vec = [] for v in vector: ...
def replacePatterns(self, vector, layer = None)
Replaces patterned inputs or targets with activation vectors.
2.616416
2.523278
1.036912
if not self.patterned: return vector if type(vector) == int: if self.getWord(vector) != '': return self.getWord(vector) else: return vector elif type(vector) == float: if self.getWord(vector) != '': retu...
def patternVector(self, vector)
Replaces vector with patterns. Used for loading inputs or targets from a file and still preserving patterns.
2.333917
2.307332
1.011522
if word in self.patterns: return self.patterns[word] else: raise ValueError('Unknown pattern in getPattern().', word)
def getPattern(self, word)
Returns the pattern with key word. Example: net.getPattern("tom") => [0, 0, 0, 1]
4.651327
5.490072
0.847225
minDist = 10000 closest = None for w in self.patterns: # There may be some patterns that are scalars; we don't search # those in this function: if type(self.patterns[w]) in [int, float, int]: continue if len(self.patterns[w]) == len(patter...
def getWord(self, pattern, returnDiff = 0)
Returns the word associated with pattern. Example: net.getWord([0, 0, 0, 1]) => "tom" This method now returns the closest pattern based on distance.
3.18249
3.034282
1.048844
if word in self.patterns: raise NetworkError('Pattern key already in use. Call delPattern to free key.', word) else: self.patterns[word] = vector
def addPattern(self, word, vector)
Adds a pattern with key word. Example: net.addPattern("tom", [0, 0, 0, 1])
8.442193
7.705558
1.095598
try: if len(v1) != len(v2): return 0 for x, y in zip(v1, v2): if abs( x - y ) > self.tolerance: return 0 return 1 except: # some patterns may not be vectors try: if abs( v1 - v2 ) > s...
def compare(self, v1, v2)
Compares two values. Returns 1 if all values are withing self.tolerance of each other.
2.45364
2.276907
1.07762
if listOfLayerNamePairs == None: listOfLayerNamePairs = [] for c in self.connections: listOfLayerNamePairs.append( [c.fromLayer.name, c.toLayer.name] ) if self.verbosity > 1: print("sharing weights:", self.name, listOfLayerNamePairs) #...
def shareWeights(self, network, listOfLayerNamePairs = None)
Share weights with another network. Connection is broken after a randomize or change of size. Layers must have the same names and sizes for shared connections in both networks. Example: net.shareWeights(otherNet, [["hidden", "output"]]) This example will take the weights between the hi...
1.669627
1.683343
0.991852
output = Network.propagate(self, *arg, **kw) if self.interactive: self.updateGraphics() # IMPORTANT: convert results from numpy.floats to conventional floats if type(output) == dict: for layerName in output: output[layerName] = [float(x) ...
def propagate(self, *arg, **kw)
Propagates activation through the network.
4.484244
4.344665
1.032127
Network.loadWeights(self, filename, mode) self.updateGraphics()
def loadWeightsFromFile(self, filename, mode='pickle')
Deprecated. Use loadWeights instead.
12.380614
9.175974
1.349243
size = list(range(len(self.layers))) size.reverse() for i in size: layer = self.layers[i] if layer.active: print('%s layer (size %d)' % (layer.name, layer.size)) tlabel, olabel = '', '' if (layer.type == 'Output'): ...
def display(self)
Displays the network to the screen.
3.291332
3.281693
1.002937
if value == "ordered-continuous": self.orderedInputs = 1 self.initContext = 0 elif value == "random-segmented": self.orderedInputs = 0 self.initContext = 1 elif value == "random-continuous": self.ordered...
def setSequenceType(self, value)
You must set this!
3.106692
3.008504
1.032637