Exemplo n.º 1
0
        public static List <DataVector> AggregateTrueMeansToFileSystem(int partitionsNum, int clustersNum, string executionDirectory)
        {
            List <PartialMean> partialMeans = new List <PartialMean>();

            for (int i = 0; i < partitionsNum; i++)
            {
                // should be replaced with Group Communication
                string     path = Path.Combine(executionDirectory, Constants.DataDirectory, Constants.PartialMeanFilePrefix + i.ToString(CultureInfo.InvariantCulture));
                FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                using (StreamReader reader = new StreamReader(file))
                {
                    int index = 0;
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        if (index++ < clustersNum)
                        {
                            partialMeans.Add(PartialMean.FromString(line));
                        }
                    }
                    reader.Close();
                }
            }
            List <DataVector> newCentroids = new List <DataVector>();

            for (int i = 0; i < clustersNum; i++)
            {
                List <PartialMean> means = partialMeans.Where(m => m.Mean.Label == i).ToList();
                newCentroids.Add(PartialMean.AggregatedMean(means));
            }
            return(newCentroids);
        }