Figure 1: Pseudocode for kmeans, an example of the PetaBricks program, is shown.
1 transform kmeans
2 from Points[n, 2] // Array of points (each column
3 // stores x and y coordinates)
4 through Centroids[sqrt(n), 2]
5 to Assignments[n]
7 {
7 // Rule 1:
8 // One possible initial condition: Random
9 // set of points
10 to (Centroids . column ( i ) c) from ( Points p) {
11 c=p . column (rand ( 0, n ) )
12 }
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 }
30 }
31 }
/ / Rule 2:
/ / Another initial condition; Centerplus initial