// Main static void Main(string[] args) { // Download the MNIST data from Mr. YannAndréLeCun's web site using (var wc = new WebClient()) { if (!File.Exists(LABEL_FILE_NAME)) { wc.DownloadFile(LABEL_FILE_URL, LABEL_FILE_NAME); } if (!File.Exists(IMAGE_FILE_NAME)) { wc.DownloadFile(IMAGE_FILE_URL, IMAGE_FILE_NAME); } } // Load the MNIST labels var labels = GetLabels().ToArray(); // Load the MNIST image data var pixels = GetImages().ToArray(); // Dimension reduction with UMAP var umap = new Umap(); var epochs = umap.InitializeFit(pixels); for (var i = 0; i < epochs; ++i) { umap.Step(); } var embedding = umap.GetEmbedding().AsEnumerable(); // Convert the embedding into chart data var graph = new Graph.Scatter() { x = embedding.Select((o) => o[0]), y = embedding.Select((o) => o[1]), text = labels.Select((o) => o.ToString()), mode = "markers", marker = new Graph.Marker { color = labels, colorscale = "Rainbow", showscale = true }, }; var chart = Chart.Plot(graph); chart.WithTitle("MNIST Embedded via UMAP"); chart.WithXTitle("X"); chart.WithYTitle("Y"); chart.WithSize(800, 800); chart.Show(); }
public static void Plot(string pattern, bool generateHtml = false) { var iterationCounts = new List <int> { 1, 10, 25, 50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000 }; var regexTimer = new RegexTimer(); List <RegexTimer.RegexTimerResult> timesStandard = iterationCounts .Select(iterationCount => regexTimer.Standard(pattern, iterations: iterationCount)) .ToList(); List <RegexTimer.RegexTimerResult> timesStandardReused = iterationCounts .Select(iterationCount => regexTimer.StandardReused(pattern, iterations: iterationCount)) .ToList(); List <RegexTimer.RegexTimerResult> timesCompiled = iterationCounts .Select(iterationCount => regexTimer.Compiled(pattern, iterations: iterationCount)) .ToList(); var graph1 = new Graph.Scatter { x = timesStandard.Select(x => x.IterationCount), y = timesStandard.Select(x => x.ElapsedTicks), name = "Standard Regex" }; var graph2 = new Graph.Scatter { x = timesStandardReused.Select(x => x.IterationCount), y = timesStandardReused.Select(x => x.ElapsedTicks), name = "Reused Regex" }; var graph3 = new Graph.Scatter { x = timesCompiled.Select(x => x.IterationCount), y = timesCompiled.Select(x => x.ElapsedTicks), name = "Compiled Regex" }; PlotlyChart chart = Chart.Plot( new[] { graph1, graph2, graph3 } ); chart.WithXTitle("Iteration Count"); chart.WithYTitle("Ticks"); chart.WithTitle("Regex on 100 characters"); chart.Show(); if (generateHtml) { string html = chart.GetHtml(); using var outFile = new StreamWriter( Path.Combine(PathUtil.GetSolutionBasePath(), "Plots", "PlotByIterationCount.html") ); outFile.Write(html); } }