Example #1
0
 def compute_geom(self, diffusion_time, n_neighbors):
     data = self.data
     dim = self.dim
     #set radius according to paper (i think this is dim not d)
     radius = (diffusion_time * (diffusion_time * np.pi * 4)**(dim/2))**(0.5)
     #set adjacency radius large enough that points beyond it have affinity close to zero
     bigradius = 3 * radius
     adjacency_method = 'cyflann'
     cyflann_kwds = {'index_type':'kdtrees', 'num_trees':10, 'num_checks':n_neighbors}
     adjacency_kwds = {'radius':bigradius, 'cyflann_kwds':cyflann_kwds}
     affinity_method = 'gaussian'
     affinity_kwds = {'radius':radius}
     laplacian_method = 'geometric'
     laplacian_kwds = {'scaling_epps':radius}
     geom = Geometry(adjacency_method=adjacency_method, adjacency_kwds=adjacency_kwds,
                     affinity_method=affinity_method, affinity_kwds=affinity_kwds,
                     laplacian_method=laplacian_method, laplacian_kwds=laplacian_kwds)
     geom.set_data_matrix(data)
     adjacency_matrix = geom.compute_adjacency_matrix()
     laplacian_matrix = geom.compute_laplacian_matrix()
     return(geom)
Example #2
0
 def compute_geom_brute(self, diffusion_time, n_neighbors):
     data = self.data
     dim = self.dim
     #set radius according to paper (i think this is dim not d)
     radius = (diffusion_time * (diffusion_time * np.pi * 4)**(dim/2))**(0.5)
     #set adjacency radius large enough that points beyond it have affinity close to zero
     bigradius = 3 * radius
     adjacency_method = 'brute'
     adjacency_kwds = {'radius':bigradius}
     affinity_method = 'gaussian'
     affinity_kwds = {'radius':radius}
     laplacian_method = 'geometric'
     laplacian_kwds = {'scaling_epps':1}
     geom = Geometry(adjacency_method=adjacency_method, adjacency_kwds=adjacency_kwds,
                     affinity_method=affinity_method, affinity_kwds=affinity_kwds,
                     laplacian_method=laplacian_method, laplacian_kwds=laplacian_kwds)
     geom.set_data_matrix(data)
     geom.adjacency_matrix = geom.compute_adjacency_matrix()
     geom.laplacian_matrix = geom.compute_affinity_matrix()
     geom.laplacian_matrix = self.get_laplacian(geom, radius)
     return(geom)
Example #3
0
}  # scaling ensures convergence to Laplace-Beltrami operator

geom = Geometry(adjacency_method=adjacency_method,
                adjacency_kwds=adjacency_kwds,
                affinity_method=affinity_method,
                affinity_kwds=affinity_kwds,
                laplacian_method=laplacian_method,
                laplacian_kwds=laplacian_kwds)

# You can/should also use the set_data_matrix, set_adjacency_matrix, set_affinity_matrix
# to send your data set (in whichever form it takes) this way.
geom.set_data_matrix(X)

# You can get the distance, affinity etc with e.g: Geometry.get_distance_matrix()
# you can update the keyword arguments passed inially using these functions
adjacency_matrix = geom.compute_adjacency_matrix()
# by defualt this is pass-by-reference. Use copy=True to get a copied version.

# If you don't want to pre-compute a Geometry you can pass a dictionary or geometry
# arguments to one of the embedding classes.
geom = {
    'adjacency_method': adjacency_method,
    'adjacency_kwds': adjacency_kwds,
    'affinity_method': affinity_method,
    'affinity_kwds': affinity_kwds,
    'laplacian_method': laplacian_method,
    'laplacian_kwds': laplacian_kwds
}

# an example follows for creating each embedding into 2 dimensions.
n_components = 2
Example #4
0
geom.set_data_matrix(X)

## Computing geometric matrices
'''
Once you've input your data you may  be interested in computing the
various geometric matrices like the distance, affinity etc.

You can do this with the .compute_ functions.

If you passed a method parameter e.g. adjacency_method = 'cyflann'
then it will use this one. 
To update this use geom.adjacency_method = <new method name>
you can pass new keywords to these functions.
'''

adjacency_matrix = geom.compute_adjacency_matrix()

'''
Note that by defualt this is pass-by-reference. 
pass copy=True to get a copied version.
'''

## Radius Selection 
'''
one important parameter to the adjacency function when using a
radius neighbors method is the radius parameter. There is no
default parameter for this as it should be chosen with care.

In general this is an iterative process and depends inherently
on the data itself. If the method does not produce the desired
result the radius can be adjusted in order to examine new