From 48c45e4b0acbf4bfdd69b6f47d00d191fecb42d1 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Sat, 29 Apr 2017 15:36:27 -0700 Subject: [PATCH] Fix more flake8 cruft; remove a bunch of logging. --- copycat/codeletMethods.py | 6 ++--- copycat/coderack.py | 3 --- copycat/conceptMapping.py | 6 ----- copycat/description.py | 2 -- copycat/formulas.py | 5 ++-- copycat/group.py | 46 ++++++++++----------------------- copycat/slipnet.py | 4 --- copycat/workspace.py | 23 +++++++++-------- copycat/workspaceFormulas.py | 4 --- copycat/workspaceObject.py | 49 +++++++++++------------------------- copycat/workspaceString.py | 17 ------------- 11 files changed, 44 insertions(+), 121 deletions(-) diff --git a/copycat/codeletMethods.py b/copycat/codeletMethods.py index 985a81c..d67f5d7 100644 --- a/copycat/codeletMethods.py +++ b/copycat/codeletMethods.py @@ -311,7 +311,7 @@ def rule_scout(ctx, codelet): for node in objectList ] descriptor = random.weighted_choice(objectList, weights) - # choose the relation (change the letmost object to "successor" or "d" + # choose the relation (change the leftmost object to "successor" or "d" objectList = [] if changed.replacement.relation: objectList += [changed.replacement.relation] @@ -878,7 +878,7 @@ def bottom_up_correspondence_scout(ctx, codelet): objectFromInitial.relevantDescriptions(), objectFromTarget.relevantDescriptions()) assert conceptMappings and __slippability(ctx, conceptMappings) - #find out if any are distinguishing + # find out if any are distinguishing distinguishingMappings = [m for m in conceptMappings if m.distinguishing()] assert distinguishingMappings # if both objects span the strings, check to see if the @@ -936,7 +936,7 @@ def important_object_correspondence_scout(ctx, codelet): objectFromInitial.relevantDescriptions(), objectFromTarget.relevantDescriptions()) assert conceptMappings and __slippability(ctx, conceptMappings) - #find out if any are distinguishing + # find out if any are distinguishing distinguishingMappings = [m for m in conceptMappings if m.distinguishing()] assert distinguishingMappings # if both objects span the strings, check to see if the diff --git a/copycat/coderack.py b/copycat/coderack.py index eb7cf24..2f630bb 100644 --- a/copycat/coderack.py +++ b/copycat/coderack.py @@ -133,10 +133,8 @@ class Coderack(object): random = self.ctx.random slipnet = self.ctx.slipnet for node in slipnet.slipnodes: - #logging.info('Trying slipnode: %s' % node.get_name()) if node.activation != 100.0: continue - #logging.info('using slipnode: %s' % node.get_name()) for codeletName in node.codelets: probability = self.probabilityOfPosting(codeletName) howMany = self.howManyToPost(codeletName) @@ -181,7 +179,6 @@ class Coderack(object): self.codelets.remove(codelet) def newCodelet(self, name, strength, arguments): - #logging.debug('Posting new codelet called %s' % name) urgency = getUrgencyBin(strength) newCodelet = Codelet(name, urgency, arguments, self.codeletsRun) self.post(newCodelet) diff --git a/copycat/conceptMapping.py b/copycat/conceptMapping.py index 34201f0..788372b 100644 --- a/copycat/conceptMapping.py +++ b/copycat/conceptMapping.py @@ -1,13 +1,7 @@ -import logging - - class ConceptMapping(object): def __init__(self, initialDescriptionType, targetDescriptionType, initialDescriptor, targetDescriptor, initialObject, targetObject): - # pylint: disable=too-many-arguments - logging.info('make a map: %s-%s', initialDescriptionType.get_name(), - targetDescriptionType.get_name()) self.slipnet = initialDescriptionType.slipnet self.initialDescriptionType = initialDescriptionType self.targetDescriptionType = targetDescriptionType diff --git a/copycat/description.py b/copycat/description.py index 472e819..1ee7365 100644 --- a/copycat/description.py +++ b/copycat/description.py @@ -1,4 +1,3 @@ -import logging from workspaceStructure import WorkspaceStructure @@ -49,7 +48,6 @@ class Description(WorkspaceStructure): self.descriptionType.buffer = 100.0 self.descriptor.buffer = 100.0 if not self.object.described(self.descriptor): - logging.info('Add %s to descriptions', self) self.object.descriptions += [self] def breakDescription(self): diff --git a/copycat/formulas.py b/copycat/formulas.py index aa7e976..8793e11 100644 --- a/copycat/formulas.py +++ b/copycat/formulas.py @@ -21,11 +21,10 @@ def __relevantDirection(objekt, slipnode): def __localRelevance(string, slipnode, relevance): - numberOfObjectsNotSpanning = numberOfMatches = 0.0 - #logging.info("find relevance for a string: %s" % string); + numberOfObjectsNotSpanning = 0.0 + numberOfMatches = 0.0 for objekt in string.objects: if not objekt.spansString(): - #logging.info('non spanner: %s' % objekt) numberOfObjectsNotSpanning += 1.0 if relevance(objekt, slipnode): numberOfMatches += 1.0 diff --git a/copycat/group.py b/copycat/group.py index fff7cc4..57a5de4 100644 --- a/copycat/group.py +++ b/copycat/group.py @@ -1,5 +1,3 @@ -import logging - from description import Description from workspaceObject import WorkspaceObject import formulas @@ -29,16 +27,6 @@ class Group(WorkspaceObject): self.descriptions = [] self.bondDescriptions = [] - self.extrinsicDescriptions = [] - self.outgoingBonds = [] - self.incomingBonds = [] - self.bonds = [] - self.leftBond = None - self.rightBond = None - self.correspondence = None - self.changed = False - self.newAnswerLetter = False - self.clampSalience = False self.name = '' if self.bondList and len(self.bondList): @@ -55,31 +43,26 @@ class Group(WorkspaceObject): letter = self.objectList[0].getDescriptor(self.facet) self.addDescription(self.facet, letter) if self.directionCategory: - self.addDescription(slipnet.directionCategory, - self.directionCategory) + self.addDescription(slipnet.directionCategory, self.directionCategory) if self.spansString(): self.addDescription(slipnet.stringPositionCategory, slipnet.whole) - elif self.leftIndex == 1: - self.addDescription( - slipnet.stringPositionCategory, slipnet.leftmost) - elif self.rightIndex == self.string.length: - self.addDescription( - slipnet.stringPositionCategory, slipnet.rightmost) + elif self.leftmost: + self.addDescription(slipnet.stringPositionCategory, slipnet.leftmost) + elif self.rightmost: + self.addDescription(slipnet.stringPositionCategory, slipnet.rightmost) elif self.middleObject(): - self.addDescription( - slipnet.stringPositionCategory, slipnet.middle) + self.addDescription(slipnet.stringPositionCategory, slipnet.middle) self.add_length_description_category() def add_length_description_category(self): - #check whether or not to add length description category + # check whether or not to add length description category random = self.ctx.random slipnet = self.ctx.slipnet probability = self.lengthDescriptionProbability() if random.coinFlip(probability): length = len(self.objectList) if length < 6: - self.addDescription(slipnet.length, - slipnet.numbers[length - 1]) + self.addDescription(slipnet.length, slipnet.numbers[length - 1]) def __str__(self): s = self.string.__str__() @@ -136,7 +119,6 @@ class Group(WorkspaceObject): def activateDescriptions(self): for description in self.descriptions: - logging.info('Activate: %s', description) description.descriptor.buffer = 100.0 def lengthDescriptionProbability(self): @@ -150,7 +132,7 @@ class Group(WorkspaceObject): probability = 0.5 ** fred value = temperature.getAdjustedProbability(probability) if value < 0.06: - value = 0.0 # otherwise 1/20 chance always + value = 0.0 return value def break_the_structure(self): @@ -214,12 +196,10 @@ class Group(WorkspaceObject): def numberOfLocalSupportingGroups(self): count = 0 for objekt in self.string.objects: - if isinstance(objekt, Group): - if (objekt.rightIndex < self.leftIndex or - objekt.leftIndex > self.rightIndex): - if (objekt.groupCategory == self.groupCategory and - objekt.directionCategory == self.directionCategory): - count += 1 + if isinstance(objekt, Group) and self.isOutsideOf(objekt): + if (objekt.groupCategory == self.groupCategory and + objekt.directionCategory == self.directionCategory): + count += 1 return count def localDensity(self): diff --git a/copycat/slipnet.py b/copycat/slipnet.py index 3478abf..5ed42f8 100644 --- a/copycat/slipnet.py +++ b/copycat/slipnet.py @@ -1,5 +1,3 @@ -import logging - from slipnode import Slipnode from sliplink import Sliplink @@ -12,7 +10,6 @@ class Slipnet(object): self.reset() def reset(self): - logging.debug('slipnet.reset()') self.numberOfUpdates = 0 for node in self.slipnodes: node.reset() @@ -20,7 +17,6 @@ class Slipnet(object): node.clampHigh() def update(self, random): - logging.debug('slipnet.update()') self.numberOfUpdates += 1 if self.numberOfUpdates == 50: for node in self.initiallyClampedSlipnodes: diff --git a/copycat/workspace.py b/copycat/workspace.py index 913ea56..5d414ca 100644 --- a/copycat/workspace.py +++ b/copycat/workspace.py @@ -1,5 +1,3 @@ -import logging - import formulas from bond import Bond from correspondence import Correspondence @@ -59,21 +57,24 @@ class Workspace(object): self.calculateTotalUnhappiness() def calculateIntraStringUnhappiness(self): - value = sum(o.relativeImportance * o.intraStringUnhappiness - for o in self.objects) / 2.0 + value = sum( + o.relativeImportance * o.intraStringUnhappiness + for o in self.objects + ) / 2.0 self.intraStringUnhappiness = min(value, 100.0) def calculateInterStringUnhappiness(self): - value = sum(o.relativeImportance * o.interStringUnhappiness - for o in self.objects) / 2.0 + value = sum( + o.relativeImportance * o.interStringUnhappiness + for o in self.objects + ) / 2.0 self.interStringUnhappiness = min(value, 100.0) def calculateTotalUnhappiness(self): - for o in self.objects: - logging.info("%s, totalUnhappiness: %d, relativeImportance: %d", - o, o.totalUnhappiness, o.relativeImportance * 1000) - value = sum(o.relativeImportance * o.totalUnhappiness - for o in self.objects) / 2.0 + value = sum( + o.relativeImportance * o.totalUnhappiness + for o in self.objects + ) / 2.0 self.totalUnhappiness = min(value, 100.0) def updateEverything(self): diff --git a/copycat/workspaceFormulas.py b/copycat/workspaceFormulas.py index 9c76474..b116db2 100644 --- a/copycat/workspaceFormulas.py +++ b/copycat/workspaceFormulas.py @@ -1,5 +1,3 @@ -import logging - def __chooseObjectFromList(ctx, objects, attribute): random = ctx.random @@ -16,8 +14,6 @@ def __chooseObjectFromList(ctx, objects, attribute): def chooseUnmodifiedObject(ctx, attribute, inObjects): workspace = ctx.workspace objects = [o for o in inObjects if o.string != workspace.modified] - if not objects: - logging.warning('no objects available in initial or target strings') return __chooseObjectFromList(ctx, objects, attribute) diff --git a/copycat/workspaceObject.py b/copycat/workspaceObject.py index 35f13c5..e0d0fdd 100644 --- a/copycat/workspaceObject.py +++ b/copycat/workspaceObject.py @@ -1,5 +1,3 @@ -import logging - from description import Description from formulas import weightedAverage from workspaceStructure import WorkspaceStructure @@ -11,19 +9,14 @@ class WorkspaceObject(WorkspaceStructure): WorkspaceStructure.__init__(self, workspaceString.ctx) self.string = workspaceString self.descriptions = [] - self.extrinsicDescriptions = [] - self.incomingBonds = [] - self.outgoingBonds = [] self.bonds = [] self.group = None - self.changed = None + self.changed = False self.correspondence = None - self.clampSalience = False self.rawImportance = 0.0 self.relativeImportance = 0.0 self.leftBond = None self.rightBond = None - self.newAnswerLetter = False self.name = '' self.replacement = None self.rightIndex = 0 @@ -45,19 +38,15 @@ class WorkspaceObject(WorkspaceStructure): def addDescription(self, descriptionType, descriptor): description = Description(self, descriptionType, descriptor) - logging.info("Adding description: %s to %s", description, self) self.descriptions += [description] def addDescriptions(self, descriptions): workspace = self.ctx.workspace copy = descriptions[:] # in case we add to our own descriptions for description in copy: - logging.info('might add: %s', description) if not self.containsDescription(description): self.addDescription(description.descriptionType, description.descriptor) - else: - logging.info("Won't add it") workspace.buildDescriptions(self) def __calculateIntraStringHappiness(self): @@ -97,26 +86,24 @@ class WorkspaceObject(WorkspaceStructure): averageHappiness = (intraStringHappiness + interStringHappiness) / 2 self.totalUnhappiness = 100.0 - averageHappiness - if self.clampSalience: - self.intraStringSalience = 100.0 - self.interStringSalience = 100.0 - else: - self.intraStringSalience = weightedAverage(( - (self.relativeImportance, 0.2), - (self.intraStringUnhappiness, 0.8))) - self.interStringSalience = weightedAverage(( - (self.relativeImportance, 0.8), - (self.interStringUnhappiness, 0.2))) - self.totalSalience = (self.intraStringSalience + - self.interStringSalience) / 2.0 - logging.info('Set salience of %s to %f = (%f + %f)/2', - self.__str__(), self.totalSalience, - self.intraStringSalience, self.interStringSalience) + self.intraStringSalience = weightedAverage(( + (self.relativeImportance, 0.2), + (self.intraStringUnhappiness, 0.8) + )) + self.interStringSalience = weightedAverage(( + (self.relativeImportance, 0.8), + (self.interStringUnhappiness, 0.2) + )) + self.totalSalience = (self.intraStringSalience + self.interStringSalience) / 2.0 def isWithin(self, other): return (self.leftIndex >= other.leftIndex and self.rightIndex <= other.rightIndex) + def isOutsideOf(self, other): + return (self.leftIndex > other.rightIndex or + self.rightIndex < other.leftIndex) + def relevantDescriptions(self): return [d for d in self.descriptions if d.descriptionType.fully_active()] @@ -124,7 +111,6 @@ class WorkspaceObject(WorkspaceStructure): def getPossibleDescriptions(self, descriptionType): from group import Group # gross, TODO FIXME slipnet = self.ctx.slipnet - logging.info('getting possible descriptions for %s', self) descriptions = [] for link in descriptionType.instanceLinks: node = link.destination @@ -138,10 +124,6 @@ class WorkspaceObject(WorkspaceStructure): descriptions += [node] if node == slipnet.middle and self.middleObject(): descriptions += [node] - s = '' - for d in descriptions: - s = '%s, %s' % (s, d.get_name()) - logging.info(s) return descriptions def containsDescription(self, sought): @@ -179,10 +161,7 @@ class WorkspaceObject(WorkspaceStructure): def getDescriptor(self, descriptionType): """The description attached to this object of the description type.""" - logging.info("\nIn %s, trying for type: %s", - self, descriptionType.get_name()) for description in self.descriptions: - logging.info("Trying description: %s", description) if description.descriptionType == descriptionType: return description.descriptor return None diff --git a/copycat/workspaceString.py b/copycat/workspaceString.py index a797a0b..1893f7f 100644 --- a/copycat/workspaceString.py +++ b/copycat/workspaceString.py @@ -1,4 +1,3 @@ -import logging from group import Group from letter import Letter @@ -32,19 +31,6 @@ class WorkspaceString(object): return '%s with %d letters, %d objects, %d bonds' % ( self.string, len(self.letters), len(self.objects), len(self.bonds)) - def log(self, heading): - s = '%s: %s - ' % (heading, self) - for l in self.letters: - s += ' %s' % l - s += '; ' - for o in self.objects: - s += ' %s' % o - s += '; ' - for b in self.bonds: - s += ' %s' % b - s += '.' - logging.info(s) - def __len__(self): return len(self.string) @@ -59,9 +45,6 @@ class WorkspaceString(object): o.relativeImportance = 0.0 else: for o in self.objects: - logging.info('object: %s, relative: %d = raw: %d / total: %d', - o, o.relativeImportance * 1000, o.rawImportance, - total) o.relativeImportance = o.rawImportance / total def updateIntraStringUnhappiness(self):