Example #1
0
 def compile(self,mode,depth=0):
     """ Produce an ops.Function object which implements the predicate definition
     """
     #find the rules which define this predicate/function
     
     if depth>MAXDEPTH:
         nullFun = bpcompiler.buildNullFunction(mode)
         self.function[(mode,depth)] = nullFun
     else:
         predDef = self.findPredDef(mode)
         if len(predDef)==0:
             assert False,'no rules match mode %s' % mode
         elif len(predDef)==1:
             #instead of a sum of one function, just find the function
             #for this single predicate
             c = bpcompiler.BPCompiler(self,depth,predDef[0])
             #print '= calling bp.compile',mode,'depth',depth
             c.compile(mode)
             self.function[(mode,depth)] = ops.OpFunction(c.getInputs(), c.getOutputs(), ops.SeqOp(c.getOps()))            
         else:
             #compute a function that will sum up the values of the
             #clauses
             ruleFuns = []
             for r in predDef:
                 c = bpcompiler.BPCompiler(self,depth,r)
                 c.compile(mode)
                 ruleFuns.append( ops.OpFunction(c.getInputs(),c.getOutputs(),ops.SeqOp(c.getOps())) )
             self.function[(mode,depth)] = ops.SumFunction(ruleFuns)
     return self.function[(mode,depth)]
Example #2
0
    def compile(self, mode, depth=0):
        """ Produce an ops.Function object which implements the predicate definition
        """
        #find the rules which define this predicate/function

        if depth > MAXDEPTH:
            nullFun = bpcompiler.buildNullFunction(mode)
            self.function[(mode, depth)] = nullFun
        else:
            predDef = self.findPredDef(mode)
            if len(predDef) == 0:
                assert False, 'no rules match mode %s' % mode
            elif len(predDef) == 1:
                #instead of a sum of one function, just find the function
                #for this single predicate
                c = bpcompiler.BPCompiler(self, depth, predDef[0])
                #print '= calling bp.compile',mode,'depth',depth
                c.compile(mode)
                self.function[(mode, depth)] = ops.OpFunction(
                    c.getInputs(), c.getOutputs(), ops.SeqOp(c.getOps()))
            else:
                #compute a function that will sum up the values of the
                #clauses
                ruleFuns = []
                for r in predDef:
                    c = bpcompiler.BPCompiler(self, depth, r)
                    c.compile(mode)
                    ruleFuns.append(
                        ops.OpFunction(c.getInputs(), c.getOutputs(),
                                       ops.SeqOp(c.getOps())))
                self.function[(mode, depth)] = ops.SumFunction(ruleFuns)
        return self.function[(mode, depth)]
Example #3
0
 def compile(self,mode,depth=0):
     """ Produce an ops.Function object which implements the predicate definition
     """
     if depth>MAXDEPTH:
         nullFun = bpcompiler.buildNullFunction(mode)
         self.function[(mode,depth)] = nullFun
     else:
         predDef = self.findPredDef(mode)
         assert predDef,'no rules match mode %s' % mode
         # We need to adjust the function appropriately for each
         # rule r, using the special WeightedSumFunction which
         # takes two parallel lists of functions and accumulates
         # them appropriately.
         ruleFuns = []
         featureFuns = []
         for r in predDef:
             cr = bpcompiler.BPCompiler(self,depth,r)
             cr.compile(mode)
             ruleFuns.append( ops.OpFunction(cr.getInputs(),cr.getOutputs(),ops.SeqOp(cr.getOps())) )
             g = self._featureGenerator(r,mode)
             cg = bpcompiler.BPCompiler(self,depth,g)
             cg.compile(mode)
             featureFuns.append( ops.OpFunction(cg.getInputs(),cg.getOutputs(),ops.SeqOp(cg.getOps())) )
         self.function[(mode,depth)] = ops.WeightedSumFunction(self.weights,ruleFuns,featureFuns)
     return self.function[(mode,depth)]
Example #4
0
 def compile(self, mode, depth=0):
     """ Produce an ops.Function object which implements the predicate definition
     """
     if depth > MAXDEPTH:
         nullFun = bpcompiler.buildNullFunction(mode)
         self.function[(mode, depth)] = nullFun
     else:
         predDef = self.findPredDef(mode)
         assert predDef, 'no rules match mode %s' % mode
         # We need to adjust the function appropriately for each
         # rule r, using the special WeightedSumFunction which
         # takes two parallel lists of functions and accumulates
         # them appropriately.
         ruleFuns = []
         featureFuns = []
         for r in predDef:
             cr = bpcompiler.BPCompiler(self, depth, r)
             cr.compile(mode)
             ruleFuns.append(
                 ops.OpFunction(cr.getInputs(), cr.getOutputs(),
                                ops.SeqOp(cr.getOps())))
             g = self._featureGenerator(r, mode)
             cg = bpcompiler.BPCompiler(self, depth, g)
             cg.compile(mode)
             featureFuns.append(
                 ops.OpFunction(cg.getInputs(), cg.getOutputs(),
                                ops.SeqOp(cg.getOps())))
         self.function[(mode, depth)] = ops.WeightedSumFunction(
             self.weights, ruleFuns, featureFuns)
     return self.function[(mode, depth)]