Example #1
0
    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace,
                               stimulateAtoms=False,
                               preferAttentionalFocus=False,
                               allow_output_with_variables=True,
                               delete_temporary_variables=True)

        for rule in create_temporal_rules(self.chainer):
            self.chainer.add_rule(rule)
Example #2
0
    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace,
                               stimulateAtoms=False,
                               agent=self,
                               learnRuleFrequencies=True)

        # ImplicationLink is MixedImplicationLink, you could also have Extensional and Intensional Implication. etc. but that's a bit much.
        #        similarity_types = [types.SimilarityLink, types.ExtensionalSimilarityLink, types.IntensionalSimilarityLink]
        #            types.EquivalenceLink]
        #        conditional_probability_types = [types.InheritanceLink, types.SubsetLink, types.IntensionalInheritanceLink, types.ImplicationLink]

        # always use the mixed inheritance types, because human inference is normally a mix of intensional and extensional
        conditional_probability_types = [
            types.InheritanceLink, types.ImplicationLink
        ]
        similarity_types = [types.SimilarityLink, types.EquivalenceLink]

        for link_type in conditional_probability_types:
            self.chainer.add_rule(rules.InversionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type))
            self.chainer.add_rule(
                rules.ModusPonensRule(self.chainer, link_type))

        # As a hack, use the standard DeductionRule for SimilarityLinks. It needs its own formula really.
        for link_type in similarity_types:
            self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type))

        # These two Rules create mixed links out of intensional and extensional links
        self.chainer.add_rule(rules.InheritanceRule(self.chainer))
        self.chainer.add_rule(rules.SimilarityRule(self.chainer))

        # and/or/not
        self.chainer.add_rule(rules.NotCreationRule(self.chainer))
        self.chainer.add_rule(rules.NotEliminationRule(self.chainer))
        for rule in rules.create_and_or_rules(self.chainer, 1, 2):
            self.chainer.add_rule(rule)

        # create probabilistic logical links out of MemberLinks
        self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer))
        self.chainer.add_rule(
            rules.IntensionalInheritanceEvaluationRule(self.chainer))

        self.chainer.add_rule(
            rules.ExtensionalSimilarityEvaluationRule(self.chainer))
        self.chainer.add_rule(
            rules.IntensionalSimilarityEvaluationRule(self.chainer))

        self.chainer.add_rule(rules.EvaluationToMemberRule(self.chainer))
        self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer))

        # AttractionLink could be useful for causality
        self.chainer.add_rule(rules.AttractionRule(self.chainer))

        for rule in temporal_rules.create_temporal_rules(self.chainer):
            self.chainer.add_rule(rule)
Example #3
0
    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace, stimulateAtoms = False, agent = self, learnRuleFrequencies=True)

        # ImplicationLink is MixedImplicationLink, you could also have Extensional and Intensional Implication. etc. but that's a bit much.
#        similarity_types = [types.SimilarityLink, types.ExtensionalSimilarityLink, types.IntensionalSimilarityLink]
#            types.EquivalenceLink]
#        conditional_probability_types = [types.InheritanceLink, types.SubsetLink, types.IntensionalInheritanceLink, types.ImplicationLink]

        # always use the mixed inheritance types, because human inference is normally a mix of intensional and extensional
        conditional_probability_types = [types.InheritanceLink, types.ImplicationLink]
        similarity_types = [types.SimilarityLink, types.EquivalenceLink]

        for link_type in conditional_probability_types:
            self.chainer.add_rule(rules.InversionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.ModusPonensRule(self.chainer, link_type))

        # As a hack, use the standard DeductionRule for SimilarityLinks. It needs its own formula really.
        for link_type in similarity_types:
            self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type))

        # These two Rules create mixed links out of intensional and extensional links
        self.chainer.add_rule(rules.InheritanceRule(self.chainer))
        self.chainer.add_rule(rules.SimilarityRule(self.chainer))

        # and/or/not
        self.chainer.add_rule(rules.NotCreationRule(self.chainer))
        self.chainer.add_rule(rules.NotEliminationRule(self.chainer))
        for rule in rules.create_and_or_rules(self.chainer, 1, 2):
            self.chainer.add_rule(rule)

        # create probabilistic logical links out of MemberLinks
        self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.IntensionalInheritanceEvaluationRule(self.chainer))

        self.chainer.add_rule(rules.ExtensionalSimilarityEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.IntensionalSimilarityEvaluationRule(self.chainer))

        self.chainer.add_rule(rules.EvaluationToMemberRule(self.chainer))
        self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer))

        # AttractionLink could be useful for causality
        self.chainer.add_rule(rules.AttractionRule(self.chainer))

        for rule in temporal_rules.create_temporal_rules(self.chainer):
            self.chainer.add_rule(rule)
Example #4
0
timeLinks = "opencog/spacetime/spacetime_types.scm"
data = "tests/python/test_pln/scm_disabled/temporal/temporalToyExample.scm"
# data = "opencog/python/pln_old/examples/temporal/temporal-r2l-input.scm"

# initialize atomspace
atomspace = AtomSpace()
__init__(atomspace)
for item in [coreTypes, utilities, timeLinks, data]:
    load_scm(atomspace, item)

# initialize chainer
chainer = Chainer(atomspace,
                  stimulateAtoms=False,
                  allow_output_with_variables=True,
                  delete_temporary_variables=True)
for rule in create_temporal_rules(chainer):
    chainer.add_rule(rule)

if print_starting_contents:
    print('AtomSpace starting contents:')
    atomspace.print_list()

outputs_produced = 0

for i in range(0, num_steps):
    result = chainer.forward_step()

    output = None
    input = None
    rule = None
    if result is not None:
Example #5
0
    def __init__(self, atomspace, chainer):
        from pln.rules import rules, temporal_rules, boolean_rules, quantifier_rules, context_rules, predicate_rules

        # contains every rule
        self.chainer = Chainer(atomspace, stimulateAtoms = False, agent = self, learnRuleFrequencies=False)
        # contains only some rules
        self.test_chainer = chainer

        conditional_probability_types = [types.InheritanceLink, types.ImplicationLink, types.PredictiveImplicationLink]
        similarity_types = [types.SimilarityLink, types.EquivalenceLink]

        for link_type in conditional_probability_types:
            self.chainer.add_rule(rules.InversionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.InductionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.AbductionRule(self.chainer, link_type))
            # Seems better than Modus Ponens - it doesn't make anything up
            self.chainer.add_rule(rules.TermProbabilityRule(self.chainer, link_type))
            self.chainer.add_rule(rules.ModusPonensRule(self.chainer, link_type))

        for link_type in similarity_types:
            # SimilarityLinks don't require an InversionRule obviously
            self.chainer.add_rule(rules.TransitiveSimilarityRule(self.chainer, link_type))
            self.chainer.add_rule(rules.SymmetricModusPonensRule(self.chainer, link_type))

        self.chainer.add_rule(predicate_rules.EvaluationImplicationRule(self.chainer))

        # These two Rules create mixed links out of intensional and extensional links
        self.chainer.add_rule(rules.InheritanceRule(self.chainer))
        self.chainer.add_rule(rules.SimilarityRule(self.chainer))

        # boolean links
        for rule in boolean_rules.create_and_or_rules(self.chainer, 2, 8):
            self.chainer.add_rule(rule)

        # create probabilistic logical links out of MemberLinks

        self.chainer.add_rule(rules.AndEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.OrEvaluationRule(self.chainer))

        self.chainer.add_rule(rules.ExtensionalLinkEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.IntensionalLinkEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.NegatedSubsetEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.ExtensionalSimilarityEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.IntensionalInheritanceEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.IntensionalSimilarityEvaluationRule(self.chainer))

        self.member_rules = [rules.EvaluationToMemberRule(self.chainer),
            rules.MemberToEvaluationRule(self.chainer)]
        self.member_rules += rules.create_general_evaluation_to_member_rules(self.chainer)
        for rule in self.member_rules:
            self.chainer.add_rule(rule)

        # It's important to have both of these
        self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer))
#        self.chainer.add_rule(rules.InheritanceToMemberRule(self.chainer))

        # AttractionLink could be useful for causality
        self.chainer.add_rule(rules.AttractionRule(self.chainer))

        self.chainer.add_rule(quantifier_rules.ScholemRule(self.chainer))

        for rule in temporal_rules.create_temporal_rules(self.chainer):
            self.chainer.add_rule(rule)
Example #6
0
    def __init__(self, atomspace, chainer):
        from pln.rules import rules, temporal_rules, boolean_rules, quantifier_rules, context_rules, predicate_rules

        # contains every rule
        self.chainer = Chainer(atomspace,
                               stimulateAtoms=False,
                               agent=self,
                               learnRuleFrequencies=False)
        # contains only some rules
        self.test_chainer = chainer

        conditional_probability_types = [
            types.InheritanceLink, types.ImplicationLink,
            types.PredictiveImplicationLink
        ]
        similarity_types = [types.SimilarityLink, types.EquivalenceLink]

        for link_type in conditional_probability_types:
            self.chainer.add_rule(rules.InversionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.InductionRule(self.chainer, link_type))
            self.chainer.add_rule(rules.AbductionRule(self.chainer, link_type))
            # Seems better than Modus Ponens - it doesn't make anything up
            self.chainer.add_rule(
                rules.TermProbabilityRule(self.chainer, link_type))
            self.chainer.add_rule(
                rules.ModusPonensRule(self.chainer, link_type))

        for link_type in similarity_types:
            # SimilarityLinks don't require an InversionRule obviously
            self.chainer.add_rule(
                rules.TransitiveSimilarityRule(self.chainer, link_type))
            self.chainer.add_rule(
                rules.SymmetricModusPonensRule(self.chainer, link_type))

        self.chainer.add_rule(
            predicate_rules.EvaluationImplicationRule(self.chainer))

        # These two Rules create mixed links out of intensional and extensional links
        self.chainer.add_rule(rules.InheritanceRule(self.chainer))
        self.chainer.add_rule(rules.SimilarityRule(self.chainer))

        # boolean links
        for rule in boolean_rules.create_and_or_rules(self.chainer, 2, 8):
            self.chainer.add_rule(rule)

        # create probabilistic logical links out of MemberLinks

        self.chainer.add_rule(rules.AndEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.OrEvaluationRule(self.chainer))

        self.chainer.add_rule(rules.ExtensionalLinkEvaluationRule(
            self.chainer))
        self.chainer.add_rule(rules.IntensionalLinkEvaluationRule(
            self.chainer))
        self.chainer.add_rule(rules.SubsetEvaluationRule(self.chainer))
        self.chainer.add_rule(rules.NegatedSubsetEvaluationRule(self.chainer))
        self.chainer.add_rule(
            rules.ExtensionalSimilarityEvaluationRule(self.chainer))
        self.chainer.add_rule(
            rules.IntensionalInheritanceEvaluationRule(self.chainer))
        self.chainer.add_rule(
            rules.IntensionalSimilarityEvaluationRule(self.chainer))

        self.member_rules = [
            rules.EvaluationToMemberRule(self.chainer),
            rules.MemberToEvaluationRule(self.chainer)
        ]
        self.member_rules += rules.create_general_evaluation_to_member_rules(
            self.chainer)
        for rule in self.member_rules:
            self.chainer.add_rule(rule)

        # It's important to have both of these
        self.chainer.add_rule(rules.MemberToInheritanceRule(self.chainer))
        #        self.chainer.add_rule(rules.InheritanceToMemberRule(self.chainer))

        # AttractionLink could be useful for causality
        self.chainer.add_rule(rules.AttractionRule(self.chainer))

        self.chainer.add_rule(quantifier_rules.ScholemRule(self.chainer))

        for rule in temporal_rules.create_temporal_rules(self.chainer):
            self.chainer.add_rule(rule)