kmeans(:: Props, K, Num : Classification)
N := |Props|-1
Seeds :=[]
for i := 0 to K-1 by 1
tuple_rand(1,Rand)
tuple_floor(Rand*N,seed)
tuple_int(seed,seed)
tuple_find(Seeds,seed, Indices)
while(|Indices|>0 and Indices # -1)
tuple_rand(1,Rand)
tuple_floor(Rand*N,seed)
tuple_find(Seeds,seed, Indices)
endwhile
Seeds :=[Seeds, seed]
stop()
endfor
PSeeds :=Props[Seeds]
iterNum := 0
tuple_gen_const(N+1, -1, Classification)
tuple_max(Props,Max)
tuple_min(Props,Min)
delta := Max-Min
while(iterNum<Num)
tuple_gen_const(N+1, -1, ClassificationNew)
for j := 0 to N by 1
Mini := delta
for i := 0 to K-1 by 1
tuple_fabs(PSeeds[i] - Props[j],d)
if(d<=Mini)
ClassificationNew[j] := i
Mini := d
endif
* stop()
end
halcon 脚本代码实现简单的一维kmeans算法
最新推荐文章于 2023-06-14 17:19:54 发布