Exemplo n.º 1
0
        /// <summary>
        /// Construct the clusters objects.
        /// </summary>
        /// <param name="k">The number of clusters to have.</param>
        /// <param name="observations">The observations.</param>
        public Clusters(int k, IMLDataSet observations)
        {
            _clustersHash = new Dictionary <IMLDataPair, int>();
            _clusters     = new List <ICollection <IMLDataPair> >();

            IList list = new List <IMLDataPair>();

            foreach (IMLDataPair pair in observations)
            {
                list.Add(pair);
            }
            var kmc = new KMeansUtil <IMLDataPair>(k, list);

            kmc.Process();

            for (int i = 0; i < k; i++)
            {
                ICollection <IMLDataPair> cluster = kmc.Get(i);
                _clusters.Add(cluster);

                foreach (IMLDataPair element in cluster)
                {
                    _clustersHash[element] = i;
                }
            }
        }
 /// <summary>
 /// Construct the K-Means object.
 /// </summary>
 /// <param name="theK">The number of clusters to use.</param>
 /// <param name="theSet">The dataset to cluster.</param>
 public KMeansClustering(int theK, IMLDataSet theSet)
 {
     IList<BasicMLDataPair> list = new List<BasicMLDataPair>();
     foreach (IMLDataPair pair in theSet)
     {
         list.Add((BasicMLDataPair) pair);
     }
     _k = theK;
     _kmeans = new KMeansUtil<BasicMLDataPair>(_k, list as IList);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Construct the K-Means object.
        /// </summary>
        /// <param name="theK">The number of clusters to use.</param>
        /// <param name="theSet">The dataset to cluster.</param>
        public KMeansClustering(int theK, IMLDataSet theSet)
        {
            IList <BasicMLDataPair> list = new List <BasicMLDataPair>();

            foreach (IMLDataPair pair in theSet)
            {
                list.Add((BasicMLDataPair)pair);
            }
            _k      = theK;
            _kmeans = new KMeansUtil <BasicMLDataPair>(_k, list as IList);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Construct the clusters objects. 
        /// </summary>
        /// <param name="k">The number of clusters to have.</param>
        /// <param name="observations">The observations.</param>
        public Clusters(int k, IMLDataSet observations)
        {
            _clustersHash = new Dictionary<IMLDataPair, int>();
            _clusters = new List<ICollection<IMLDataPair>>();

            IList list = new List<IMLDataPair>();
            foreach (IMLDataPair pair in observations)
            {
                list.Add(pair);
            }
            var kmc = new KMeansUtil<IMLDataPair>(k, list);
            kmc.Process();

            for (int i = 0; i < k; i++)
            {
                ICollection<IMLDataPair> cluster = kmc.Get(i);
                _clusters.Add(cluster);

                foreach (IMLDataPair element in cluster)
                {
                    _clustersHash[element] = i;
                }
            }
        }