def __init__(self, mrf, simplify=False, unsatfailure=False, formulas=None, cache=None, **params): DefaultGroundingFactory.__init__(self, mrf, simplify=simplify, unsatfailure=unsatfailure, formulas=formulas, cache=cache, **params)
def _compute_statistics(self): self._stat = [] grounder = DefaultGroundingFactory(self.mrf) eworld = list(self.mrf.evidence) if self.verbose: bar = ProgressBar(width=100, steps=self.mrf.countworlds(), color='green') for widx, world in self.mrf.iterallworlds(): if self.verbose: bar.label(str(widx)) bar.inc() values = {} self._stat.append(values) if self._eworld_idx is None and world == eworld: self._eworld_idx = widx for gf in grounder.itergroundings(): truth = gf(world) if truth != 0: values[gf.idx] = values.get(gf.idx, 0) + truth
def _compute_statistics(self): ''' computes the statistics upon which the optimization is based ''' self._stat = {} self._varidx2fidx = defaultdict(set) grounder = DefaultGroundingFactory(self.mrf, simplify=False, unsatfailure=True, verbose=self.verbose, cache=0) for f in grounder.itergroundings(): for gndatom in f.gndatoms(): var = self.mrf.variable(gndatom) with temporary_evidence(self.mrf): for validx, value in var.itervalues(): var.setval(value, self.mrf.evidence) truth = f(self.mrf.evidence) if truth != 0: self._varidx2fidx[var.idx].add(f.idx) self._addstat(f.idx, var.idx, validx, truth)