Beispiel #1
0
        private void updateSeeds(List<Object> lstNeighbor, Object centreObj, Seeds seeds)
        {
            float coreDist = centreObj.coreDist;
            int num = lstNeighbor.Count;
            for(int i = 0; i < num; i++)
            {
                Object obj = lstNeighbor[i];
                if(obj.process == false)
                {
                    float dist = matrixDistance[centreObj.index, obj.index];
                    float tempCoreReach = dist > coreDist ? dist : coreDist;

                    if(obj.coreReachibility == -1)
                    {
                        obj.coreReachibility = tempCoreReach;
                        seeds.Insert(obj);
                    }
                    else
                        if (tempCoreReach < obj.coreReachibility)
                        {
                            seeds.Moveup(obj, tempCoreReach);
                        }
                }
            }
        }
Beispiel #2
0
        public void Run(ref List<Item> lstMatrix)
        {
            int n = lstMatrix.Count;
            for (int i = 0; i < n; i++)
            {
                matrixDistance[i, i] = 0.0f;
                setOfObject.Add(new Object(i));

                //for (int j = 0; j < i; j++)
                //{
                //    if (matrixDistance[i, j] <= eps)
                //    {
                //        int ind = 0;
                //        foreach (Object obj in setOfObject[i].lstNeighbor)
                //        {
                //            ind++;
                //            if (matrixDistance[i, j] < matrixDistance[i, obj.index])
                //                break;
                //        }

                //        setOfObject[i].lstNeighbor.Insert(ind, setOfObject[j]);
                //    }
                //}

                for (int j = i + 1; j < n; j++)
                {
                    float res = distance(lstMatrix[i].Vector.Tf_idf, lstMatrix[j].Vector.Tf_idf);
                    matrixDistance[i, j] = res;
                    matrixDistance[j, i] = res;
                    //if (res <= eps)
                    //{
                    //    int ind = 0;
                    //    foreach (Object obj in setOfObject[i].lstNeighbor)
                    //    {
                    //        ind++;
                    //        if (res < matrixDistance[i, obj.index])
                    //            break;
                    //    }

                    //    setOfObject[i].lstNeighbor.Insert(ind, setOfObject[j]);
                    //}

                }
            }

            n = setOfObject.Count;
            for(int i = 0; i < n; i++)
            {
                Object obj = setOfObject[i];
                List<Object> lstNeighbor = obj.getNeighbor(matrixDistance, setOfObject, Eps);

                if(obj.process == false)
                {
                    obj.process = true;
                    obj.setCoreDist(matrixDistance, Eps, MinPts);

                    if (obj.coreDist != 0)
                    {
                        // Tạo Seed mới
                        Seeds seeds = new Seeds();
                        updateSeeds(obj.lstNeighbor, obj, seeds);

                        foreach (Object objNeighbor in seeds.LstSeeds)
                        {
                            List<Object> lstNeighborOfObj = objNeighbor.getNeighbor(matrixDistance, setOfObject, Eps);
                            objNeighbor.process = true;
                            if (objNeighbor.coreDist != 0.0)
                            {
                                updateSeeds(lstNeighborOfObj, objNeighbor, seeds);
                            }
                        }
                        if (seeds.LstSeeds.Count > 0)
                        {

                            foreach (Object objCluster in seeds.LstSeeds)
                            {
                                lstMatrix[objCluster.index].TmpLabel = countLabel;
                            }

                            countLabel++;
                        }
                    }
                }
            }
        }