def buildNNDataStructure(self):
"""Builds a nearest neighbor data structure. User doesn't need to
call this unless the self.problems attribute was changed manually."""
if len(self.problemFeatures)==0 or len(self.featureNames)==0:
return
try:
from sklearn.neighbors import NearestNeighbors,BallTree
from scipy.spatial import KDTree
with self.lock:
try:
farray = self.problemFeatures.array
except AttributeError:
farray = np.array(self.problemFeatures.items)
if self.metricTransform is not None:
farray = np.dot(farray,self.metricTransform)
#self.nn = NearestNeighbors(n_neighbors=1,algorithm="auto").fit(farray)
self.nn = BallTree(farray)
#self.nn = KDTree(farray)
self.nnBuildSize = len(self.problemFeatures)
except ImportError:
print "IKDatabase: Warning, scikit-learn is not installed, queries will be much slower"
with self.lock:
self.nn = None
self.nnBuildSize = 0
return
评论列表
文章目录