Further Pythonicity and flake8 cleanup. NFC.

This commit is contained in:
Arthur O'Dwyer
2017-04-16 02:40:55 -07:00
parent 31323cd2bc
commit 0ff9d49111
8 changed files with 25 additions and 28 deletions

View File

@ -710,7 +710,7 @@ def group_builder(codelet):
incompatible.break_the_structure() incompatible.break_the_structure()
# create new bonds # create new bonds
group.bondList = [] group.bondList = []
for i in range(1, len(group.objectList)): for i in xrange(1, len(group.objectList)):
#print 803 #print 803
object1 = group.objectList[i - 1] object1 = group.objectList[i - 1]
object2 = group.objectList[i] object2 = group.objectList[i]
@ -761,7 +761,7 @@ def __getCutOff(density):
distribution = [1.0, 1.0, 1.0, 2.0, 5.0, 150.0, 5.0, 2.0, 1.0, 1.0] distribution = [1.0, 1.0, 1.0, 2.0, 5.0, 150.0, 5.0, 2.0, 1.0, 1.0]
stop = sum(distribution) * random.random() stop = sum(distribution) * random.random()
total = 0.0 total = 0.0
for i in range(0, len(distribution)): for i in xrange(len(distribution)):
total += distribution[i] total += distribution[i]
if total >= stop: if total >= stop:
return i + 1 return i + 1

View File

@ -71,7 +71,7 @@ class CodeRack(object):
probability = workspaceFormulas.probabilityOfPosting( probability = workspaceFormulas.probabilityOfPosting(
codeletName) codeletName)
howMany = workspaceFormulas.howManyToPost(codeletName) howMany = workspaceFormulas.howManyToPost(codeletName)
for _ in range(0, howMany): for _ in xrange(howMany):
if random.random() >= probability: if random.random() >= probability:
continue continue
urgency = getUrgencyBin( urgency = getUrgencyBin(
@ -108,7 +108,7 @@ class CodeRack(object):
urgency = 1 urgency = 1
if formulas.Temperature < 25.0 and 'translator' in codeletName: if formulas.Temperature < 25.0 and 'translator' in codeletName:
urgency = 5 urgency = 5
for _ in range(0, howMany): for _ in xrange(howMany):
if random.random() < probability: if random.random() < probability:
codelet = Codelet(codeletName, urgency, self.codeletsRun) codelet = Codelet(codeletName, urgency, self.codeletsRun)
self.post(codelet) self.post(codelet)
@ -219,7 +219,7 @@ class CodeRack(object):
urgencies += [urgency] urgencies += [urgency]
threshold = random.random() * sum(urgencies) threshold = random.random() * sum(urgencies)
sumOfUrgencies = 0.0 sumOfUrgencies = 0.0
for i in range(0, len(self.codelets)): for i in xrange(len(self.codelets)):
sumOfUrgencies += urgencies[i] sumOfUrgencies += urgencies[i]
if sumOfUrgencies > threshold: if sumOfUrgencies > threshold:
return self.codelets[i] return self.codelets[i]
@ -227,11 +227,9 @@ class CodeRack(object):
def postInitialCodelets(self): def postInitialCodelets(self):
for name in self.initialCodeletNames: for name in self.initialCodeletNames:
for _ in range(0, workspaceFormulas.numberOfObjects()): for _ in xrange(2 * workspaceFormulas.numberOfObjects()):
codelet = Codelet(name, 1, self.codeletsRun) codelet = Codelet(name, 1, self.codeletsRun)
self.post(codelet) self.post(codelet)
codelet2 = Codelet(name, 1, self.codeletsRun)
self.post(codelet2)
def tryRun(self, newCodelet): def tryRun(self, newCodelet):
if self.removeTerracedScan: if self.removeTerracedScan:
@ -267,7 +265,8 @@ class CodeRack(object):
'bottom-up-correspondence-scout', 'bottom-up-correspondence-scout',
'important-object-correspondence-scout', 'important-object-correspondence-scout',
'correspondence-strength-tester', 'correspondence-strength-tester',
'correspondence-builder',) 'correspondence-builder',
)
self.methods = {} self.methods = {}
for codeletName in knownCodeletNames: for codeletName in knownCodeletNames:
methodName = re.sub('[ -]', '_', codeletName) methodName = re.sub('[ -]', '_', codeletName)
@ -352,4 +351,5 @@ class CodeRack(object):
except AssertionError: except AssertionError:
pass pass
coderack = CodeRack() coderack = CodeRack()

View File

@ -109,9 +109,8 @@ class Correspondence(WorkspaceStructure):
if self.objectFromTarget.spansString(): if self.objectFromTarget.spansString():
return 100.0 return 100.0
total = sum(c.totalStrength for c in workspace.correspondences() total = sum(c.totalStrength for c in workspace.correspondences()
if self.supporting(c)) if self.supporting(c))
total = min(total, 100.0) return min(total, 100.0)
return total
def updateInternalStrength(self): def updateInternalStrength(self):
"""A function of how many concept mappings there are """A function of how many concept mappings there are
@ -144,8 +143,8 @@ class Correspondence(WorkspaceStructure):
def internallyCoherent(self): def internallyCoherent(self):
"""Whether any pair of distinguishing mappings support each other""" """Whether any pair of distinguishing mappings support each other"""
mappings = self.relevantDistinguishingConceptMappings() mappings = self.relevantDistinguishingConceptMappings()
for i in range(0, len(mappings)): for i in xrange(len(mappings)):
for j in range(0, len(mappings)): for j in xrange(len(mappings)):
if i != j: if i != j:
if mappings[i].supports(mappings[j]): if mappings[i].supports(mappings[j]):
return True return True

View File

@ -12,4 +12,5 @@ class GroupRun(object):
self.modified = workspace.modified self.modified = workspace.modified
self.target = workspace.target self.target = workspace.target
groupRun = GroupRun() groupRun = GroupRun()

View File

@ -10,9 +10,8 @@ def distinguishingDescriptor(descriptor):
return False return False
if descriptor == slipnet.group: if descriptor == slipnet.group:
return False return False
for number in slipnet.numbers: if descriptor in slipnet.numbers:
if number == descriptor: return False
return False
return True return True
@ -43,8 +42,8 @@ class SlipNet(object):
self.numberOfUpdates = 0 self.numberOfUpdates = 0
for node in self.slipnodes: for node in self.slipnodes:
node.reset() node.reset()
if node in self.initiallyClampedSlipnodes: for node in self.initiallyClampedSlipnodes:
node.clampHigh() node.clampHigh()
def update(self): def update(self):
logging.debug('slipnet.update()') logging.debug('slipnet.update()')
@ -279,4 +278,5 @@ class SlipNet(object):
self.__addNonSlipLink(item, previous, label=self.predecessor) self.__addNonSlipLink(item, previous, label=self.predecessor)
previous = item previous = item
slipnet = SlipNet() slipnet = SlipNet()

View File

@ -1,6 +1,6 @@
import math import math
import logging import logging
from random import random import random
def full_activation(): def full_activation():
@ -11,11 +11,6 @@ def jump_threshold():
return 55.0 return 55.0
def points_at(links, other):
"""Whether any of the links points at the other"""
return any(l.points_at(other) for l in links)
class Slipnode(object): class Slipnode(object):
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
def __init__(self, name, depth, length=0.0): def __init__(self, name, depth, length=0.0):
@ -95,11 +90,11 @@ class Slipnode(object):
def linked(self, other): def linked(self, other):
"""Whether the other is among the outgoing links""" """Whether the other is among the outgoing links"""
return points_at(self.outgoingLinks, other) return any(l.points_at(other) for l in self.outgoingLinks)
def slipLinked(self, other): def slipLinked(self, other):
"""Whether the other is among the lateral links""" """Whether the other is among the lateral links"""
return points_at(self.lateralSlipLinks, other) return any(l.points_at(other) for l in self.lateralSlipLinks)
def related(self, other): def related(self, other):
"""Same or linked""" """Same or linked"""
@ -163,7 +158,7 @@ class Slipnode(object):
if self.clamped: if self.clamped:
return False return False
value = (self.activation / 100.0) ** 3 value = (self.activation / 100.0) ** 3
return random() < value return random.random() < value
def jump(self): def jump(self):
if self.can_jump(): if self.can_jump():

View File

@ -21,4 +21,5 @@ class Temperature(object):
def log(self): def log(self):
logging.debug('temperature.value: %f', self.value) logging.debug('temperature.value: %f', self.value)
temperature = Temperature() temperature = Temperature()

View File

@ -33,6 +33,7 @@ class WorkspaceFormulas(object):
formulas.Temperature = formulas.actualTemperature formulas.Temperature = formulas.actualTemperature
temperature.update(formulas.Temperature) temperature.update(formulas.Temperature)
workspaceFormulas = WorkspaceFormulas() workspaceFormulas = WorkspaceFormulas()