Spikey Spheres http://www.penzba.co.uk/cgi-bin/PvsNP.py?SpikeySpheres
from sklearn.decomposition import PCA, FastICA
from sklearn.manifold import MDS, Isomap
import matplotlib.pyplot as plt
fig = plt.figure()
fig.set_size_inches(15,15)
# fun params to play with
BBOX = 0.5
SAMPLES = 20000
MAX_DIM = 11
ALPHA_OUT = 0.1
ALPHA_IN = 0.1
#r = PCA(n_components=2)
r = FastICA(n_components=2)
#r = Isomap(n_components=2)
#r = MDS(n_components=2)
for dim in xrange(2, MAX_DIM):
pts = array([random.uniform(low=-BBOX, high=BBOX, size=SAMPLES) for i in xrange(dim)])
z = pts.T
r_dim = (sqrt(dim)-1)/2 # central sphere radius
w = z[(sum(z**2, axis=1)>=r_dim**2)] # out of the central sphere
centers = map(lambda x: map(lambda e: float(e.replace('0','-1')), list(x)),
[bin(x).split('b')[1].zfill(dim) for x in range(2**dim)])
centers = np.array(centers)
centers /= 2
for sphere in centers:
w = w[(sum((w-sphere)**2, axis=1)>=0.5**2)] # out of the outer spheres
z = z[(sum(z**2, axis=1)<r_dim**2)] # in the central sphere
if dim == 2:
pass
else:
r.fit(pts.T)
#r.fit(z)
#r.fit(w)
z = r.transform(z)
w = r.transform(w)
inner_pts = z.T
outer_pts = w.T
print "inner/all", inner_pts.shape[1] * 1. / pts.shape[1]
print "outer/all", outer_pts.shape[1] * 1. / pts.shape[1]
print "inner/outer", inner_pts.shape[1] * 1. / outer_pts.shape[1]
figdims = ceil(sqrt(MAX_DIM-2))
figdims = figdims * 100 + figdims * 10 + 1
ax1 = fig.add_subplot(int(figdims) + (dim-2))
ax1.axis('equal')
ax1.scatter(outer_pts[0], outer_pts[1], marker='.', linewidth=0, c='r', alpha=ALPHA_OUT, s=100)
ax1.scatter(inner_pts[0], inner_pts[1], marker='.', linewidth=0, c='b', alpha=ALPHA_IN, s=100)
plt.show()
inner/all 0.1333 outer/all 0.07975 inner/outer 1.67147335423 inner/all 0.20605 outer/all 0.26915 inner/outer 0.7655582389 inner/all 0.3096 outer/all 0.38495 inner/outer 0.804260293545 inner/all 0.43805 outer/all 0.3964 inner/outer 1.10507063572 inner/all 0.57405 outer/all 0.34655 inner/outer 1.65647092772 inner/all 0.69485 outer/all 0.2683 inner/outer 2.58982482296 inner/all 0.7884 outer/all 0.19635 inner/outer 4.01527883881 inner/all 0.8627 outer/all 0.13085 inner/outer 6.59304547191 inner/all 0.9122 outer/all 0.08515 inner/outer 10.7128596594