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 1581–1604 of 1604. Source text is displayed literally.
1581 abs(w0) == 1 and all(s == w0 for s in sp) and net_winding(bstar - 1e-3) == w0 and net_winding(bstar + 1e-3) == 0 and mn < 1e-3,1582 'degree %d; signed preimages of three directions %s; degree drops to 0 at bias %.4f, where the smallest output norm is %.1e' % (w0, sp, bstar, mn))1583 1584 1585# --- N7: zeros of odd networks (own generator)1586rg12 = random.Random(20261124)1587hist = {}1588ok_odd = True1589for _ in range(200):1590 units = [(rg12.gauss(0, 2), rg12.gauss(0, 2), rg12.gauss(0, 1)) for _ in range(6)]1591 fo = lambda t: sum(c_ * math.tanh(a_ * math.cos(t) + b_ * math.sin(t)) for a_, b_, c_ in units)1592 M_ = 200001593 vals_ = [fo(2 * PI * (i + 0.5) / M_) for i in range(M_)]1594 z_ = sum(1 for i in range(M_) if vals_[i - 1] * vals_[i] < 0)1595 hist[z_] = hist.get(z_, 0) + 11596 ok_odd = ok_odd and z_ % 4 == 21597# Each tanh is bounded by 1 in absolute value, so this is a global lower bound.1598biased_lower_bound = 10.0 - sum(abs(weight) for _, _, weight in units)1599check('N7 the sampled sign crossings of the scalar odd networks number 2 modulo 4',1600 ok_odd and biased_lower_bound > 0,1601 '200 random networks with six tanh units: sign crossings on the unit circle %s; with output bias 10 the last output is at least %.4f' % (sorted(hist.items()), biased_lower_bound))1602 1603footer()1604