Beispiel #1
0
    def construct_simplices(self, points, labels, epsilon, distfcn):
        delaunay = Delaunay(points)
        delaunay_simplices = map(tuple, delaunay.simplices)
        distdict = self.calculate_distmatrix(points, labels, distfcn)

        simplices = []
        for simplex in delaunay_simplices:
            faces = list(facesiter(simplex))
            detached = map(
                partial(contain_detachededges,
                        distdict=distdict,
                        epsilon=epsilon), faces)
            if reduce(or_, detached):
                if len(simplex) > 2:
                    for face, notkeep in zip(faces, detached):
                        if not notkeep:
                            simplices.append(face)
            else:
                simplices.append(simplex)
        simplices = map(lambda simplex: tuple(sorted(simplex)), simplices)
        simplices = list(set(simplices))

        allpts = get_allpoints(simplices)
        for point in (set(labels) - allpts):
            simplices += [(point, )]

        return simplices
Beispiel #2
0
def contain_detachededges(simplex, distdict, epsilon):
    if len(simplex) == 2:
        return (distdict[simplex[0], simplex[1]] > 2 * epsilon)
    else:
        return reduce(
            or_,
            map(
                partial(contain_detachededges,
                        distdict=distdict,
                        epsilon=epsilon), facesiter(simplex)))
Beispiel #3
0
    def construct_simplices(self, points, labels, epsilon, distfcn):
        delaunay = Delaunay(points)
        delaunay_simplices = map(tuple, delaunay.simplices)
        distdict = self.calculate_distmatrix(points, labels, distfcn)

        simplices = []
        for simplex in delaunay_simplices:
            faces = list(facesiter(simplex))
            detached = map(partial(contain_detachededges, distdict=distdict, epsilon=epsilon), faces)
            if reduce(or_, detached):
                if len(simplex)>2:
                    for face, notkeep in zip(faces, detached):
                        if not notkeep:
                            simplices.append(face)
            else:
                simplices.append(simplex)
        simplices = map(lambda simplex: tuple(sorted(simplex)), simplices)
        simplices = list(set(simplices))

        allpts = get_allpoints(simplices)
        for point in (set(labels)-allpts):
            simplices += [(point,)]

        return simplices
Beispiel #4
0
def contain_detachededges(simplex, distdict, epsilon):
    if len(simplex)==2:
        return (distdict[simplex[0], simplex[1]] > 2*epsilon)
    else:
        return reduce(or_, map(partial(contain_detachededges, distdict=distdict, epsilon=epsilon), facesiter(simplex)))