Esempio n. 1
0
        //--------------------------------------------
        private void Compared_Ferns_commonMember_(int[, ,] fernij, int fernsNumber, int numClusters, double[,] fernpcknumber, out int[,] _r1) //ferns size, sample size, cluster size
        {
            newFern = new double[numClusters];                                                                                                //存取newFerns(用來持續修正)
            //第一次比對(尚未開始加入修正的值)
            int a = 0;

            _r1 = new int[fernsNumber, numClusters]; //用來存取ferns之間cluster的對應
            //將fern1的cluster先放好 此動作只需要一次
            for (int i = 0; i < numClusters; i++)
            {
                _r1[a, i] = i;
            }
            if (fernsNumber == 1)
            {
            }
            else
            {
                int b = 1;
                while (b < fernsNumber)
                {
                    for (int i = 0; i < numClusters; i++)
                    {
                        for (int j = 0; j < numClusters; j++)
                        {
                            a_b[i, j] = fernij[a, i, j];
                        }
                    }
                    //--------------//
                    //利用指派問題 - 匈牙利法 得到最佳的指派
                    ZMatrix m = new ZMatrix(numClusters, numClusters, a_b);
                    m.Calculation();
                    _r = m._result;
                    for (int i = 0; i < numClusters; i++)    //與fern1比較 將與fern1對應的cluster存入!!!!!!!
                    {
                        for (int j = 0; j < numClusters; j++)
                        {
                            if (_r[i].X == j)
                            {
                                _r1[b, j] = _r[i].Y;
                                break;
                            }
                        }
                    }
                    b++;
                }

                a++;
            }
            //-----------------------------------------------------------------------------------------
        }
        public List <Point> _r = new List <Point>();                                                                             //用於存取 指派問題 - 匈牙利法的結果
        private void Compared_Ferns(double[,] fernij, int fernsNumber, int numClusters, double[,] fernpcknumber, out int[,] _r1) //ferns size, sample size, cluster size
        {
            newFern = new double[numClusters];                                                                                   //存取newFerns(用來持續修正)
            //第一次比對(尚未開始加入修正的值)
            int a = 0;

            _r1 = new int[fernsNumber, numClusters];   //用來存取ferns之間cluster的對應
            //將fern1的cluster先放好 此動作只需要一次
            for (int i = 0; i < numClusters; i++)
            {
                _r1[a, i] = i;
            }
            if (fernsNumber == 1)
            {
            }
            else
            {
                int b = 1;
                while (b < fernsNumber)
                {
                    if (b == 1)
                    {
                        //--------------//這個動作只要一次--------
                        for (int i = 0; i < numClusters; i++)
                        {
                            for (int j = 0; j < numClusters; j++)
                            {
                                a_b[i, j] = Math.Abs(fernij[a, i] - fernij[b, j]);
                            }
                        }
                        //--------------//
                        //利用指派問題 - 匈牙利法 得到最佳的指派
                        ZMatrix m = new ZMatrix(numClusters, numClusters, a_b);
                        m.Calculation();
                        _r = m._result;
                        for (int i = 0; i < numClusters; i++)      //與fern1比較 將與fern1對應的cluster存入!!!!!!!
                        {
                            for (int j = 0; j < numClusters; j++)
                            {
                                if (_r[i].X == j)
                                {
                                    _r1[b, j] = _r[i].Y;
                                    break;
                                }
                            }
                        }
                        //-------------------------------------------------------------
                        //開始修正fern1值
                        for (int i = 0; i < numClusters; i++)
                        {
                            newNumber[i] = fernpcknumber[a, _r1[a, i]] + fernpcknumber[b, _r1[b, i]];
                            if (newNumber[i] == 0)
                            {
                                newFern[i] = 0;
                            }
                            else
                            {
                                newFern[i] = (fernij[a, _r1[a, i]] * fernpcknumber[a, _r1[a, i]] + fernij[b, _r1[b, i]] * fernpcknumber[b, _r1[b, i]]) / newNumber[i];
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < numClusters; i++)   //計算newFern與其他fern之值
                        {
                            for (int j = 0; j < numClusters; j++)
                            {
                                a_b[i, j] = Math.Abs(newFern[i] - fernij[b, j]);
                            }
                        }
                        ZMatrix m = new ZMatrix(numClusters, numClusters, a_b);
                        m.Calculation();
                        _r = m._result;

                        for (int i = 0; i < numClusters; i++)      //與fern1比較 將與fern1對應的cluster存入!!!!!!!
                        {
                            for (int j = 0; j < numClusters; j++)
                            {
                                if (_r[i].X == j)
                                {
                                    _r1[b, j] = _r[i].Y;
                                    break;
                                }
                            }
                        }
                        for (int i = 0; i < numClusters; i++)
                        {
                            newNumber[i] = newNumber[i] + fernpcknumber[b, _r1[b, i]];
                            newFern[i]   = ((newFern[_r1[a, i]] * newNumber[i]) + (fernij[b, _r1[b, i]]) * fernpcknumber[b, _r1[b, i]]) / newNumber[i];
                        }
                    }
                    b++;
                }
                //-----------------------------------------------------------------------------------------
            }
        }