def strip_small_categories(glyphs): gc = knn.glyphs_by_category(glyphs) new_glyphs = [] for v in gc.itervalues(): if len(v) > 3: new_glyphs.extend(v) return new_glyphs
def strip_small_categories(glyphs): gc = knn.glyphs_by_category(glyphs) new_glyphs = [] for v in gc.values(): if len(v) > 3: new_glyphs.extend(v) return new_glyphs
def get_graph_stats(glyphs, k): s = { } gc = knn.glyphs_by_category(glyphs) for x in gc.itervalues(): if len(x) == 1: s[x[0].get_main_id()] = 1.0 continue graph = cluster.make_spanning_tree(x, k) edges = [] for edge in graph.get_edges(): edges.append(edge.cost) id = x[0].get_main_id() s[id] = stats.mean(edges) #cluster.make_subtrees_stddev(graph, 1, 2, 0) #print graph.nedges, len(x) return s
def get_graph_stats(glyphs, k): s = {} gc = knn.glyphs_by_category(glyphs) for x in gc.values(): if len(x) == 1: s[x[0].get_main_id()] = 1.0 continue graph = cluster.make_spanning_tree(x, k) edges = [] for edge in graph.get_edges(): edges.append(edge.cost) id = x[0].get_main_id() s[id] = stats.mean(edges) #cluster.make_subtrees_stddev(graph, 1, 2, 0) #print graph.nedges, len(x) return s
def cluster2(glyphs): ko = knn.kNNInterative() gc = knn.glyphs_by_category(cluster(glyphs, k=ko)) small = [] large = [] for x in gc.itervalues(): if len(x) < 10: small.extend(x) else: large.append(x) print len(small) output = cluster(small, 1, 1, label="cluster_small.", k=ko) cur_label = 0 for x in large: l = x[0].get_main_id() + ".cluster_large" + str(cur_label) + "." cur_label += 1 c = cluster(x, .6, 4, label=l, k=ko) output.extend(c) return output