Exemple #1
0
        private void ComputeNewCentroids()
        {
            int columnCount = Input.ColumnCount;

            for (int c = 0; c < Centroids.Count; c++)
            {
                int[]           clusterIndex = AssignedClusters.FindAllIndexof(c);
                List <double[]> clusterRows  = Input.ToRowArrays().Where((x, i) => clusterIndex.Contains(i)).ToList();

                List <double> newCentroid = new List <double>(Enumerable.Repeat(0.0, Input.ColumnCount));

                int clusterRowCount = clusterRows.Count;
                for (int j = 0; j < clusterRowCount; j++)
                {
                    for (int i = 0; i < columnCount; i++)
                    {
                        newCentroid[i] = (newCentroid[i] + clusterRows[j][i]) / 2; //vectorize this shit
                    }
                }
                Centroids[c] = CreateVector.Dense(newCentroid.ToArray());
            }
            Centroids.RemoveAll(x => x.Count == 0);
        }
Exemple #2
0
 public List <double[]> GetClusterOfInput(int clusterNumber)
 {
     return(Input.ToRowArrays().Where((x, i) => AssignedClusters.FindAllIndexof(clusterNumber).Contains(i)).ToList());
 }