using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; namespace ReadFromFile { public class k_means1 { static void Main(string[] args) { Console.WriteLine("\nBegin k-means clustering demo\n"); StreamReader reader = new StreamReader(@"F:\DOT NET PROJECTS\2012 projects\scalable learning of collective behaviour\app.txt"); string content = null; string[] line = null; char[] ch = { ',' }; int a = 1; double[][] rawdata = new double[20][]; while ((content = reader.ReadLine()) != null) { if (a == 1 || a == 2) Console.WriteLine("Does nothing"); else { line = content.Split(ch); // try //{ for (int b = 0; b < 20; b++) { rawdata[b] = new double[2]; rawdata[b][0] = Convert.ToDouble(line[1]); rawdata[b][1] = Convert.ToDouble(line[2]); } //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} //Console.WriteLine("First value: " + line[1]); //Console.WriteLine(); //Console.WriteLine("First value: " + line[2]); } a++; } foreach (double[] d in rawdata) { Console.WriteLine("First value: " + line[1]); Console.WriteLine(); Console.WriteLine("First value: " + line[2]); } Console.WriteLine("Raw unclustered data:\n"); Console.WriteLine(" Height Weight"); Console.WriteLine("-------------------"); ShowData(rawdata, 1, true, true); int numClusters = 3; Console.WriteLine("\nSetting numClusters to " + numClusters); int[] clustering = Cluster(rawdata, numClusters); // this is it Console.WriteLine("\nK-means clustering complete\n"); Console.WriteLine("Final clustering in internal form:\n"); ShowVector(clustering, true); Console.WriteLine("Raw data by cluster:\n"); ShowClustered(rawdata, clustering, numClusters, 1); Console.WriteLine("\nEnd k-means clustering demo\n"); Console.ReadLine(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)