Further Pythonicity and flake8 cleanup. NFC.
This commit is contained in:
@ -710,7 +710,7 @@ def group_builder(codelet):
|
||||
incompatible.break_the_structure()
|
||||
# create new bonds
|
||||
group.bondList = []
|
||||
for i in range(1, len(group.objectList)):
|
||||
for i in xrange(1, len(group.objectList)):
|
||||
#print 803
|
||||
object1 = group.objectList[i - 1]
|
||||
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]
|
||||
stop = sum(distribution) * random.random()
|
||||
total = 0.0
|
||||
for i in range(0, len(distribution)):
|
||||
for i in xrange(len(distribution)):
|
||||
total += distribution[i]
|
||||
if total >= stop:
|
||||
return i + 1
|
||||
|
||||
@ -71,7 +71,7 @@ class CodeRack(object):
|
||||
probability = workspaceFormulas.probabilityOfPosting(
|
||||
codeletName)
|
||||
howMany = workspaceFormulas.howManyToPost(codeletName)
|
||||
for _ in range(0, howMany):
|
||||
for _ in xrange(howMany):
|
||||
if random.random() >= probability:
|
||||
continue
|
||||
urgency = getUrgencyBin(
|
||||
@ -108,7 +108,7 @@ class CodeRack(object):
|
||||
urgency = 1
|
||||
if formulas.Temperature < 25.0 and 'translator' in codeletName:
|
||||
urgency = 5
|
||||
for _ in range(0, howMany):
|
||||
for _ in xrange(howMany):
|
||||
if random.random() < probability:
|
||||
codelet = Codelet(codeletName, urgency, self.codeletsRun)
|
||||
self.post(codelet)
|
||||
@ -219,7 +219,7 @@ class CodeRack(object):
|
||||
urgencies += [urgency]
|
||||
threshold = random.random() * sum(urgencies)
|
||||
sumOfUrgencies = 0.0
|
||||
for i in range(0, len(self.codelets)):
|
||||
for i in xrange(len(self.codelets)):
|
||||
sumOfUrgencies += urgencies[i]
|
||||
if sumOfUrgencies > threshold:
|
||||
return self.codelets[i]
|
||||
@ -227,11 +227,9 @@ class CodeRack(object):
|
||||
|
||||
def postInitialCodelets(self):
|
||||
for name in self.initialCodeletNames:
|
||||
for _ in range(0, workspaceFormulas.numberOfObjects()):
|
||||
for _ in xrange(2 * workspaceFormulas.numberOfObjects()):
|
||||
codelet = Codelet(name, 1, self.codeletsRun)
|
||||
self.post(codelet)
|
||||
codelet2 = Codelet(name, 1, self.codeletsRun)
|
||||
self.post(codelet2)
|
||||
|
||||
def tryRun(self, newCodelet):
|
||||
if self.removeTerracedScan:
|
||||
@ -267,7 +265,8 @@ class CodeRack(object):
|
||||
'bottom-up-correspondence-scout',
|
||||
'important-object-correspondence-scout',
|
||||
'correspondence-strength-tester',
|
||||
'correspondence-builder',)
|
||||
'correspondence-builder',
|
||||
)
|
||||
self.methods = {}
|
||||
for codeletName in knownCodeletNames:
|
||||
methodName = re.sub('[ -]', '_', codeletName)
|
||||
@ -352,4 +351,5 @@ class CodeRack(object):
|
||||
except AssertionError:
|
||||
pass
|
||||
|
||||
|
||||
coderack = CodeRack()
|
||||
|
||||
@ -109,9 +109,8 @@ class Correspondence(WorkspaceStructure):
|
||||
if self.objectFromTarget.spansString():
|
||||
return 100.0
|
||||
total = sum(c.totalStrength for c in workspace.correspondences()
|
||||
if self.supporting(c))
|
||||
total = min(total, 100.0)
|
||||
return total
|
||||
if self.supporting(c))
|
||||
return min(total, 100.0)
|
||||
|
||||
def updateInternalStrength(self):
|
||||
"""A function of how many concept mappings there are
|
||||
@ -144,8 +143,8 @@ class Correspondence(WorkspaceStructure):
|
||||
def internallyCoherent(self):
|
||||
"""Whether any pair of distinguishing mappings support each other"""
|
||||
mappings = self.relevantDistinguishingConceptMappings()
|
||||
for i in range(0, len(mappings)):
|
||||
for j in range(0, len(mappings)):
|
||||
for i in xrange(len(mappings)):
|
||||
for j in xrange(len(mappings)):
|
||||
if i != j:
|
||||
if mappings[i].supports(mappings[j]):
|
||||
return True
|
||||
|
||||
@ -12,4 +12,5 @@ class GroupRun(object):
|
||||
self.modified = workspace.modified
|
||||
self.target = workspace.target
|
||||
|
||||
|
||||
groupRun = GroupRun()
|
||||
|
||||
@ -10,9 +10,8 @@ def distinguishingDescriptor(descriptor):
|
||||
return False
|
||||
if descriptor == slipnet.group:
|
||||
return False
|
||||
for number in slipnet.numbers:
|
||||
if number == descriptor:
|
||||
return False
|
||||
if descriptor in slipnet.numbers:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@ -43,8 +42,8 @@ class SlipNet(object):
|
||||
self.numberOfUpdates = 0
|
||||
for node in self.slipnodes:
|
||||
node.reset()
|
||||
if node in self.initiallyClampedSlipnodes:
|
||||
node.clampHigh()
|
||||
for node in self.initiallyClampedSlipnodes:
|
||||
node.clampHigh()
|
||||
|
||||
def update(self):
|
||||
logging.debug('slipnet.update()')
|
||||
@ -279,4 +278,5 @@ class SlipNet(object):
|
||||
self.__addNonSlipLink(item, previous, label=self.predecessor)
|
||||
previous = item
|
||||
|
||||
|
||||
slipnet = SlipNet()
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import math
|
||||
import logging
|
||||
from random import random
|
||||
import random
|
||||
|
||||
|
||||
def full_activation():
|
||||
@ -11,11 +11,6 @@ def jump_threshold():
|
||||
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):
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
def __init__(self, name, depth, length=0.0):
|
||||
@ -95,11 +90,11 @@ class Slipnode(object):
|
||||
|
||||
def linked(self, other):
|
||||
"""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):
|
||||
"""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):
|
||||
"""Same or linked"""
|
||||
@ -163,7 +158,7 @@ class Slipnode(object):
|
||||
if self.clamped:
|
||||
return False
|
||||
value = (self.activation / 100.0) ** 3
|
||||
return random() < value
|
||||
return random.random() < value
|
||||
|
||||
def jump(self):
|
||||
if self.can_jump():
|
||||
|
||||
@ -21,4 +21,5 @@ class Temperature(object):
|
||||
def log(self):
|
||||
logging.debug('temperature.value: %f', self.value)
|
||||
|
||||
|
||||
temperature = Temperature()
|
||||
|
||||
@ -33,6 +33,7 @@ class WorkspaceFormulas(object):
|
||||
formulas.Temperature = formulas.actualTemperature
|
||||
temperature.update(formulas.Temperature)
|
||||
|
||||
|
||||
workspaceFormulas = WorkspaceFormulas()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user