当前位置: 首页>>代码示例>>Python>>正文


Python Chainer.forward_step方法代码示例

本文整理汇总了Python中pln.chainers.Chainer.forward_step方法的典型用法代码示例。如果您正苦于以下问题:Python Chainer.forward_step方法的具体用法?Python Chainer.forward_step怎么用?Python Chainer.forward_step使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pln.chainers.Chainer的用法示例。


在下文中一共展示了Chainer.forward_step方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: InferenceAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class InferenceAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace, stimulateAtoms=False)

        # EvaluationToMember, MemberToInheritance
        self.chainer.add_rule(EvaluationToMemberRule(self.chainer))
        self.chainer.add_rule(MemberToEvaluationRule(self.chainer))
        self.chainer.add_rule(MemberToInheritanceRule(self.chainer))
        self.chainer.add_rule(InheritanceToMemberRule(self.chainer))

        # For predicates with 2 arguments,
        # with the 0th argument made into a variable
        self.chainer.add_rule(
            GeneralEvaluationToMemberRule(self.chainer, 0, 2))

        # ModusPonens:
        # Implication smokes(x) cancer(X)
        # smokes(Anna)
        # |= cancer(Anna)
        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()
        return result
开发者ID:BlastarIndia,项目名称:opencog,代码行数:34,代码来源:smokes_agent.py

示例2: SyllogismAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class SyllogismAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, local_atomspace):
        self.chainer = Chainer(
            local_atomspace,
            agent=self,
            stimulateAtoms=False,
            # can be set to True to use AA on syllogisms
            preferAttentionalFocus=False,
            allow_output_with_variables=True,
            delete_temporary_variables=True,
        )
        # add rules here
        # self.chainer.add_rule()

    def run(self, local_atomspace):
        if self.chainer is None:
            self.create_chainer(local_atomspace)
            print ("PLN Chainer created.")
            return

        print ("PLN continuing.")

        result = self.chainer.forward_step()
        return result
开发者ID:aro-ai-robots,项目名称:opencog,代码行数:29,代码来源:syllogism_r2l_pln_pipeline.py

示例3: DeductionAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class DeductionAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace, stimulateAtoms=False)

        link_types = [types.InheritanceLink]

        for link_type in link_types:
            self.chainer.add_rule(DeductionRule(self.chainer, link_type))

    def run(self, atomspace):
        # Run is invoked on every cogserver cognitive cycle
        # If it is the first time it has been invoked, then the chainer
        # needs to be created
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()

        if __VERBOSE__:
            print result

        return result

    def get_trails(self):
        return self.chainer.trails

    def get_history(self):
        return self.chainer.history.get_history()
开发者ID:AdolphLua,项目名称:opencog,代码行数:34,代码来源:deduction_agent.py

示例4: DeceptionAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class DeceptionAgent(MindAgent):
    def __init__(self):
        self.chainer = None
        print "Initialized DeceptionAgent."

    def create_chainer(self, atomspace, stimulate_atoms=False):
        self.chainer = Chainer(atomspace,
                               agent=self,
                               stimulateAtoms=stimulate_atoms,
                               allow_output_with_variables=False,
                               delete_temporary_variables=True)

        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()

        # if __VERBOSE__:
        #     print result

        return result

    def get_trails(self):
        return self.chainer.trails

    def get_history(self):
        return self.chainer.history.get_history()
开发者ID:dewadkar,项目名称:opencog,代码行数:34,代码来源:deception_agent.py

示例5: InferenceAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class InferenceAgent(MindAgent):
    def __init__(self):
        self.chainer = None
        print "Initializing InferenceAgent."

    def create_chainer(self, atomspace, stimulate_atoms=True):
        self.chainer = Chainer(atomspace,
                               agent=self,
                               stimulateAtoms=stimulate_atoms,
                               allow_output_with_variables=False,
                               preferAttentionalFocus=True,
                               delete_temporary_variables=True)

        # ModusPonens:
        # Implication smokes(x) cancer(X)
        # smokes(Anna)
        # |= cancer(Anna)
        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            print "PLN Chainer created."
            return

        print "PLN continuing."

        target = atomspace[scheme_eval_h(atomspace, "query")]

        if not check_result(atomspace):
            result = self.chainer.forward_step()
            self.chainer._give_stimulus(target, TARGET_STIMULUS)

            return result
开发者ID:HunterChen,项目名称:opencog,代码行数:37,代码来源:smokes_agent.py

示例6: SocratesAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class SocratesAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace,
                               #stimulates atoms (stimulus of 10 at the moment)
                               stimulateAtoms=True,
                               #agent selects atoms with higher stis
                               preferAttentionalFocus=False,
                               allow_output_with_variables=True,
                               delete_temporary_variables=True)

        self.chainer.add_rule(
            GeneralEvaluationToMemberRule(self.chainer, 0, 2))
        self.chainer.add_rule(MemberToInheritanceRule(self.chainer))
        self.chainer.add_rule(
            DeductionRule(self.chainer, types.InheritanceLink))
        self.chainer.add_rule(
            InheritanceToMemberRule(self.chainer))
        self.chainer.add_rule(
            MemberToEvaluationRule(self.chainer))
        self.chainer.add_rule(
            AbductionRule(self.chainer, types.InheritanceLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()
        return result
开发者ID:HunterChen,项目名称:opencog,代码行数:34,代码来源:socrates_agent.py

示例7: InferenceAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class InferenceAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace, stimulateAtoms=False)

        # Note:
        # The API for adding Rules and Links to a PLN Chainer is
        # hard to use. It could be redesigned so that you would
        # just pass a list of rule types and link types when you
        # instantiate the Chainer, without having to be aware of
        # the different sets of rules that require different
        # argument sets.

        for rule in RULES_CHAINER_LINKTYPE:
            for link_type in LINK_TYPES:
                print rule, link_type
                self.chainer.add_rule(rule(self.chainer, link_type))

        for rule in RULES_CHAINER:
            self.chainer.add_rule(rule(self.chainer))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()

        if __VERBOSE__:
            print result

        return result
开发者ID:Ferattie,项目名称:opencog,代码行数:36,代码来源:smokes_agent.py

示例8: ContextAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class ContextAgent(MindAgent):
    def __init__(self):
        self.chainer = None

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

        self.chainer.add_rule(InheritanceToContextRule(self.chainer))
        self.chainer.add_rule(EvaluationToContextRule(self.chainer))
        self.chainer.add_rule(SubsetToContextRule(self.chainer))
        self.chainer.add_rule(ContextToInheritanceRule(self.chainer))
        self.chainer.add_rule(ContextToEvaluationRule(self.chainer))
        self.chainer.add_rule(ContextToSubsetRule(self.chainer))
        self.chainer.add_rule(ContextFreeToSensitiveRule(self.chainer))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()
        return result
开发者ID:AdolphLua,项目名称:opencog,代码行数:28,代码来源:context_agent.py

示例9: EvaluationToMemberAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class EvaluationToMemberAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace,
                               stimulateAtoms=False,
                               allow_output_with_variables=True,
                               delete_temporary_variables=True)

        self.chainer.add_rule(
            GeneralEvaluationToMemberRule(self.chainer, 0, 2))
        self.chainer.add_rule(MemberToInheritanceRule(self.chainer))
        self.chainer.add_rule(
            DeductionRule(self.chainer, types.InheritanceLink))
        self.chainer.add_rule(
            InheritanceToMemberRule(self.chainer))
        self.chainer.add_rule(
            MemberToEvaluationRule(self.chainer))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()
        return result
开发者ID:edyirdaw,项目名称:opencog,代码行数:29,代码来源:evaluation_to_member_agent.py

示例10: InferenceAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class InferenceAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace, stimulate_atoms=True):
        self.chainer = Chainer(atomspace,
                               agent=self,
                               stimulateAtoms=stimulate_atoms,
                               allow_output_with_variables=False,
                               preferAttentionalFocus=True,
                               delete_temporary_variables=True)

        # ModusPonens:
        # Implication smokes(x) cancer(X)
        # smokes(Anna)
        # |= cancer(Anna)
        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        if not check_result(atomspace):
            result = self.chainer.forward_step()
            return result
开发者ID:Counterfly,项目名称:opencog,代码行数:29,代码来源:smokes_agent.py

示例11: InferenceAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class InferenceAgent(MindAgent):
    def __init__(self):
        self.chainer = None
        self.query = None
        print "Initializing InferenceAgent."

    def create_chainer(self, atomspace, stimulate_atoms=True):
        """
        Creates the chainer for the "smokes" example. Optionally, you can
         define the target query before calling this method, by defining a
         Scheme expression named "query". For example, you can issue the
         Scheme expression "(define query hasCancer)" in reference to the
         predicate defined in smokes.scm before loading this agent. Once
         defined, the target query will receive stimulus at every time step.
         Stimulus requires the agent to be running in a CogServer.
         For a complete example that incorporates this behavior, see
         example.py here:
           https://github.com/opencog/external-tools/tree/master/attention
        """
        self.chainer = Chainer(atomspace,
                               agent=self,
                               stimulateAtoms=stimulate_atoms,
                               allow_output_with_variables=False,
                               preferAttentionalFocus=True,
                               delete_temporary_variables=True)

        # ModusPonens:
        # Implication smokes(x) cancer(X)
        # smokes(Anna)
        # |= cancer(Anna)
        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

        # stimulateAtoms is only enabled when the agent is ran inside the
        # CogServer, since the functionality requires a CogServer and
        # attention allocation
        if self.chainer._stimulateAtoms:
            self.query = scheme_eval_h(atomspace, "query")

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            print "PLN Chainer created."
            return

        print "PLN continuing."

        if not check_result(atomspace):
            result = self.chainer.forward_step()

            if self.query is not None:
                self.chainer._give_stimulus(atomspace[self.query],
                                            TARGET_STIMULUS)

            return result
开发者ID:beefy,项目名称:opencog,代码行数:57,代码来源:smokes_agent.py

示例12: InferenceAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class InferenceAgent(MindAgent):
    def __init__(self):
        self.chainer = None
        self.antecedents = []

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace,
                               agent=self,
                               stimulateAtoms=True,
                               preferAttentionalFocus=True,
                               delete_temporary_variables=True,
                               allow_output_with_variables=True)

        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)

            implications = atomspace.get_atoms_by_type(types.ImplicationLink)
            for implication in implications:
                outgoing = atomspace.get_outgoing(implication.h)
                and_link = outgoing[0]
                self.antecedents.append(and_link)

            return

        # Run a forward step of the chainer with the ModusPonensRule so as to
        # perform inference using the "domain rules" defined as
        # ImplicationLinks
        self.chainer.forward_step()

        # Run a backward step of the chainer with the AndCreationRule for each
        # of the antecedents of the defined "domain rules" so as to
        # successfully ground the variables.
        for antecedent in self.antecedents:
            num_predicates = len(atomspace.get_outgoing(antecedent.h))
            self.chainer.backward_step(
                AndCreationRule(self.chainer, num_predicates), [antecedent])

        return
开发者ID:Alex-van-der-Peet,项目名称:opencog,代码行数:44,代码来源:class_agent.py

示例13: InferenceAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class InferenceAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace, stimulateAtoms=False)

        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()
        return result
开发者ID:JayTeeSF,项目名称:opencog,代码行数:19,代码来源:smokes_agent.py

示例14: TemporalAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class TemporalAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    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)

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()
        return result
开发者ID:Punxeh,项目名称:opencog,代码行数:23,代码来源:temporal_agent.py

示例15: EvaluationToMemberAgent

# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import forward_step [as 别名]
class EvaluationToMemberAgent(MindAgent):
    def __init__(self):
        self.chainer = None

    def create_chainer(self, atomspace):
        self.chainer = Chainer(atomspace, stimulateAtoms=False)

        # EvaluationToMemberRule only accepts predicates with 1 argument
        # For predicates with more arguments, GeneralEvaluationToMemberRule
        # is used.
        self.chainer.add_rule(
            GeneralEvaluationToMemberRule(self.chainer, 0, 2))
        self.chainer.add_rule(MemberToInheritanceRule(self.chainer))
        self.chainer.add_rule(
            DeductionRule(self.chainer, types.InheritanceLink))

    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            return

        result = self.chainer.forward_step()
        return result
开发者ID:BlastarIndia,项目名称:opencog,代码行数:25,代码来源:evaluation_to_member_agent.py


注:本文中的pln.chainers.Chainer.forward_step方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。