Remove all print statements from the Copycat library.
Convert the most important one to logging; kill the rest.
This commit is contained in:
@ -35,7 +35,7 @@ def __showWhichStringObjectIsFrom(structure):
|
||||
whence = 'target'
|
||||
if structure.string == workspace.initial:
|
||||
whence = 'initial'
|
||||
#print 'object chosen = %s from %s string' % (structure, whence)
|
||||
logging.info('object chosen = %s from %s string' % (structure, whence))
|
||||
|
||||
|
||||
def __getScoutSource(ctx, slipnode, relevanceMethod, typeName):
|
||||
@ -740,7 +740,6 @@ def group_builder(ctx, codelet):
|
||||
workspace = ctx.workspace
|
||||
# update strength value of the group
|
||||
group = codelet.arguments[0]
|
||||
#print '%s' % group
|
||||
__showWhichStringObjectIsFrom(group)
|
||||
equivalent = group.string.equivalentGroup(group)
|
||||
if equivalent:
|
||||
@ -756,7 +755,6 @@ def group_builder(ctx, codelet):
|
||||
if len(group.objectList) > 1:
|
||||
previous = group.objectList[0]
|
||||
for objekt in group.objectList[1:]:
|
||||
#print 770
|
||||
leftBond = objekt.leftBond
|
||||
if leftBond:
|
||||
if leftBond.leftObject == previous:
|
||||
@ -787,7 +785,6 @@ def group_builder(ctx, codelet):
|
||||
# create new bonds
|
||||
group.bondList = []
|
||||
for i in xrange(1, len(group.objectList)):
|
||||
#print 803
|
||||
object1 = group.objectList[i - 1]
|
||||
object2 = group.objectList[i]
|
||||
if not object1.rightBond:
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
from coderack import Coderack
|
||||
from randomness import Randomness
|
||||
from slipnet import Slipnet
|
||||
@ -5,7 +7,11 @@ from temperature import Temperature
|
||||
from workspace import Workspace
|
||||
|
||||
|
||||
class CopycatReporter(object):
|
||||
class Reporter(object):
|
||||
"""Do-nothing base class for defining new reporter types"""
|
||||
def report_answer(self, answer):
|
||||
pass
|
||||
|
||||
def report_coderack(self, coderack):
|
||||
pass
|
||||
|
||||
@ -23,7 +29,7 @@ class Copycat(object):
|
||||
self.slipnet = Slipnet()
|
||||
self.temperature = Temperature()
|
||||
self.workspace = Workspace(self)
|
||||
self.reporter = reporter or CopycatReporter()
|
||||
self.reporter = reporter or Reporter()
|
||||
|
||||
def mainLoop(self, lastUpdate):
|
||||
currentTime = self.coderack.codeletsRun
|
||||
@ -56,11 +62,20 @@ class Copycat(object):
|
||||
answer = None
|
||||
finalTemperature = self.temperature.last_unclamped_value
|
||||
finalTime = self.coderack.codeletsRun
|
||||
print 'Answered %s (time %d, final temperature %.1f)' % (answer, finalTime, finalTemperature)
|
||||
answers[answer] = answers.get(answer, {'count': 0, 'tempsum': 0, 'timesum': 0})
|
||||
answers[answer]['count'] += 1
|
||||
answers[answer]['tempsum'] += finalTemperature
|
||||
answers[answer]['timesum'] += finalTime
|
||||
logging.info('Answered %s (time %d, final temperature %.1f)' % (answer, finalTime, finalTemperature))
|
||||
self.reporter.report_answer({
|
||||
'answer': answer,
|
||||
'temp': finalTemperature,
|
||||
'time': finalTime,
|
||||
})
|
||||
d = answers.setdefault(answer, {
|
||||
'count': 0,
|
||||
'sumtemp': 0,
|
||||
'sumtime': 0
|
||||
})
|
||||
d['count'] += 1
|
||||
d['sumtemp'] += finalTemperature
|
||||
d['sumtime'] += finalTime
|
||||
|
||||
def run(self, initial, modified, target, iterations):
|
||||
self.workspace.resetWithStrings(initial, modified, target)
|
||||
@ -68,6 +83,6 @@ class Copycat(object):
|
||||
for i in xrange(iterations):
|
||||
self.runTrial(answers)
|
||||
for answer, d in answers.iteritems():
|
||||
d['avgtemp'] = d.pop('tempsum') / d['count']
|
||||
d['avgtime'] = d.pop('timesum') / d['count']
|
||||
d['avgtemp'] = d.pop('sumtemp') / d['count']
|
||||
d['avgtime'] = d.pop('sumtime') / d['count']
|
||||
return answers
|
||||
|
||||
@ -98,15 +98,10 @@ class Workspace(object):
|
||||
"""A list of all objects in the workspace with >= 1 open bond slots"""
|
||||
objects = [o for o in self.objects
|
||||
if o.string == self.initial or o.string == self.target]
|
||||
#print 'A: %d' % len(objects)
|
||||
objects = [o for o in objects if not o.spansString()]
|
||||
#print 'B: %d' % len(objects)
|
||||
objects = [o for o in objects
|
||||
if (not o.leftBond and not o.leftmost) or
|
||||
(not o.rightBond and not o.rightmost)]
|
||||
#print 'C: %d' % len(objects)
|
||||
#objects = [ o for o in objects if ]
|
||||
#print 'D: %d' % len(objects)
|
||||
return len(objects)
|
||||
|
||||
def numberOfUngroupedObjects(self):
|
||||
@ -118,14 +113,14 @@ class Workspace(object):
|
||||
return len(objects)
|
||||
|
||||
def numberOfUnreplacedObjects(self):
|
||||
"""A list of all unreplaced objects in the inital string"""
|
||||
"""A list of all unreplaced objects in the initial string"""
|
||||
objects = [o for o in self.objects
|
||||
if o.string == self.initial and isinstance(o, Letter)]
|
||||
objects = [o for o in objects if not o.replacement]
|
||||
return len(objects)
|
||||
|
||||
def numberOfUncorrespondingObjects(self):
|
||||
"""A list of all uncorresponded objects in the inital string"""
|
||||
"""A list of all uncorresponded objects in the initial string"""
|
||||
objects = [o for o in self.objects
|
||||
if o.string == self.initial or o.string == self.target]
|
||||
objects = [o for o in objects if not o.correspondence]
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import logging
|
||||
|
||||
def __chooseObjectFromList(ctx, objects, attribute):
|
||||
random = ctx.random
|
||||
@ -14,8 +15,8 @@ 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 len(objects):
|
||||
print 'no objects available in initial or target strings'
|
||||
if not objects:
|
||||
logging.warning('no objects available in initial or target strings')
|
||||
return __chooseObjectFromList(ctx, objects, attribute)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user