def _get_id_stats(glyphs, k=None): import stats if len(glyphs) < 3: return (len(glyphs), 1.0, 1.0, 1.0) if k is None: k = knncore.kNN() distances = k.unique_distances(glyphs) return (len(glyphs), stats.lmean(distances), stats.lstdev(distances), stats.lmedian(distances))
def get_glyphs_stats(glyphs): k = knncore.kNN() klasses = {} for x in glyphs: id = x.get_main_id() if not klasses.has_key(id): klasses[id] = [] klasses[id].append(x) stats = {} for x in klasses.iteritems(): stats[x[0]] = _get_id_stats(x[1], k) return stats