public IClusteringCentroid <DomainType> Cluster(IDataSet <DomainType> data_set) { IFunction <IList <DomainType[]>, ICentroidDistance <DomainType> > centroid_calculator = centroid_calculator_template.Generate(data_set.DataContext); IList <DomainType[]> instance_features_list = data_set.FeatureData; RandomNumberGenerator generator = new RNGCryptoServiceProvider(); IList <ICentroidDistance <DomainType> > centroids = new List <ICentroidDistance <DomainType> >(); int[] permutation = generator.RandomPermutation(instance_features_list.Count); for (int centroid_index = 0; centroid_index < this.desired_cluster_count; centroid_index++) { IList <DomainType[]> centroid_members = new List <DomainType[]>(); centroid_members.Add(instance_features_list[permutation[centroid_index]]); if (centroid_members.Count != 0) { centroids.Add(centroid_calculator.Compute(centroid_members)); } } Cluster(instance_features_list, centroid_calculator, centroids); return(new ClusteringCentroid <DomainType>(data_set.DataContext, centroids)); }