public void test() { K_mean k = new K_mean(); k.doIt("data254.csv", "News", new List <Type>() { typeof(string) }, 5, 400, "res123.csv"); }
static void Main(string[] args) { K_mean k = new K_mean(); k.doIt(@"../../Data/GExpress.txt", "News", new List <Type>() { typeof(string) }, 5, 400, @"G_res.csv"); }
/// <summary> /// after text preparation do the Kmean Process. /// </summary> /// <param name="data">double array of dataset</param> /// <param name="k">num of clusters</param> /// <param name="initial_centroids">initial centroids</param> /// <param name="maxiter">Maximum iteration</param> /// <param name="record_heterogeneity">heterogenity collection</param> /// <returns>Centroids and Cluster assignmets</returns> public Tuple <double[][], int[]> kmeans(double[][] data, int k, double[][] initial_centroids, int maxiter, ref List <double> record_heterogeneity) { K_mean km = new K_mean(); double[][] centroids = initial_centroids; int[] prev_cluster_assignment = new int[] { -1 }; for (int i = 0; i < maxiter; i++) { #if verbose if (i % 100 == 0) { Console.WriteLine("iter:\t" + i + " - " + (i / 100 + 1) * 100 + " \tof " + maxiter); } #endif int[] cluster_assignment = assign_clusters(data, centroids); centroids = revise_centroids(data, k, cluster_assignment); if ((prev_cluster_assignment[0] != -1) && (Common.arraysEqual(cluster_assignment, prev_cluster_assignment))) { break; } #if verbose if (prev_cluster_assignment[0] != -1) { int changed_clusters = Common.getArrayChanges(cluster_assignment, prev_cluster_assignment); Console.WriteLine(changed_clusters + " elements changed their clusters."); } #endif double score = compute_heterogeneity(data, k, centroids, cluster_assignment); record_heterogeneity.Add(score); prev_cluster_assignment = cluster_assignment; } #if verbose for (int i = 0; i < record_heterogeneity.Count; i++) { Console.WriteLine("Heterogenity : " + record_heterogeneity[i]); } #endif return(new Tuple <double[][], int[]>(centroids, prev_cluster_assignment)); }