private static void ClusterizeAll(IReadOnlyList <float> series, int[] from, int[] to, ILogger logger) { foreach (var template in Wishart.GenerateTemplateForWishart(from, to)) { var vectors = ZVectorBuilder.Build(series, template, 0); var clusters = Clusterize(vectors); var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "clusters", $"{template[0]}-{template[1]}-{template[2]}-{template[3]}.json"); using (var writer = new StreamWriter(path)) { ServiceStack.Text.JsonSerializer.SerializeToWriter(clusters, writer); } } }
private static void ClusterizeAllParallel(IReadOnlyList <float> series, int[] from, int[] to, ILogger logger, string clustersDir) { Wishart.GenerateTemplateForWishart(from, to).AsParallel().ForAll(template => { string stringTemplate = $"{template[0]}-{template[1]}-{template[2]}-{template[3]}"; var vectors = ZVectorBuilder.Build(series, template, 0); logger.LogInformation("Clusterize for template {template}", stringTemplate); var clusters = Clusterize(vectors); logger.LogInformation("Start writing results for {template} to file", stringTemplate); var path = Path.Combine(clustersDir, "full", $"{stringTemplate}.json"); fileWriter.Write(clusters, path); var centers = clusters.Select(cluster => cluster.Centr).ToList(); var pathCenters = Path.Combine(clustersDir, "centers", $"{stringTemplate}.centers.json"); fileWriter.Write(centers, pathCenters); logger.LogInformation("Writing finished for {template}", stringTemplate); }); }