def create_temporal_rules(chainer): rules = [] # directly evaluate temporal links combinations = [ (types.BeforeLink, temporal_formulas.beforeFormula), (types.OverlapsLink, temporal_formulas.overlapsFormula), (types.DuringLink, temporal_formulas.duringFormula), (types.MeetsLink, temporal_formulas.meetsFormula), (types.StartsLink, temporal_formulas.startsFormula), (types.FinishesLink, temporal_formulas.finishesFormula), (types.EqualsLink, temporal_formulas.equalsFormula), ] for (type, formula) in combinations: rules.append(TemporalRule(chainer, type, formula)) for type, _ in combinations: # use temporal links to evaluate more temporal links rules.append(TemporalTransitivityRule(chainer, type)) # Use the wrong formula to predict events #rules.append(ModusPonensRule(chainer, types.BeforeLink)) #rules.append(PredictiveAttractionRule(chainer)) return rules
def make_symmetric_rule(lhs, rhs): rule = Rule(inputs=lhs, outputs=rhs, formula=formulas.identityFormula) rule.name = 'BooleanTransformationRule' rules.append(rule) rule = Rule(inputs=rhs, outputs=lhs, formula=formulas.identityFormula) rule.name = 'BooleanTransformationRule' rules.append(rule)
def make_symmetric_rule(lhs, rhs): rule = Rule(inputs=lhs, outputs=rhs, formula=formulas.identityFormula) rule.name = 'BooleanTransformationRule' rules.append(rule) rule = Rule(inputs=rhs, outputs=lhs, formula=formulas.identityFormula) rule.name = 'BooleanTransformationRule' rules.append(rule)
def embodied_inference(self, sample_count=1000): '''Do the series of inferences that is typically useful for embodied inference. Create a variety of MemberLinks from EvaluationLinks, and then use those to derive SubsetLinks, and use those to derive IntensionalInheritanceLinks, and use those to derive (Mixed)InheritanceLinks, then use those InheritanceLinks to find lots of InheritanceLinks. The reason to do it in this order is that doing the later stages first, you would find few results''' # Store those rules, in that order rules=[] rules+= self.member_rules rules.append(self.chainer.lookup_rule("ExtensionalLinkEvaluationRule")) rules.append(self.chainer.lookup_rule("AttractionRule")) rules.append(self.chainer.lookup_rule("IntensionalLinkEvaluationRule")) rules.append(self.chainer.lookup_rule("InheritanceRule")) for rule in rules: self.chainer.update_all_node_probabilities() if len(rule._inputs) == 1: self.chainer.apply_bulk(rule=rule) else: for i in xrange(0, sample_count): self.chainer.forward_step(rule=rule)
def embodied_inference(self, sample_count=1000): '''Do the series of inferences that is typically useful for embodied inference. Create a variety of MemberLinks from EvaluationLinks, and then use those to derive SubsetLinks, and use those to derive IntensionalInheritanceLinks, and use those to derive (Mixed)InheritanceLinks, then use those InheritanceLinks to find lots of InheritanceLinks. The reason to do it in this order is that doing the later stages first, you would find few results''' # Store those rules, in that order rules = [] rules += self.member_rules rules.append(self.chainer.lookup_rule("ExtensionalLinkEvaluationRule")) rules.append(self.chainer.lookup_rule("AttractionRule")) rules.append(self.chainer.lookup_rule("IntensionalLinkEvaluationRule")) rules.append(self.chainer.lookup_rule("InheritanceRule")) for rule in rules: self.chainer.update_all_node_probabilities() if len(rule._inputs) == 1: self.chainer.apply_bulk(rule=rule) else: for i in xrange(0, sample_count): self.chainer.forward_step(rule=rule)
def create_and_or_rules(chainer, min_n, max_n): rules = [] for n in min_n, max_n: rules.append(AndCreationRule(chainer, n)) rules.append(OrCreationRule(chainer, n)) rules.append(AndEliminationRule(chainer, n)) rules.append(OrEliminationRule(chainer, n)) rules.append(AndBreakdownRule(chainer)) rules.append(OrBreakdownRule(chainer)) rules.append(NotCreationRule(chainer)) rules.append(NotEliminationRule(chainer)) return rules
def create_and_or_rules(chainer, min_n, max_n): rules = [] for n in min_n, max_n: rules.append(AndCreationRule(chainer, n)) rules.append(OrCreationRule(chainer, n)) rules.append(AndEliminationRule(chainer, n)) rules.append(OrEliminationRule(chainer, n)) rules.append(AndBreakdownRule(chainer)) rules.append(OrBreakdownRule(chainer)) rules.append(NotCreationRule(chainer)) rules.append(NotEliminationRule(chainer)) return rules