Esempio n. 1
0
        private void ThreadMethod(int start, int end, int min)
        {
            for (int i = start; i < end; i++)
            {
                int           cCount        = i;
                ClusterResult clusterresult = null;
                switch (this.MethodMode)
                {
                case 0: clusterresult = SingleStart(cCount, ref this.WaitObj.Flags[i - min]); break;

                case 1: clusterresult = SingleStartWithWeight(cCount, ref this.WaitObj.Flags[i - min]); break;
                }
                ClusterAssessReport_BWP clusterassessreport = Assess.GetBWP(Data, clusterresult, Distences);
                lock (this.SyObject)
                {
                    this.FinalReport.HisResult.Add(clusterresult);
                    this.FinalReport.HisReport.Add(clusterassessreport);
                    if (clusterassessreport.AvgBWP > this.Score)
                    {
                        this.Score = clusterassessreport.AvgBWP;
                        FinalReport.FanialResult = clusterresult;
                        FinalReport.FanialReport = clusterassessreport;
                    }
                }
            }
            if (Barobj != null)
            {
                Barobj.RemoveParticipant();
            }
        }
Esempio n. 2
0
        public static ClusterAssessReport_BWP GetBWP(IDataTable <DataRow> data, ClusterResult result, double[,] distence)
        {
            int cCount      = result.cCount;
            int dataCount   = data.RowCount;
            int paraCount   = result.Properties.Length;
            var classnumber = result.ClassNumbers;
            var properties  = result.Properties;

            int[] eachClusterCount = result.CountEachCluster;
            double[,] bc = new double[dataCount, cCount];
            double[] b      = new double[dataCount];
            double[] w      = new double[dataCount];
            double[] bwp    = new double[dataCount];
            double   avgBwp = 0;
            ClusterAssessReport_BWP report = new ClusterAssessReport_BWP();

            for (int i = 0; i < dataCount - 1; i++)
            {
                for (int j = i + 1; j < dataCount; j++)
                {
                    int    cj         = classnumber[j];
                    int    ci         = classnumber[i];
                    double temp       = distence[i, j];
                    int    tempcountj = eachClusterCount[cj];
                    int    tempcounti = eachClusterCount[ci];
                    if (ci == cj)
                    {
                        temp  = temp / (tempcountj - 1);
                        w[i] += temp;
                        w[j] += temp;
                    }
                    else
                    {
                        bc[i, cj] += temp / tempcountj;
                        bc[j, ci] += temp / tempcounti;
                    }
                }
            }
            for (int i = 0; i < dataCount; i++)
            {
                var    iclass = classnumber[i];
                double tempb  = Double.PositiveInfinity;
                for (int j = 0; j < iclass; j++)
                {
                    double t = bc[i, j];
                    if (t < tempb && t != 0)
                    {
                        tempb = t;
                    }
                }
                for (int j = iclass + 1; j < cCount; j++)
                {
                    double t = bc[i, j];
                    if (t < tempb && t != 0)
                    {
                        tempb = t;
                    }
                }
                b[i] = tempb;
                double tempw = w[i];
                bwp[i]  = (tempb - tempw) / (tempb + tempw);
                avgBwp += bwp[i];
            }
            avgBwp        = avgBwp / dataCount;
            report.AvgBWP = avgBwp;
            report.B      = b;
            report.W      = w;
            report.BWP    = bwp;
            return(report);
        }
Esempio n. 3
0
        public ClusterResult SingleStartWithWeight(int cCount, ref int flag)
        {
            DateTime starttime = DateTime.Now;
            var      result    = new ClusterResult();

            double[,] center = new double[cCount, ParaCount];
            double[] w = new double[ParaCount];
            int[]    reCount;
            int      i, j, k;

            for (i = 0; i < ParaCount; i++)
            {
                w[i] = (double)1 / ParaCount;
            }
            int[]  classnumber = new int[DataCount];
            int    count       = 0;
            bool   same;
            int    fail;
            double odd = 2;

            switch (InitialMode)
            {
            case 0: InitCenter(cCount, center); break;

            case 1: InitCenterSPSS(cCount, center); break;

            case 2: InitCenterAvg(cCount, odd, center); break;
            }
            while (true)
            {
                reCount = new int[cCount];
                same    = true;
                for (i = 0; i < DataCount; i++)
                {
                    double[] len = new double[cCount];
                    int      min = 0;
                    for (j = 0; j < cCount; j++)
                    {
                        for (k = 0; k < ParaCount; k++)
                        {
                            len[j] += w[k] * Math.Pow(Data[i, Properties[k]].ConvertToDouble() - center[j, k], 2);
                        }
                        if (len[j] < len[min])
                        {
                            min = j;
                        }
                    }
                    if (same && classnumber[i] != min)
                    {
                        same = false;
                    }
                    classnumber[i] = min;
                    reCount[min]++;
                }
                if (InitialMode == 2 && count == 0)
                {
                    fail = 0;
                    for (i = 0; i < cCount; i++)
                    {
                        if (reCount[i] == 0)
                        {
                            fail++;
                            if (fail > cCount / 10)
                            {
                                break;
                            }
                        }
                    }
                    if (fail > cCount / 10)
                    {
                        odd = odd / 2;
                        InitCenterAvg(cCount, odd, center);
                        continue;
                    }
                }
                count++;
                if (count >= MaxCount || same)
                {
                    break;
                }
                ResetCenterAndWeights(cCount, classnumber, reCount, center, w);
                flag++;
            }
            result.Centers          = center;
            result.ClassNumbers     = classnumber;
            result.Weights          = w;
            result.cCount           = cCount;
            result.Properties       = Properties;
            result.LoopCount        = count;
            result.CountEachCluster = reCount;
            DateTime endtime = DateTime.Now;

            result.CostTime = (endtime - starttime).TotalMilliseconds;
            flag            = MaxCount;
            return(result);
        }