}
// add the value to the current vector
vector[i] = value;
}
// add the vector to the list of vectors
vectors.add(new DoubleArray(vector, vectorCount));
vectorCount++;
}
// close the file
reader.close();
// Create a list of clusters
clusters = new ArrayList<Cluster>();
// Get the size of vectors
int vectorsSize = vectors.get(0).data.length;
System.out.println("Vector size: " + vectors.size());
// SPECIAL CASE: If only one vector
if (vectors.size() == 1) {
// Create a single cluster and return it
DoubleArray vector = vectors.get(0);
Cluster cluster = new Cluster(vectorsSize);
cluster.addVector(vector);
clusters.add(cluster);
return clusters;
}
// (1) Randomly generate k empty clusters with a random mean (cluster
// center)
for(int i=0; i< k; i++){
int rand = 0 + (int)(Math.random() * vectors.size()-1);
DoubleArray meanVector = vectors.get(rand);
Cluster cluster = new Cluster(vectorsSize);
cluster.setMean(meanVector);
clusters.add(cluster);
}