Example #1
0
        private static void Run(string input_file, string output_file, bool output_csv, string config_file, int dimensions, bool verbose)
        {
            float[][] Data = ReadBinary(input_file);

            Stopwatch sw   = Stopwatch.StartNew();
            tSNE      tsne = new tSNE(Data);

            sw.Stop();
            if (config_file != "")
            {
                tsne = SetConfig(tsne, config_file);
            }
            sw.Start();
            double[][] Y = tsne.Reduce(dimensions, verbose);
            sw.Stop();
            Console.WriteLine("t-SNE reduction time:\t{0}s", sw.ElapsedMilliseconds / 1000.0);

            if (output_csv)
            {
                SaveCSV(Y, output_file);
            }
            else
            {
                SaveBinary(Y, output_file);
            }
        }
Example #2
0
        public static tSNE SetConfig(tSNE tsne, string configFile)
        {
            string json;

            try
            {
                json = File.ReadAllText(configFile);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Configuration file {0} not found! Using default parameters.");
                return(tsne);
            }

            Dictionary <string, Dictionary <string, object> > config = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, object> > >(json);

            foreach (KeyValuePair <string, Dictionary <string, object> > conf in config)
            {
                UpdateConfig(tsne, conf.Key, conf.Value);
            }

            Console.WriteLine("\n\n");

            return(tsne);
        }
Example #3
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            double perplexity;
            int    dimension;
            double epsilon;

            if (Double.TryParse(tbPerplexity.Text, out perplexity) &&
                Int32.TryParse(tbDimension.Text, out dimension) &&
                Double.TryParse(tbEpsilon.Text, out epsilon) &&
                this.srcDataSet != null)
            {
                this.tsne = new tSNE(perplexity, dimension, epsilon);
                this.tsne.InitDataRaw(this.srcDataSet);

                for (int i = 0; i < 500; i++)
                {
                    tsne.Step();
                }

                this.result2D = tsne.GetSolution();
                this.DrawResult();
            }
            else
            {
                MessageBox.Show("Invalid Option");
            }
        }
Example #4
0
        private static void UpdateConfig(tSNE tsne, string conf, Dictionary <string, object> param)
        {
            Console.WriteLine("\n{0}Configuration:", conf);
            switch (conf)
            {
            case "Initialization":
                InitializationConfiguration ic = tsne.InitializationConfig;
                ic.SmartInit           = Convert.ToBoolean(UpdateField(param, "SmartInit", ic.SmartInit));
                ic.InitialSolutionSeed = Convert.ToInt32(UpdateField(param, "InitialSolutionSeed", ic.InitialSolutionSeed));
                if (ic.InitialSolutionSeed == -1)
                {
                    Console.WriteLine("\tInitialSolutionSeed set to -1 - using random seed.");
                }
                break;

            case "Affinities":
                AffinitiesConfiguration ac = tsne.AffinitiesConfig;
                ac.Perplexity  = Convert.ToDouble(UpdateField(param, "Perplexity", ac.Perplexity));
                ac.EntropyTol  = Convert.ToDouble(UpdateField(param, "EntropyTol", ac.EntropyTol));
                ac.EntropyIter = Convert.ToInt32(UpdateField(param, "EntropyIter", ac.EntropyIter));
                break;

            case "LSHF":
                LSHFConfiguration lc = tsne.LSHFConfig;
                lc.LSHForestTrees = Convert.ToInt32(UpdateField(param, "LSHForestTrees", lc.LSHForestTrees));
                lc.LSHTreeC       = Convert.ToInt32(UpdateField(param, "LSHTreeC", lc.LSHTreeC));
                lc.LSHHashDims    = Convert.ToInt32(UpdateField(param, "LSHHashDims", lc.LSHHashDims));
                lc.LSHSeed        = Convert.ToInt32(UpdateField(param, "LSHSeed", lc.LSHSeed));
                if (lc.LSHSeed == -1)
                {
                    Console.WriteLine("\tLSHSeed set to -1 - using random seed.");
                }
                break;

            case "Gradient":
                GradientConfiguration gc = tsne.GradientConfig;
                gc.Iterations      = Convert.ToInt32(UpdateField(param, "Iterations", gc.Iterations));
                gc.GradMinGain     = Convert.ToDouble(UpdateField(param, "GradMinGain", gc.GradMinGain));
                gc.RepulsionMethod = UpdateRepulsionMethod(param, gc.RepulsionMethod);
                gc.Exaggeration    = UpdateFunctionField(param, "Exaggeration", gc.Exaggeration);
                gc.Momentum        = UpdateFunctionField(param, "Momentum", gc.Momentum);
                gc.LearningRate    = UpdateFunctionField(param, "LearningRate", gc.LearningRate);
                break;

            case "BarnesHut":
                BarnesHutConfiguration bc = tsne.BarnesHutConfig;
                bc.BarnesHutCondition = Convert.ToDouble(UpdateField(param, "BarnesHutCondition", bc.BarnesHutCondition));
                bc.Presort            = Convert.ToBoolean(UpdateField(param, "Presort", bc.Presort));
                break;

            case "PI":
                PIConfiguration pc = tsne.PIConfig;
                pc.min_num_intervals      = Convert.ToInt32(UpdateField(param, "min_num_intervals", pc.min_num_intervals));
                pc.intervals_per_integer  = Convert.ToDouble(UpdateField(param, "intervals_per_integer", pc.intervals_per_integer));
                pc.n_interpolation_points = Convert.ToInt32(UpdateField(param, "n_interpolation_points", pc.n_interpolation_points));
                break;

            default:
                Console.WriteLine("\tConfiguration type {0} unknown.", conf);
                break;
            }
            if (param.Count > 0)
            {
                Console.WriteLine("\tUnknown {0}Configuration parameters: {1}!", conf, string.Join(", ", param.Keys));
            }
        }