def B_using_tree_l2c(leaf2clusters, bonding_calc = lambda common_path_fraction: common_path_fraction): """Generates bonding matrix for given tree. leaf2clusters - tree given as a dictionary {leaf: descending-list-of-clusters} bonding_calc(common_path_fraction) - returns bonding value """ B = [] #print "[B_using_tree_l2c] Considering:",leaf2clusters max_levels = trees.tree_depth(leaf2clusters) logging.info("[B_using_tree_l2c] max_levels="+str(max_levels)) for lix,leaf in enumerate(sorted(leaf2clusters)): leaf_path = leaf2clusters[leaf]+[lix] #append leaf_no to path bv = [] #bonding vector for lix2,leaf2 in enumerate(sorted(leaf2clusters)): leaf2_path = leaf2clusters[leaf2]+[lix2] #append leaf_no to path common_levels = calc_common_levels(leaf_path, leaf2_path) #common_path_fraction = float(common_levels) / max_levels #common_path_fraction = 0.5*(float(common_levels) / len(leaf_path) + float(common_levels) / len(leaf2_path)) #common_path_fraction = max(float(common_levels) / len(leaf_path) , float(common_levels) / len(leaf2_path)) common_path_fraction = min(float(common_levels) / len(leaf_path) , float(common_levels) / len(leaf2_path)) bv.append(bonding_calc(common_path_fraction)) #print "leaf_path, leaf2_path =",leaf_path, leaf2_path,"->",bonding_calc(common_path_fraction) B.append(bv) return B
def find_regions(self, root): data_regions = [] if tree_depth(root) >= 2: scores = self.compare_generalized_nodes(root, self.max_generalized_nodes) data_regions.extend(self.identify_regions(0, root, self.max_generalized_nodes, self.threshold, scores)) covered = set() for data_region in data_regions: for i in xrange(data_region.start, data_region.covered): covered.add(data_region.parent[i]) for child in root: if child not in covered: data_regions.extend(self.find_regions(child)) return data_regions