public static void DrawGradient(Rectangle rectangle, Color fromColor, Color toColor, bool horizontal, int steps) { horizontal = !horizontal; //because f**k you. GradientConfiguration gConfig = new GradientConfiguration(); bool foundConfig = false; foreach (GradientConfiguration g in _gradientConfigs) { if (g.IsConfig(rectangle.Width, rectangle.Height, fromColor, toColor, horizontal, steps)) { gConfig = g; foundConfig = true; break; // TODO: might not be correct. Was : Exit For } } if (foundConfig == false) { gConfig = new GradientConfiguration(rectangle.Width, rectangle.Height, fromColor, toColor, horizontal, steps); _gradientConfigs.Add(gConfig); } gConfig.Draw(rectangle); }
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)); } }