public static void SaveGraphData(String outputFolder, Graph graph, int numDimensions) { // extract the interesting information GraphHelper gh = new GraphHelper(graph, numDimensions); // get the graph of the input data // get the graph nodes/vertices List <float[]> graphVertices = gh.GetNodePositions(); // get the from to edges List <float[]> edges = gh.GetEdges(graphVertices); CSVIO.Save <float>(outputFolder + "/graph_nodes.csv", graphVertices); CSVIO.Save <float>(outputFolder + "/edge.csv", edges); // Get any separate objects // get the graph nodes that belong to a connected component. List <List <GraphNode> > connComps = gh.GetConnectedComponents(); // get the mapping List <int[]> nodeClusterIndex = gh.GetNodeClusterIndex(connComps); // get the average position of the nodes in a connected component List <float[]> clusterCenters = gh.GetClusterCenters(connComps, nodeClusterIndex); CSVIO.Save <float>(outputFolder + "/cluster_centres.csv", clusterCenters); CSVIO.Save <int>(outputFolder + "/node_to_cluster_index.csv", nodeClusterIndex); }
static void Main(string[] args) { if (args.Length < 5) { Console.WriteLine("Usage: GNG.exe <datafilepath> <outputfolder> <numepochs> <maxnodes> <numthreads> <metric>"); Console.WriteLine(@"e.g. GNG.exe c:\data\data.csv c:\data 10 5000 4 1"); return; } DateTime dtStart = DateTime.Now; Console.WriteLine("Starting: {0}", dtStart); String dataFilePath = args[0]; String outputFolder = args[1]; int numEpochs = Int32.Parse(args[2]); int maxNodes = Int32.Parse(args[3]); int numThreads = Int32.Parse(args[4]); // 1 is squared euclidean, 2 is cosine int metric = Int32.Parse(args[5]); // load the data text file List <float[]> samples = CSVIO.Load <float>(dataFilePath); int numDimensions = samples[0].Length; // GNGRunner r = new GNGRunner(numDimensions, maxNodes, numThreads, metric); Console.WriteLine("Training: {0}", DateTime.Now); // build the graph Graph graph = r.Fit(samples, numEpochs); Console.WriteLine("Predicting: {0}", DateTime.Now); // identify the cluster each sample is nearest to. List <int[]> predictions = r.Predict(samples); Console.WriteLine("Saving: {0}", DateTime.Now); CSVIO.Save <int>(outputFolder + "/predictions.csv", predictions); // save the learnt graph SaveGraphData(outputFolder, graph, numDimensions); DateTime dtFinished = DateTime.Now; Console.WriteLine("Finished: {0} Duration: {1}", dtFinished, dtFinished - dtStart); }
static void Main(string[] args) { String fitsPaths = args[0]; String[] fitsFilePaths = fitsPaths.Split(','); for (int i = 0; i < fitsFilePaths.Length; i++) { fitsFilePaths[i] = fitsFilePaths[i].Trim(); } String positionsFilePath = args[1]; String outputFilePath = args[2]; double threshold = double.Parse(args[3]); List <float[]> positions = CSVIO.Load <float>(positionsFilePath); List <int[]> mask = CreateMask(fitsFilePaths, positions, threshold); CSVIO.Save <int>(outputFilePath, mask); }
static void Main(string[] args) { Console.WriteLine("Starting: {0}", DateTime.Now); String filePath = args[0]; String outputFilePath = args[1]; int k = Int32.Parse(args[2]); int distance = Int32.Parse(args[3]); int numThreads = Int32.Parse(args[4]); var samples = CSVIO.Load <float>(filePath); Similarity sim = new EuclideanDistance(); if (distance == 2) { sim = new PearsonSimilarity(); } if (distance == 3) { sim = new CosineSimilarity(); } Console.WriteLine("Using distance measure: {0} on {1} samples of dimensionality: {2}", sim, samples.Count, samples[0].Length); Console.WriteLine("Beginning Clustering: {0}", DateTime.Now); var clusters = Cluster(samples, sim, numThreads); Cluster root = clusters[0]; Console.WriteLine("Finished Clustering: {0}", DateTime.Now); var classifications = Classify(samples, root, k); CSVIO.Save <int>(outputFilePath, classifications); Console.WriteLine("Finished: {0}", DateTime.Now); }
static void Main(string[] args) { String dataFilePath = args[0]; String weightsFilePath = args[1]; String outputFilePath = args[2]; int metric = Int32.Parse(args[3]); int numThreads = Int32.Parse(args[4]); Stopwatch w = new Stopwatch(); w.Start(); List <double[]> samples = CSVIO.Load <double>(dataFilePath); List <double[]> weights = CSVIO.Load <double>(weightsFilePath); w.Stop(); long loadingMS = w.ElapsedMilliseconds; w.Reset(); w.Start(); DistanceFunctions distFunc = distFunc = new SquareEuclideanDistanceFunction(); if (metric == 2) { distFunc = new Cosine(); } if (metric == 3) { distFunc = new Pearson(); } Console.WriteLine("Using distance function with brute force: {0} and numthreads: {1}", metric, numThreads); NNAlgorithm nnMethod = null; // if euclidean then can use fast kdtree if (metric == 1) { nnMethod = new KDTreeNN(weights, distFunc); } else { nnMethod = new BruteForceNN(weights, distFunc); } List <int[]> nearestNeighbours = NearestNeighbour.GetNearestNeighbours(samples, nnMethod, numThreads); w.Stop(); long vqMS = w.ElapsedMilliseconds; w.Reset(); w.Start(); CSVIO.Save <int>(outputFilePath, nearestNeighbours); w.Stop(); long savingMS = w.ElapsedMilliseconds; Console.WriteLine("Loading Time: {0} NN Time: {1} Saving Time: {2}", loadingMS, vqMS, savingMS); }