From 52d81872ab391c87b5d925fe1774ed3892526082 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Tue, 19 Apr 2016 12:05:30 +0200 Subject: Naive VR implementation for internal use. --- phstuff/simplicial.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/phstuff/simplicial.py b/phstuff/simplicial.py index 884a543..6614bf7 100644 --- a/phstuff/simplicial.py +++ b/phstuff/simplicial.py @@ -1,3 +1,6 @@ +import numpy as np +import itertools + class Node: def __init__(self, x, i, w, parent): self.x = x @@ -132,13 +135,36 @@ class Complex: return parent.children.setdefault(last, node) - def __contains__(self, simplex): return self.find(simplex) is not None def __iter__(self): return ComplexIterator(self.__root) + def __len__(self): + return self.__count - +# Very naive temporary VR implementations. +def naive_vr_tmp(graph, top_dim): + assert(graph.shape[0] == graph.shape[1]) + + vertex_set = np.arange(0, graph.shape[0]) + cplx = Complex() + for p in range(0, top_dim): + to_add = itertools.combinations(vertex_set, p+1) + if p == 0: + for v in vertex_set: + cplx.add([v], 0.0) + elif p == 1: + for simplex in to_add: + cplx.add(simplex, graph[simplex[0], simplex[1]]) + else: + for simplex in to_add: + codim1faces = itertools.combinations(simplex, p) + weight = 0.0 + for face in codim1faces: + weight = max(cplx.find(face).w, weight) + cplx.add(simplex, weight) + + return cplx -- cgit v1.2.3