當前位置: 首頁>>代碼示例>>Python>>正文


Python pyflann.FLANN屬性代碼示例

本文整理匯總了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 
開發者ID:varun-suresh,項目名稱:Clustering,代碼行數:18,代碼來源:clustering.py

示例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 
開發者ID:XiaohangZhan,項目名稱:cdp,代碼行數:18,代碼來源:approx_rank_order_cluster.py

示例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)) 
開發者ID:mmp2,項目名稱:megaman,代碼行數:22,代碼來源:adjacency.py

示例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 
開發者ID:mmp2,項目名稱:megaman,代碼行數:25,代碼來源:test_adjacency.py

示例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() 
開發者ID:mjacar,項目名稱:pytorch-nec,代碼行數:28,代碼來源:dnd.py

示例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 
開發者ID:LPDI-EPFL,項目名稱:masif,代碼行數:35,代碼來源:evalPatchDock.py

示例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') 
開發者ID:zju3dv,項目名稱:GIFT,代碼行數:14,代碼來源:evaluation.py

示例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 
開發者ID:djsutherland,項目名稱:skl-groups,代碼行數:11,代碼來源:knn.py

示例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 = [] 
開發者ID:brain-research,項目名稱:tensorfuzz,代碼行數:16,代碼來源:corpus.py

示例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 
開發者ID:erikbern,項目名稱:ann-benchmarks,代碼行數:6,代碼來源:flann.py

示例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) 
開發者ID:erikbern,項目名稱:ann-benchmarks,代碼行數:9,代碼來源:flann.py

示例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 
開發者ID:mmp2,項目名稱:megaman,代碼行數:11,代碼來源:adjacency.py

示例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)) 
開發者ID:mmp2,項目名稱:megaman,代碼行數:11,代碼來源:adjacency.py

示例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 
開發者ID:yl-1993,項目名稱:learn-to-cluster,代碼行數:15,代碼來源:aro.py


注:本文中的pyflann.FLANN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。