Я написал код для алгоритма dbscan. когда я вызываю функцию в главном Это не работает, и я не знаю, почемуФункция, не вызываемая в R
здесь код
x=read.delim("C:/Users/mf/Desktop/stp.txt")
y=read.delim("C:/Users/mf/Desktop/stp.txt")
hash=0
c=temp1=0
q=1
C=0
eps=30
MinPts=30
lable=matrix(-2,1,nrow(x))
clusterlab=matrix(-3,1,nrow(x))
for(p in 1:nrow(x))
{
if(lable[p]==-2)
{
lable[p]=1 #visited=1 and nonvisited=-2
NeighborPts = regionQuery(p, eps)
temp=nrow(NeighborPts)-1
if (temp < MinPts){
clusterlab[p]=0 #noise = 0
}
else if(temp>=MinPts){
C = C+1
haha=expandCluster(p, NeighborPts, C, eps, MinPts,hash,clusterlab,lable)
}
}
}
expandCluster <- function(p, NeighborPts, C, eps, MinPts,hash,clusterlab,lable) {
hash=hash+1
clusterlab[p]=C
for (q in 2:nrow(NeighborPts))
{ testP=NeighborPts[q,1]
if(lable[testP]==-2)
lable[testP]=1
newNeighborPts = regionQuery(testP, eps)
if ((nrow(newNeighborPts)-1) >= MinPts)
NeighborPts = rbind(NeighborPts,newNeighborPts)
if(clusterlab[testP]==-3) #is not yet member of any cluster
clusterlab[testP]=C
}
return(hash)
}
regionQuery <- function(p, eps) {
neighborhood=p
for(i in 1:nrow(x)){
temp=sqrt((x[p,1]-y[i,1])^2+(x[p,2]-y[i,2])^2)
if(temp<eps){
c=c+1
neighborhood=rbind(neighborhood,i)}
}
#neighborhood=neighborhood[-1,]
return(neighborhood)
}
, когда я называю
haha=expandCluster(p, NeighborPts, C, eps, MinPts,hash,clusterlab,lable)
Это не работает !!
Я добавляю переменную хэша, чтобы ее проверить. каждый раз, когда expachdCLuster, называемый hash, должен иметь значение. но он увеличился.
lable и clusterlab не меняется тоже.
данные here
У нас нет данных для запуска этого, и где функция regionQuery? – Spacedman
да простите, теперь я его редактирую, – knifer