Fix more flake8 cruft; remove a bunch of logging.
This commit is contained in:
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user