Preparing for refactor

This commit is contained in:
Alexandre Linhares
2017-09-27 20:00:02 -03:00
parent 120aa3a293
commit a564e43dff
2 changed files with 57964 additions and 175306 deletions

233203
copycat.log

File diff suppressed because it is too large Load Diff

View File

@ -75,10 +75,10 @@ def __structureVsStructure(structure1, weight1, structure2, weight2):
temperature = ctx.temperature
structure1.updateStrength()
structure2.updateStrength()
#TODO: use entropy
# TODO: use entropy
weightedStrength1 = temperature.getAdjustedValue(
structure1.totalStrength * weight1)
#TODO: use entropy
# TODO: use entropy
weightedStrength2 = temperature.getAdjustedValue(
structure2.totalStrength * weight2)
return random.weighted_greater_than(weightedStrength1, weightedStrength2)
@ -114,7 +114,7 @@ def __slippability(ctx, conceptMappings):
temperature = ctx.temperature
for mapping in conceptMappings:
slippiness = mapping.slippability() / 100.0
#TODO: use entropy
# TODO: use entropy
probabilityOfSlippage = temperature.getAdjustedProbability(slippiness)
if random.coinFlip(probabilityOfSlippage):
return True
@ -126,7 +126,7 @@ def breaker(ctx, codelet):
random = ctx.random
temperature = ctx.temperature
workspace = ctx.workspace
#TODO: use entropy
# TODO: use entropy
probabilityOfFizzle = (100.0 - temperature.value()) / 100.0
if random.coinFlip(probabilityOfFizzle):
return
@ -143,7 +143,7 @@ def breaker(ctx, codelet):
breakObjects += [structure.source.group]
# Break all the objects or none of them; this matches the Java
for structure in breakObjects:
#TODO: use entropy
# TODO: use entropy
breakProbability = temperature.getAdjustedProbability(
structure.totalStrength / 100.0)
if random.coinFlip(breakProbability):
@ -155,8 +155,7 @@ def breaker(ctx, codelet):
def chooseRelevantDescriptionByActivation(ctx, workspaceObject):
random = ctx.random
descriptions = workspaceObject.relevantDescriptions()
weights = [description.descriptor.activation
for description in descriptions]
weights = [description.descriptor.activation for description in descriptions]
return random.weighted_choice(descriptions, weights)
@ -166,7 +165,7 @@ def similarPropertyLinks(ctx, slip_node):
result = []
for slip_link in slip_node.propertyLinks:
association = slip_link.degreeOfAssociation() / 100.0
#TODO:use entropy
# TODO:use entropy
probability = temperature.getAdjustedProbability(association)
if random.coinFlip(probability):
result += [slip_link]
@ -189,7 +188,7 @@ def bottom_up_description_scout(ctx, codelet):
sliplinks = similarPropertyLinks(ctx, description.descriptor)
assert sliplinks
weights = [sliplink.degreeOfAssociation() * sliplink.destination.activation
for sliplink in sliplinks]
for sliplink in sliplinks]
chosen = random.weighted_choice(sliplinks, weights)
chosenProperty = chosen.destination
coderack.proposeDescription(chosenObject, chosenProperty.category(),
@ -222,7 +221,7 @@ def description_strength_tester(ctx, codelet):
description.descriptor.buffer = 100.0
description.updateStrength()
strength = description.totalStrength
#TODO: use entropy
# TODO: use entropy
probability = temperature.getAdjustedProbability(strength / 100.0)
assert random.coinFlip(probability)
coderack.newCodelet('description-builder', strength, [description])
@ -306,7 +305,7 @@ def rule_scout(ctx, codelet):
workspace = ctx.workspace
assert workspace.numberOfUnreplacedObjects() == 0
changedObjects = [o for o in workspace.initial.objects if o.changed]
#assert len(changedObjects) < 2
# assert len(changedObjects) < 2
# if there are no changed objects, propose a rule with no changes
if not changedObjects:
return coderack.proposeRule(None, None, None, None)
@ -336,8 +335,8 @@ def rule_scout(ctx, codelet):
if targetObject.described(node):
if targetObject.distinguishingDescriptor(node):
newList += [node]
objectList = newList # surely this should be +=
# "union of this and distinguishing descriptors"
objectList = newList # surely this should be +=
# "union of this and distinguishing descriptors"
assert objectList
# use conceptual depth to choose a description
weights = [
@ -368,7 +367,7 @@ def rule_strength_tester(ctx, codelet):
temperature = ctx.temperature
rule = codelet.arguments[0]
rule.updateStrength()
#TODO: use entropy
# TODO: use entropy
probability = temperature.getAdjustedProbability(rule.totalStrength / 100.0)
if random.coinFlip(probability):
coderack.newCodelet('rule-builder', rule.totalStrength, [rule])
@ -401,8 +400,8 @@ def replacement_finder(ctx, codelet):
relation = relations[diff]
else:
relation = None
letterOfInitialString.replacement = Replacement(ctx,
letterOfInitialString, letterOfModifiedString, relation)
letterOfInitialString.replacement = Replacement(ctx, letterOfInitialString,
letterOfModifiedString, relation)
if relation != slipnet.sameness:
letterOfInitialString.changed = True
workspace.changedObject = letterOfInitialString
@ -445,8 +444,8 @@ def top_down_bond_scout__direction(ctx, codelet):
coderack = ctx.coderack
slipnet = ctx.slipnet
direction = codelet.arguments[0]
source = __getScoutSource(ctx,
direction, formulas.localDirectionCategoryRelevance, 'bond')
source = __getScoutSource(ctx, direction, formulas.localDirectionCategoryRelevance,
'bond')
destination = chooseDirectedNeighbor(ctx, source, direction)
assert destination
logging.info('to object: %s', destination)
@ -471,7 +470,7 @@ def bond_strength_tester(ctx, codelet):
__showWhichStringObjectIsFrom(bond)
bond.updateStrength()
strength = bond.totalStrength
#Todo: use entropy
# TODO: use entropy
probability = temperature.getAdjustedProbability(strength / 100.0)
logging.info('bond strength = %d for %s', strength, bond)
assert random.coinFlip(probability)
@ -512,7 +511,7 @@ def bond_builder(ctx, codelet):
if incompatibleCorrespondences:
logging.info("trying to break incompatible correspondences")
assert __fight(bond, 2.0, incompatibleCorrespondences, 3.0)
#assert __fightIncompatibles(incompatibleCorrespondences,
# assert __fightIncompatibles(incompatibleCorrespondences,
# bond, 'correspondences', 2.0, 3.0)
for incompatible in incompatibleBonds:
incompatible.break_the_structure()
@ -702,7 +701,7 @@ def top_down_group_scout__direction(ctx, codelet):
direction, bondFacet)
#noinspection PyStringFormat
# noinspection PyStringFormat
@codelet('group-scout--whole-string')
def group_scout__whole_string(ctx, codelet):
coderack = ctx.coderack
@ -754,7 +753,7 @@ def group_strength_tester(ctx, codelet):
__showWhichStringObjectIsFrom(group)
group.updateStrength()
strength = group.totalStrength
#TODO: use entropy
# TODO: use entropy
probability = temperature.getAdjustedProbability(strength / 100.0)
if random.coinFlip(probability):
# it is strong enough - post builder & activate nodes
@ -882,7 +881,7 @@ def rule_translator(ctx, codelet):
bondDensity = min(bondDensity, 1.0)
weights = __getCutoffWeights(bondDensity)
cutoff = 10.0 * random.weighted_choice(list(range(1, 11)), weights)
#TODO: use entropy
# TODO: use entropy
if cutoff >= temperature.actual_value:
result = workspace.rule.buildTranslatedRule()
if result is not None:
@ -919,11 +918,11 @@ def bottom_up_correspondence_scout(ctx, codelet):
and m.initialDescriptionType != slipnet.bondFacet]
initialDescriptionTypes = [m.initialDescriptionType for m in opposites]
flipTargetObject = False
if (objectFromInitial.spansString() and
objectFromTarget.spansString() and
slipnet.directionCategory in initialDescriptionTypes
and all(m.label == slipnet.opposite for m in opposites) # unreached?
and slipnet.opposite.activation != 100.0):
if (objectFromInitial.spansString() and
objectFromTarget.spansString() and
slipnet.directionCategory in initialDescriptionTypes
and all(m.label == slipnet.opposite for m in opposites) # unreached?
and slipnet.opposite.activation != 100.0):
objectFromTarget = objectFromTarget.flippedVersion()
conceptMappings = formulas.getMappings(
objectFromInitial, objectFromTarget,
@ -939,7 +938,7 @@ def important_object_correspondence_scout(ctx, codelet):
coderack = ctx.coderack
random = ctx.random
slipnet = ctx.slipnet
#TODO: use entropy
# TODO: use entropy
temperature = ctx.temperature
workspace = ctx.workspace
objectFromInitial = chooseUnmodifiedObject(ctx, 'relativeImportance',
@ -979,11 +978,11 @@ def important_object_correspondence_scout(ctx, codelet):
and m.initialDescriptionType != slipnet.bondFacet]
initialDescriptionTypes = [m.initialDescriptionType for m in opposites]
flipTargetObject = False
if (objectFromInitial.spansString()
and objectFromTarget.spansString()
and slipnet.directionCategory in initialDescriptionTypes
and all(m.label == slipnet.opposite for m in opposites) # unreached?
and slipnet.opposite.activation != 100.0):
if (objectFromInitial.spansString()
and objectFromTarget.spansString()
and slipnet.directionCategory in initialDescriptionTypes
and all(m.label == slipnet.opposite for m in opposites) # unreached?
and slipnet.opposite.activation != 100.0):
objectFromTarget = objectFromTarget.flippedVersion()
conceptMappings = formulas.getMappings(
objectFromInitial, objectFromTarget,