Checking Rank Estimates¶
Copyright (C) 2020 Andreas Kloeckner
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as pt
Let's make two particle collections: sources and targets
sources = np.random.randn(2, 200)
targets = np.random.randn(2, 200) + 10
pt.plot(sources[0], sources[1], "go")
pt.plot(targets[0], targets[1], "ro")
[<matplotlib.lines.Line2D at 0x7f63650425d0>]
What's our convergence ratio $\rho$: $$ \rho=\frac{d(c,\text{furthest target})}{d(c,\text{closest source})}? $$
Well, what should $c$ be, really? (Technically, we can use any $c$, so we're free to choose whichever we think is best.)
c = np.sum(targets, axis=1) / targets.shape[1]
c
array([ 9.98878098, 10.02648225])
pt.plot(sources[0], sources[1], "go")
pt.plot(targets[0], targets[1], "ro")
pt.plot(c[0], c[1], "bo")
[<matplotlib.lines.Line2D at 0x7f6364f514d0>]
Assemble the interaction matrix¶
all_distvecs = sources.reshape(2, 1, -1) - targets.reshape(2, -1, 1)
dists = np.sqrt(np.sum(all_distvecs**2, axis=0))
interaction_mat = np.log(dists)
Estimate the rank depending on precision $\varepsilon$¶
First, obtain an idea of what $\rho$ is:
dist_tgt_to_c = np.sqrt(np.sum((c.reshape(2, 1) - targets)**2, axis=0))
dist_src_to_c = np.sqrt(np.sum((c.reshape(2, 1) - sources)**2, axis=0))
rho = np.max(dist_tgt_to_c) / np.min(dist_src_to_c)
rho
0.2537137489568833
Then plot the numerical rank depending on epsilon:
_, sigma, V = la.svd(interaction_mat)
pt.semilogy(sigma)
[<matplotlib.lines.Line2D at 0x7f6364ea8310>]
eps_values = 10**(-np.linspace(1, 12))
For the given precisions $\varepsilon$, find the associated numerical rank:
def numrank(eps):
return np.sum(sigma > eps)
ranks = [numrank(e) for e in eps_values]
pt.semilogx(eps_values, ranks)
[<matplotlib.lines.Line2D at 0x7f63659fced0>]
Now compare with our estimate:
pt.semilogx(eps_values, ranks)
pt.semilogx(eps_values, (np.log(eps_values)/np.log(rho)-1)**2)
[<matplotlib.lines.Line2D at 0x7f6364bb14d0>]
- We estimated that the rank would grow quadratically.
- Comments on how good our estimate is?