KdKeys.DataMining.Clustering.KMeans.Cluster.Add C# (CSharp) Method

Add() public method

Adds a single dimension array data to the cluster
public Add ( double data ) : void
data double A 1-dimensional array containing data that will be added to the cluster
return void
        public virtual void Add(double [] data)
        {
            this.List.Add(data);

            if (this.List.Count == 1)
            {
                this._clusterSum = new double[data.Length];

                this._clusterMean = new double[data.Length];
            }

            for (int count = 0; count < data.Length; count++)
            {
                this._clusterSum[count] = this._clusterSum[count] + data[count];
            }
        }

Usage Example

示例#1
0
        public ClusterCollection RandomSeeding(int k, double[][] data)
        {
            int size = data.Length;

            double[][]        seeds         = new double[k][];
            Random            random        = new Random();
            Hashtable         random_table  = new Hashtable();
            Cluster           cluster       = null;
            ClusterCollection init_clusters = new ClusterCollection();

            for (int i = 0; i < k;)
            {
                int r = random.Next(size - 1);
                if (!random_table.ContainsKey(r))
                {
                    random_table.Add(r, 0);
                    seeds[i]    = new double[3];
                    seeds[i][0] = data[r][0]; seeds[i][1] = data[r][1]; seeds[i][2] = data[r][2];
                    cluster     = new Cluster();
                    cluster.Add(seeds[i]);
                    init_clusters.Add(cluster);
                    i++;
                }
            }
            return(init_clusters);
        }
All Usage Examples Of KdKeys.DataMining.Clustering.KMeans.Cluster::Add