def extract_cover(self, label, model): """ Extracts a resulting DS from a model returned by a SAT oracle. """ for j in range(1, self.nof_terms + 1): premise = [] for r in range(1, self.nof_feats + 1): if model[self.pvar(j, r) - 1] < 0: id_orig = self.ffmap.opp[r - 1] premise.append(id_orig) elif model[self.nvar(j, r) - 1] < 0: id_orig = self.ffmap.opp[r - 1] premise.append(-id_orig) # creating the rule rule = Rule(fvars=premise, label=label, mapping=self.data.fvmap) if self.options.verb: print('c1 cover:', str(rule)) self.covrs[label].append(rule) self.cost += len(rule) return self.covrs
def extract_cover(self, label, model): """ Extracts a resulting DS from a model returned by a SAT oracle. """ premise = [] for j in range(1, self.nof_lits + 1): for r in range(1, self.nof_feats + 2): if model[self.feat(j, r)] > 0: if model[self.leaf(j)] > 0: # creating the rule rule = Rule(fvars=premise, label=label, mapping=self.data.fvmap) self.covrs[label].append(rule) self.cost += len(rule) if self.options.verb: print('c1 cover:', str(rule)) premise = [] else: id_orig = self.ffmap.opp[r - 1] if model[self.sign(j)] * id_orig > 0: premise.append(id_orig) else: premise.append(-id_orig) return self.covrs
def extract_cover(self, model): """ Extracts a resulting DS from a model returned by a SAT oracle. """ for j in range(1, self.nof_terms + 1): premise = [] for r in range(1, self.nof_feats + 1): if model[self.dvar0(j, r) - 1] > 0: id_orig = self.ffmap.opp[r - 1] premise.append(id_orig) elif model[self.dvar1(j, r) - 1] > 0: id_orig = self.ffmap.opp[r - 1] premise.append(-id_orig) if self.nof_labls == 2: label = self.labels[0 if model[self.cvar(j, 1) - 1] > 0 else 1] else: for z, lb in enumerate(self.labels, 1): if model[self.cvar(j, z) - 1] > 0: label = lb break else: assert False, 'No class label found in the model' # creating the rule rule = Rule(fvars=premise, label=label, mapping=self.data.fvmap) if self.options.verb: print('c1 cover:', str(rule)) self.covrs[label].append(rule) self.cost += len(rule) return self.covrs
def process_mcs(self, mcs): """ Extract a rule from MCS. """ # getting the corresponding variables rule = Rule(fvars=[self.drvmap[i] for i in mcs], label=self.target, mapping=self.data.fvmap) # printing rule if self.options.verb > 1: if self.options.verb > 2: print('c1 mcs: {0}'.format(' '.join([str(l) for l in mcs]))) return rule