-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKmeansRun.go
68 lines (65 loc) · 1.3 KB
/
KmeansRun.go
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
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bufio"
"encoding/csv"
"io"
"log"
"os"
"strconv"
"time"
)
func main() {
dimension := 4
k := 5
numOfThreads := 7
minChange := 0.00000000001
f, _ := os.Open("C:\\data\\fakeDataBig.csv") //TODO create folder at this location or change path to your dataset
points := make([]Point, 0)
// Create a new reader.
r := csv.NewReader(bufio.NewReader(f))
for {
record, err := r.Read()
// Stop at EOF.
if err == io.EOF {
break
}
point := Point{
make([]float64, 0),
dimension,
}
for value := range record {
num, _ := strconv.ParseFloat(record[value], 64)
point.numbers = append(point.numbers, num)
}
points = append(points, point)
}
kMeans := Kmeans{
points,
k,
dimension,
minChange,
numOfThreads,
}
start := time.Now()
clusters := kMeans.doKmeansSerial()
elapsed := time.Since(start)
log.Printf("Kmeans serial took %s", elapsed)
//Check if all clusters were used
sumLen := 0
for _, value := range clusters {
sumLen += len(value)
println(value)
}
//Check if all points are present
println(sumLen)
start = time.Now()
clusters = kMeans.doKmeansParallel()
elapsed = time.Since(start)
log.Printf("Kmeans parallel took %s", elapsed)
sumLen = 0
for _, value := range clusters {
sumLen += len(value)
println(value)
}
println(sumLen)
}