Ejemplo n.º 1
0
        static void DoTsne(string[] args)
        {
            string inFile          = (args.Length >= 1) ? args[0] : "";
            double perplexityRatio = (args.Length >= 2) ? double.Parse(args[1]) : 0.05;
            int    epochs          = (args.Length >= 3) ? int.Parse(args[2]) : 500;
            int    outDim          = (args.Length >= 4) ? int.Parse(args[3]) : 2;

            if (!(inFile.EndsWith(".csv") || inFile.EndsWith(".npy")))
            {
                Console.WriteLine("Usage:  TsneDx.exe <input-file>.csv [perplexity-ratio] [epochs] [out-dim]");
                return;
            }
            string outFile = inFile.Substring(0, inFile.Length - 4) + "_map.csv";

            Console.WriteLine("Loading file " + inFile);
            float[][] X = inFile.EndsWith(".csv") ? ReadCsvFile(inFile) : TsneMap.ReadNumpyFile(inFile);
            Console.WriteLine("Loaded table: " + X.Length + "x" + X[0].Length);
            Console.WriteLine(string.Format(
                                  "Running tSNE: Perpelxity Ratio: {0}, Epochs: {1}, Out Dimension: {2}...",
                                  perplexityRatio, epochs, outDim));

            using (TsneMap tsne = new TsneMap()
            {
                PerplexityRatio = perplexityRatio,
                MaxEpochs = epochs,
                OutDim = outDim
            }) {
                float[][] Y = tsne.Fit(X);
                WriteCsvFile(Y, outFile);
            }
        }
Ejemplo n.º 2
0
        static void DoPca(string[] args)
        {
            int    outDim  = int.Parse(args[0]);
            string inFile  = args[1];
            string outFile = inFile.Substring(0, inFile.Length - 4) + "_pc.csv";

            if (!(inFile.EndsWith(".csv") || inFile.EndsWith(".npy")))
            {
                Console.WriteLine("PCA Usage:  TsneDx.exe <out-dim> <input-file>.csv");
                return;
            }
            float[][] X = inFile.EndsWith(".csv") ? ReadCsvFile(inFile) : TsneMap.ReadNumpyFile(inFile);
            if (X == null)
            {
                Console.WriteLine("Cannot load input file: " + TsneMap.ErrorMsg);
                return;
            }
            var pca = new FastPca();
            var B   = pca.DoPca(X, outDim);

            WriteCsvFile(B, outFile);
        }
Ejemplo n.º 3
0
 public float[] DoPcaNumpy(float[][] X, int eigenCount)
 {
     return(TsneMap.Flatten(DoPca(X, eigenCount)));
 }
Ejemplo n.º 4
0
        public float[] DoPcaBuffer(long ptr, int rows, int columns, int eigenCount)
        {
            var matrix = TsneMap.NumpyArrayToMatrix(ptr, rows, columns);

            return(TsneMap.Flatten(DoPca(matrix, eigenCount)));
        }
Ejemplo n.º 5
0
 public float[] DoPcaNumpyFile(string fileName, int eigenCount)
 {
     return(TsneMap.Flatten(DoPca(TsneMap.ReadNumpyFile(fileName), eigenCount)));
 }