Beispiel #1
0
 def __init__(self, mrf, queries=ALL, state=None, **params):
     MCMCInference.__init__(self, mrf, queries, **params)
     if state is None:
         self.state = self.random_world(self.mrf.evidence)
     else:
         self.state = state
     self.sum = 0
     self.var2gf = defaultdict(set)
     self.weights = list(self.mrf.mln.weights)
     formulas = []
     for f in self.mrf.formulas:
         if f.weight < 0:
             f_ = self.mrf.mln.logic.negate(f)
             f_.weight = -f.weight
             formulas.append(f_.nnf())
     grounder = FastConjunctionGrounding(mrf,
                                         formulas=formulas,
                                         simplify=True,
                                         unsatfailure=True)
     for gf in grounder.itergroundings():
         if isinstance(gf, Logic.TrueFalse): continue
         vars_ = set(map(lambda a: self.mrf.variable(a).idx, gf.gndatoms()))
         for v in vars_:
             self.var2gf[v].add(gf)
         self.sum += (self.hardw if gf.weight == HARD else
                      gf.weight) * (1 - gf(self.state))
Beispiel #2
0
 def __init__(self, mrf, queries=ALL, **params):
     MCMCInference.__init__(self, mrf, queries, **params)
     self.var2gf = defaultdict(set)
     grounder = FastConjunctionGrounding(mrf, simplify=True, unsatfailure=True, cache=None)
     for gf in grounder.itergroundings():
         if isinstance(gf, Logic.TrueFalse): continue
         vars_ = set(map(lambda a: self.mrf.variable(a).idx, gf.gndatoms()))
         for v in vars_: self.var2gf[v].add(gf)
Beispiel #3
0
 def __init__(self, mrf, queries=ALL, **params):
     MCMCInference.__init__(self, mrf, queries, **params)
     self.var2gf = defaultdict(set)
     grounder = FastConjunctionGrounding(mrf, simplify=True, unsatfailure=True, cache=None)
     for gf in grounder.itergroundings():
         if isinstance(gf, Logic.TrueFalse): continue
         vars_ = set(map(lambda a: self.mrf.variable(a).idx, gf.gndatoms()))
         for v in vars_: self.var2gf[v].add(gf)
Beispiel #4
0
 def __init__(self, mrf, queries=ALL, state=None, **params):
     MCMCInference.__init__(self, mrf, queries, **params)
     if state is None:
         self.state = self.random_world(self.mrf.evidence)
     else:
         self.state = state
     self.sum = 0
     self.var2gf = defaultdict(set)
     self.weights = list(self.mrf.mln.weights)
     formulas = []
     for f in self.mrf.formulas:
         if f.weight < 0:
             f_ = self.mrf.mln.logic.negate(f)
             f_.weight = - f.weight
             formulas.append(f_.nnf())
     grounder = FastConjunctionGrounding(mrf, formulas=formulas, simplify=True, unsatfailure=True)
     for gf in grounder.itergroundings():
         if isinstance(gf, Logic.TrueFalse): continue
         vars_ = set(map(lambda a: self.mrf.variable(a).idx, gf.gndatoms()))
         for v in vars_: self.var2gf[v].add(gf)
         self.sum += (self.hardw if gf.weight == HARD else gf.weight) * (1 - gf(self.state))
Beispiel #5
0
 def __init__(self, mrf, queries=ALL, **params):
     MCMCInference.__init__(self, mrf, queries, **params)
     self._weight_backup = list(self.mrf.mln.weights)
Beispiel #6
0
 def __init__(self, mrf, queries=ALL, **params):
     MCMCInference.__init__(self, mrf, queries, **params)
     self._weight_backup = list(self.mrf.mln.weights)