Ejemplo n.º 1
0
    def test_random_3d(self):
        N = 200
        R = 0.25

        pts = rand(N, 3)
        rc = rips_complex(pts, R)

        edges = set([tuple(e) for e in rc.simplices[1]])

        for i in range(N):
            for j in range(i + 1, N):
                if norm(pts[i] - pts[j]) < R:
                    assert ((i, j) in edges)
                else:
                    assert ((i, j) not in edges)

        for t in rc.simplices[2]:
            for i, j in [(0, 1), (0, 2), (1, 2)]:
                assert ((t[i], t[j]) in edges)

        for t in rc.simplices[3]:
            for i, j in [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]:
                assert ((t[i], t[j]) in edges)

        ensure_complex_exactness(rc)
Ejemplo n.º 2
0
 def test_random_3d(self):
     N = 200
     R = 0.25
 
     pts = rand(N,3)
     rc  = rips_complex( pts, R )
 
     edges = set( [tuple(e) for e in rc.simplices[1]] )
     
     for i in range(N):
         for j in range(i+1,N):
             if norm(pts[i] - pts[j]) < R:
                 assert( (i,j) in edges )
             else:
                 assert( (i,j) not in edges )
    
     for t in rc.simplices[2]:
         for i,j in [(0,1),(0,2),(1,2)]:
             assert( (t[i],t[j]) in edges )
 
     for t in rc.simplices[3]:
         for i,j in [(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)]:
             assert( (t[i],t[j]) in edges )
     
     ensure_complex_exactness(rc)
Ejemplo n.º 3
0
"""
Detection of holes in coverage in an idealized abstraction of a sensor
network. Hodge decomposition of a random cochain is used to compute a
harmonic cochain.

"""
from scipy import rand
from scipy.linalg import norm
from scipy.sparse.linalg import cg

from pydec import kd_tree, flatten, triplot, read_array
from pydec.dec.rips_complex import rips_complex


pts = read_array('300pts.mtx')  # 300 random points in 2D
rc = rips_complex( pts, 0.15 )

simplices = rc.simplices

cmplx = rc.chain_complex()  # boundary operators [ b0, b1, b2 ]
b1 = cmplx[1].astype(float)  # edge boundary operator
b2 = cmplx[2].astype(float)  # face boundary operator

x = rand(b1.shape[1]) # random 1-chain
# Decompose x using discrete Hodge decomposition
alpha = cg( b1 * b1.T, b1   * x, tol=1e-8)[0]
beta  = cg( b2.T * b2, b2.T * x, tol=1e-8)[0]
h = x - (b1.T * alpha) - (b2 * beta) # harmonic component of x
h /= abs(h).max() # normalize h

Ejemplo n.º 4
0
"""
Detection of holes in coverage in an idealized abstraction of a sensor
network. Hodge decomposition of a random cochain is used to compute a
harmonic cochain.

"""
from scipy import rand
from scipy.linalg import norm
from scipy.sparse.linalg import cg

from pydec import kd_tree, flatten, triplot, read_array
from pydec.dec.rips_complex import rips_complex

pts = read_array('300pts.mtx')  # 300 random points in 2D
rc = rips_complex(pts, 0.15)

simplices = rc.simplices

cmplx = rc.chain_complex()  # boundary operators [ b0, b1, b2 ]
b1 = cmplx[1].astype(float)  # edge boundary operator
b2 = cmplx[2].astype(float)  # face boundary operator

x = rand(b1.shape[1])  # random 1-chain
# Decompose x using discrete Hodge decomposition
alpha = cg(b1 * b1.T, b1 * x, tol=1e-8)[0]
beta = cg(b2.T * b2, b2.T * x, tol=1e-8)[0]
h = x - (b1.T * alpha) - (b2 * beta)  # harmonic component of x
h /= abs(h).max()  # normalize h

#print 'norm( h )',norm(h)
#print 'norm(b1   * h)', norm(b1   * h)  #should be small