Indexed text attachment
verify-topology-learning.py
Source for Algebraic and Differential Topology in Machine Learning and AI: Obstructions, Invariants, and Counts
View paper · Download original file
Lines 684–783 of 1604. Source text is displayed literally.
684 F = []685 for x in facets_of(K):686 for i in range(len(x)):687 F.append(list(x[:i + 1]) + [v + N for v in x[i:]])688 return Cx(F), N689 690 691def is_pseudomanifold(K, closed=True):692 d = K.dim693 cnt = {}694 for x in K.S[d]:695 for i in range(d + 1):696 f = x[:i] + x[i + 1:]697 cnt[f] = cnt.get(f, 0) + 1698 vals = set(cnt.values())699 return (vals == {2}) if closed else (vals <= {1, 2})700 701 702def torus7():703 return Cx([[i, (i + 1) % 7, (i + 3) % 7] for i in range(7)] + [[i, (i + 2) % 7, (i + 3) % 7] for i in range(7)])704 705 706def rp2():707 return Cx([[1, 2, 4], [1, 2, 6], [1, 3, 4], [1, 3, 5], [1, 5, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [3, 4, 6], [4, 5, 6]])708 709 710def klein():711 def v(i, j):712 if i == 4:713 i, j = 0, (-j) % 4714 return 4 * i + (j % 4)715 F = []716 for i in range(4):717 for j in range(4):718 F.append([v(i, j), v(i + 1, j), v(i + 1, j + 1)])719 F.append([v(i, j), v(i, j + 1), v(i + 1, j + 1)])720 return Cx(F)721 722 723def moebius():724 return Cx([[i, (i + 1) % 5, (i + 2) % 5] for i in range(5)])725 726 727def simplex_boundary(n):728 return Cx([c for c in itertools.combinations(range(n + 2), n + 1)])729 730 731def cross_sphere(n):732 """boundary of the (n+1)-dimensional cross-polytope; vertex 2i is +e_i, 2i+1 is -e_i"""733 return Cx([[2 * i + s for i, s in enumerate(signs)] for signs in itertools.product((0, 1), repeat=n + 1)])734 735 736def icosahedron():737 T, B = 0, 11738 u = lambda i: 1 + i % 5739 l = lambda i: 6 + i % 5740 F = []741 for i in range(5):742 F += [[T, u(i), u(i + 1)], [u(i), u(i + 1), l(i)], [u(i + 1), l(i), l(i + 1)], [B, l(i), l(i + 1)]]743 return Cx(F)744 745 746def grid_torus(m, d):747 """Freudenthal triangulation of (Z/m)^d"""748 def num(v):749 r = 0750 for a in v:751 r = r * m + a % m752 return r753 F = []754 for v in itertools.product(range(m), repeat=d):755 for perm in itertools.permutations(range(d)):756 w = list(v)757 s = [num(w)]758 for k in perm:759 w[k] += 1760 s.append(num(w))761 F.append(s)762 return Cx(F)763 764 765def circle(n):766 return Cx([[i, (i + 1) % n] for i in range(n)])767 768 769# ######################## CHECKS FOR THE PAPER ########################770random.seed(20261119)771 772 773def vnorm(a):774 return math.sqrt(sum(x * x for x in a))775 776 777def trig_poly(deg=3):778 co = [(random.gauss(0, 1), random.gauss(0, 1)) for _ in range(deg + 1)]779 return lambda t: sum(a * math.cos(k * t) + b * math.sin(k * t) for k, (a, b) in enumerate(co))780 781 782sec('1. Obstructions')783okbu = True