-
Notifications
You must be signed in to change notification settings - Fork 65
/
k-means2.cl
57 lines (47 loc) · 1.14 KB
/
k-means2.cl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(defpackage :clml.k-means
(:use :cl :hjs.util.vector :hjs.util.meta
:statistics :hjs.util.matrix)
(:nicknames :k-means)
(:export #:k-means
#:make-cluster
#:c-center
#:c-size
#:c-points
#:cluster
#:pw-points
#:pw-clusters
#:p-pos
#:p-owner
#:point
#:get-cluster-centroids
#:get-cluster-points
))
(in-package :clml.k-means)
;;;; global variables
(defparameter *num-of-trials* 10)
(defparameter *distance-function* #'euclid-distance)
(defparameter *k-means-random-state* (make-random-state t))
(defparameter *max-iteration* 1000)
(declaim (type fixnum *num-of-trials* *max-iteration*))
(defstruct distance-function
name
v.v
m.v
m.m)
(defun trial ()
(loop
do (progn
(update-lower-bounds problem-workspace)
(select-points-for-update)
(update-center-for-selected-points)
(update-all-centers-and-save-old-centers)
(update-distance-between-point-and-owner)
(decf rest-iteration))
until (stop-p))
)
(defun k-means ()
(loop repeat num-of-trials
do
(trial)
(update-best-trial))
)