Indexed text attachment
verify-pde-learning.py
Source for Partial Differential Equations in Machine Learning and AI: Naturality, Well-Posedness, and Spectral Rates
View paper · Download original file
Lines 1221–1244 of 1244. Source text is displayed literally.
1221 U[n2 + i][n2 + j] += cs * pij1222Em = [[0.0] * (2 * n2) for _ in range(2 * n2)]1223for i in range(n2):1224 for j in range(n2):1225 Em[i][j] = A2[i][j]1226 Em[n2 + i][n2 + i] = 1.01227UEU = mm(tr(U), mm(Em, U))1228iso = max(abs(UEU[i][j] - Em[i][j]) for i in range(2 * n2) for j in range(2 * n2)) / l15[-1]1229check('O1 numerical rank at relative accuracy 1e-6: elliptic inverse 1000 modes (algebraic), heat flow at t = 0.01 eleven modes, wave flow all of them',1230 rank_e == 63 and cont_p == 11 and rank_p in (11, 12) and close(ell[0], 1 / PI ** 2, 1e-3) and iso < 1e-10,1231 'singular values 1/(pi k)^2 exceed 1e-6 of the first for k < 1000; heat: %d in the continuum, %d on a 63-point grid; wave propagator is an isometry of the energy (defect %.0e)' % (cont_p, rank_p, iso))1232 1233m = 601234Cm = [[(1 - max((i + 0.5) / m, (j + 0.5) / m)) / m for j in range(m)] for i in range(m)]1235lc_, _ = jacobi_eig(Cm)1236top = sorted(lc_, reverse=True)[:3]1237exact3 = [1 / ((k - 0.5) ** 2 * PI ** 2) for k in (1, 2, 3)]1238tail10 = 0.5 - sum(1 / ((k - 0.5) ** 2 * PI ** 2) for k in range(1, 11))1239check('O2 translates of a step have covariance eigenvalues 1/((k-1/2)pi)^2: ten modes leave 14 per cent error, the n-width decays like n^(-1/2)',1240 all(close(a_, b_, 2e-3) for a_, b_ in zip(top, exact3)) and close(math.sqrt(tail10 / 0.5), 0.1424, 5e-3),1241 'eigenvalues %s (exact %s); relative error after 10 modes %.4f, after 100 modes %.4f' % (', '.join('%.5f' % v for v in top), ', '.join('%.5f' % v for v in exact3), math.sqrt(tail10 / 0.5), math.sqrt((0.5 - sum(1 / ((k - 0.5) ** 2 * PI ** 2) for k in range(1, 101))) / 0.5)))1242 1243footer()1244