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