summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGard Spreemann <gard.spreemann@epfl.ch>2016-04-19 12:05:30 +0200
committerGard Spreemann <gard.spreemann@epfl.ch>2016-04-19 12:05:30 +0200
commit52d81872ab391c87b5d925fe1774ed3892526082 (patch)
tree332c56ad1f5226ea6e1a0ad26ad8af1116aa48f5
parent7e126c4bdf300ccc69648c8b22a745849667c50f (diff)
Naive VR implementation for internal use.
-rw-r--r--phstuff/simplicial.py30
1 files 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