Ejemplo n.º 1
0
        public IReadOnlyList <InitialCluster> Clusterize(IReadOnlyList <ZVector> zVectors)//
        {
            Prepare(zVectors);

            double e = 0.000001;

            clusters.Add(new InitialCluster());
            for (int i = 0; i < n; i++)
            {
                ZVector xi = x[i];

                List <double> Ui = BuildU(i);

                //находим номера l классов, которые содержат точки, с которыми связана xi
                List <int> l = new List <int>();
                for (int j = 0; j < Ui.Count; j++)
                {
                    if (Ui[j] > e)                     //xi связанна с xj
                    {
                        int wxj = w(x[j]);
                        if (wxj != -1 && (!l.Contains(wxj)) && IsFar(xi, clusters[wxj]))
                        {
                            l.Add(wxj);
                        }
                    }
                }

                //(3.1)
                if (l.Count == 0)
                {
                    clusters.Add(new InitialCluster(xi));
                    continue;
                }
                //(3.2)
                if (l.Count == 1)
                {
                    if (clusters[l[0]].IsFormed)
                    {
                        clusters[0].Add(xi);
                    }
                    else
                    {
                        clusters[l[0]].Add(xi);
                    }
                    continue;
                }
                //(3.3)
                //проверяем сколько классов сформировано
                int tmp = 1;
                for (; tmp < clusters.Count; tmp++)
                {
                    if (!clusters[tmp].IsFormed)
                    {
                        break;
                    }
                }
                //(3.3.1)
                if (tmp == clusters.Count)                 //все классы сформированы
                {
                    clusters[0].Add(xi);
                    continue;
                }
                //(3.3.2)
                int zh = z(l);
                l.Sort();
                //a)
                if (zh > 1 || l[0] == 0)
                {
                    clusters[0].Add(xi);

                    for (int j = clusters.Count - 1; j >= 1; j--)
                    {
                        InitialCluster c = clusters[j];
                        if (Check(c))
                        {
                            c.IsFormed = true;
                        }
                        else
                        {
                            clusters[0].Add(c.ZVectors);
                            clusters.Remove(c);
                        }
                    }
                }
                else                 //b)
                {
                    for (int j = l.Count - 1; j > 0; j--)
                    {
                        clusters[l[0]].Add(clusters[l[j]].ZVectors);
                        clusters.Remove(clusters[l[j]]);
                    }
                    clusters[l[0]].Add(xi);
                }
            }

            clusters.Remove(clusters[0]);
            //foreach (var cluster in clusters)
            //{
            //    cluster.SetCentr();
            //}
            return(clusters);
        }
Ejemplo n.º 2
0
    public override string ToString()
    {
        string temp = "O " + Origin.ToString("F2") + " Z " + ZVector.ToString("F2");

        return(temp);
    }