def vector_smooth(self): edges = ss.compute_edges(self.net, self.vld) snl = [n for n in self.net.pot if n.is_sum()] cnl = [n for n in self.net.pot if n.is_categorical()] for sn in snl: vw = np.bincount(edges[sn], minlength=len(sn.weights)).astype(np.float) if vw.sum() == 0: continue vw /= vw.sum() w = calculate_weights( np.array(sn.weights), vw ) sn.set_weights(w) for cn in cnl: vm = np.bincount(edges[cn], minlength=len(cn.masses)).astype(np.float) if vm.sum() == 0: continue vm /= vm.sum() m = calculate_weights( np.array(cn.masses), vm ) cn.set_masses(m)
def smart_smooth(self, verbose=False): edges = ss.compute_edges(self.net, self.vld) pn_scores = sorted( [(ss.compute_score_of(pn, edges),pn) for pn in self.net.pot if pn.is_prod()] ) for s,pn in pn_scores: nodes = pn.children self.smooth_nodes(nodes, verbose)