## ----- echo = false,结果=“ hide”,messages = false -------------------------------------------------------------------------------------------------------------------------require(knitr)opts_chunk $ set(错误= false,message = false,parning = false)库(biocneighbors)## ------------------------------------------------------------------------------------------------------------------------------------------------------------ nobs <-10000 ndim <-20数据<-matrix(runif(nobs*ndim),ncol = ndim)## --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- fout < - findknn(数据,k = 10,bnparam = kmknnparam())头(fout $ index)头(fout $ dance)## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------fout $ dange [3,] ## -------------------------------------------------------------------------------------------------------------------------------------- nquery <- 1000 ndim <- 20 query <- matrix(runif(nquery*ndim), ncol=ndim) ## ----------------------------------------------------------------------------- qout <- queryKNN(data, query, k=5, BNPARAM=KmknnParam()) head(qout$index) head(qout$distance) ## ----------------------------------------------------------------------------- qout$index[3,] ## ----------------------------------------------------------------------------- qout$distance[3,] ## ----------------------------------------------------------------------------- findKNN(data, k=5, subset=3:5) ## ----------------------------------------------------------------------------- names(findKNN(data, k=2, get.distance=FALSE)) ## ----------------------------------------------------------------------------- library(BiocParallel) out <- findKNN(data, k=10, BPPARAM=MulticoreParam(3)) ## ----------------------------------------------------------------------------- pre <- buildIndex(data, BNPARAM=KmknnParam()) out1 <- findKNN(BNINDEX=pre, k=5) out2 <- queryKNN(BNINDEX=pre, query=query, k=2) ## ----------------------------------------------------------------------------- out.m <- findKNN(data, k=5, BNPARAM=KmknnParam(distance="Manhattan")) ## ----------------------------------------------------------------------------- sessionInfo()