本文整理汇总了Python中pyflann.FLANN属性的典型用法代码示例。如果您正苦于以下问题:Python pyflann.FLANN属性的具体用法?Python pyflann.FLANN怎么用?Python pyflann.FLANN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pyflann
的用法示例。
在下文中一共展示了pyflann.FLANN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_index
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def build_index(dataset, n_neighbors):
"""
Takes a dataset, returns the "n" nearest neighbors
"""
# Initialize FLANN
pyflann.set_distance_type(distance_type='euclidean')
flann = pyflann.FLANN()
params = flann.build_index(dataset,
algorithm='kdtree',
trees=4
)
#print params
nearest_neighbors, dists = flann.nn_index(dataset, n_neighbors,
checks=params['checks'])
return nearest_neighbors, dists
示例2: build_index
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def build_index(dataset, n_neighbors):
"""
Takes a dataset, returns the "n" nearest neighbors
"""
# Initialize FLANN
pyflann.set_distance_type(distance_type='euclidean')
flann = pyflann.FLANN()
params = flann.build_index(dataset,
algorithm='kdtree',
trees=4
)
#print params
nearest_neighbors, dists = flann.nn_index(dataset, n_neighbors,
checks=params['checks'])
return nearest_neighbors, dists
示例3: radius_adjacency
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def radius_adjacency(self, X):
flindex = self._get_built_index(X)
n_samples, n_features = X.shape
X = np.require(X, requirements = ['A', 'C']) # required for FLANN
graph_i = []
graph_j = []
graph_data = []
for i in range(n_samples):
jj, dd = flindex.nn_radius(X[i], self.radius ** 2)
graph_data.append(dd)
graph_j.append(jj)
graph_i.append(i*np.ones(jj.shape, dtype=int))
graph_data = np.concatenate(graph_data)
graph_i = np.concatenate(graph_i)
graph_j = np.concatenate(graph_j)
return sparse.coo_matrix((np.sqrt(graph_data), (graph_i, graph_j)),
shape=(n_samples, n_samples))
示例4: test_all_methods_close
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def test_all_methods_close():
rand = np.random.RandomState(36)
X = rand.randn(10, 2)
D_true = squareform(pdist(X))
D_true[D_true > 0.5] = 0
def check_method(method):
kwargs = {}
if method == 'pyflann':
try:
import pyflann as pyf
except ImportError:
raise SkipTest("pyflann not installed.")
flindex = pyf.FLANN()
flindex.build_index(X, algorithm='kmeans',
target_precision=0.9)
kwargs['flann_index'] = flindex
this_D = compute_adjacency_matrix(X, method=method, radius=0.5,
**kwargs)
assert_allclose(this_D.toarray(), D_true, rtol=1E-5)
for method in ['auto', 'cyflann', 'pyflann', 'brute']:
yield check_method, method
示例5: __init__
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def __init__(self, kernel, num_neighbors, max_memory, lr):
self.kernel = kernel
self.num_neighbors = num_neighbors
self.max_memory = max_memory
self.lr = lr
self.keys = None
self.values = None
self.kdtree = FLANN()
# key_cache stores a cache of all keys that exist in the DND
# This makes DND updates efficient
self.key_cache = {}
# stale_index is a flag that indicates whether or not the index in self.kdtree is stale
# This allows us to only rebuild the kdtree index when necessary
self.stale_index = True
# indexes_to_be_updated is the set of indexes to be updated on a call to update_params
# This allows us to rebuild only the keys of key_cache that need to be rebuilt when necessary
self.indexes_to_be_updated = set()
# Keys and value to be inserted into self.keys and self.values when commit_insert is called
self.keys_to_be_inserted = None
self.values_to_be_inserted = None
# Move recently used lookup indexes
# These should be moved to the back of self.keys and self.values to get LRU property
self.move_to_back = set()
示例6: __init__
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def __init__(self, low, high, points):
self._low = np.array(low)
self._high = np.array(high)
self._range = self._high - self._low
self._dimensions = len(low)
self.__space = init_uniform_space([0] * self._dimensions,
[1] * self._dimensions,
points)
self._flann = pyflann.FLANN()
self.rebuild_flann()
开发者ID:jimkon,项目名称:Deep-Reinforcement-Learning-in-Large-Discrete-Action-Spaces,代码行数:13,代码来源:action_space.py
示例7: test_alignment
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def test_alignment(target_pdb_fn, source_pdb_fn, aligned_pdb_fn, interface_dist = 10.0):
parser = PDBParser()
target_struct = parser.get_structure(target_pdb_fn, target_pdb_fn)
target_coord = np.asarray([atom.get_coord() for atom in target_struct.get_atoms() if atom.get_id() == 'CA'])
source_struct = parser.get_structure(source_pdb_fn, source_pdb_fn)
source_coord = np.asarray([atom.get_coord() for atom in source_struct.get_atoms() if atom.get_id() == 'CA'])
source_atom = [atom for atom in source_struct.get_atoms() if atom.get_id() == 'CA']
aligned_struct = parser.get_structure(aligned_pdb_fn, aligned_pdb_fn)
# Find interface atoms in source.
flann = pyflann.FLANN()
r, d = flann.nn(target_coord, source_coord)
d = np.sqrt(d)
int_at_ix = np.where(d < interface_dist)[0]
dists = []
for at_ix in int_at_ix:
res_id = source_atom[at_ix].get_parent().get_id()
chain_id = source_atom[at_ix].get_parent().get_parent().get_id()
try:
d = aligned_struct[0][chain_id][res_id]['CA'] - source_atom[at_ix]
except:
print('Failed for {} '.format(aligned_pdb_fn))
sys.exit(1)
dists.append(d)
rmsd = np.sqrt(np.mean(np.square(dists)))
return rmsd
# Go to directory
示例8: __init__
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def __init__(self, cfg):
self.mutual_best=cfg['mutual_best']
self.ratio_test=cfg['ratio_test']
self.ratio=cfg['ratio']
self.use_cuda=cfg['cuda']
self.flann=FLANN()
if self.use_cuda:
self.match_fn_1=lambda desc0,desc1: find_nearest_point_idx(desc1, desc0)
self.match_fn_2=lambda desc0,desc1: find_first_and_second_nearest_point(desc1, desc0)
else:
self.match_fn_1=lambda desc0,desc1: self.flann.nn(desc1, desc0, 1, algorithm='linear')
self.match_fn_2=lambda desc0,desc1: self.flann.nn(desc1, desc0, 2, algorithm='linear')
示例9: _build_indices
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def _build_indices(X, flann_args):
"Builds FLANN indices for each bag."
# TODO: should probably multithread this
logger.info("Building indices...")
indices = [None] * len(X)
for i, bag in enumerate(plog(X, name="index building")):
indices[i] = idx = FLANNIndex(**flann_args)
idx.build_index(bag)
return indices
示例10: __init__
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def __init__(self, threshold, algorithm):
"""Inits the object.
Args:
threshold: Float distance at which coverage is considered new.
algorithm: Algorithm used to get approximate neighbors.
Returns:
Initialized object.
"""
self.flann = pyflann.FLANN()
self.threshold = threshold
self.algorithm = algorithm
self.corpus_buffer = []
self.lookup_array = []
示例11: __init__
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def __init__(self, metric, target_precision):
self._target_precision = target_precision
self.name = 'FLANN(target_precision=%f)' % self._target_precision
self._metric = metric
示例12: fit
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def fit(self, X):
self._flann = pyflann.FLANN(
target_precision=self._target_precision,
algorithm='autotuned', log_level='info')
if self._metric == 'angular':
X = sklearn.preprocessing.normalize(X, axis=1, norm='l2')
self._flann.build_index(X)
示例13: _get_built_index
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def _get_built_index(self, X):
if self.flann_index is None:
pyindex = pyf.FLANN(**(self.pyflann_kwds or {}))
else:
pyindex = self.flann_index
flparams = pyindex.build_index(X, algorithm=self.algorithm,
target_precision=self.target_precision)
return pyindex
示例14: knn_adjacency
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def knn_adjacency(self, X):
n_samples = X.shape[0]
flindex = self._get_built_index(X)
A_ind, A_data = flindex.nn_index(X, self.n_neighbors)
A_ind = np.ravel(A_ind)
A_data = np.sqrt(np.ravel(A_data)) # FLANN returns square distances
A_indptr = self.n_neighbors * np.arange(n_samples + 1)
return sparse.csr_matrix((A_data, A_ind, A_indptr),
shape=(n_samples, n_samples))
示例15: build_index
# 需要导入模块: import pyflann [as 别名]
# 或者: from pyflann import FLANN [as 别名]
def build_index(dataset, n_neighbors):
"""
Takes a dataset, returns the "n" nearest neighbors
"""
# Initialize FLANN
import pyflann
pyflann.set_distance_type(distance_type='euclidean')
flann = pyflann.FLANN()
params = flann.build_index(dataset, algorithm='kdtree', trees=4)
#print params
nbrs, dists = flann.nn_index(dataset, n_neighbors, checks=params['checks'])
return nbrs, dists