예제 #1
0
        private void CalHao(SequenceData seqX, SequenceData seqY, Result result, int k, int m = 0)
        {
            if (k < 2)
            {
                return;
            }

            if (result.ContiansKeys("Hao_k" + k))
            {
                return;
            }

            double resultHao = 0;
            double tmpXY     = 0;
            double tmpX      = 0;
            double tmpY      = 0;
            double tmp1      = 0;
            double tmp2      = 0;
            double fXi       = 0;
            double fYi       = 0;

            List <int>    listKtupleX = seqX.GetKtupleData(k);
            List <double> listPosX    = seqX.GetMarkovData(k, k - 2);
            int           totalX      = seqX.GetTotal(k);

            List <int>    listKtupleY = seqY.GetKtupleData(k);
            List <double> listPosY    = seqY.GetMarkovData(k, k - 2);
            int           totalY      = seqY.GetTotal(k);

            for (int i = 0; i < listKtupleY.Count; i++)
            {
                fXi = listKtupleX[i] * 1.0 / totalX;
                fYi = listKtupleY[i] * 1.0 / totalY;
                if (listPosX[i] == 0)
                {
                    tmp1 = -1;
                }
                else
                {
                    tmp1 = (fXi / listPosX[i]) - 1;
                }
                if (listPosY[i] == 0)
                {
                    tmp2 = -1;
                }
                else
                {
                    tmp2 = (fYi / listPosY[i]) - 1;
                }
                tmpXY += tmp1 * tmp2;
                tmpX  += tmp1 * tmp1;
                tmpY  += tmp2 * tmp2;
            }
            tmpX      = Math.Sqrt(tmpX);
            tmpY      = Math.Sqrt(tmpY);
            resultHao = (1 - tmpXY / (tmpX * tmpY)) / 2;
            SaveResult("Hao_k" + k, seqX, seqY, result, resultHao);
            //result.AddToMatrix("Hao_k" + k, seqX.ID, seqY.ID, resultHao);
            //result.AddToMatrix("Hao_k" + k, seqY.ID, seqX.ID, resultHao);
        }
예제 #2
0
        private void CalD2Star(SequenceData seqX, SequenceData seqY, Result result, int k, int m)
        {
            if (k < 3)
            {
                return;
            }
            //public
            List <int>    listKtupleX = seqX.GetKtupleData(k);
            List <double> listPosX    = seqX.GetMarkovData(k, m);
            double        totalX      = seqX.GetTotal(k);

            List <int>    listKtupleY = seqY.GetKtupleData(k);
            List <double> listPosY    = seqY.GetMarkovData(k, m);
            double        totalY      = seqY.GetTotal(k);

            //D2Star
            double tmpXD2Star   = 0;
            double tmpYD2Star   = 0;
            double resultD2Star = 0;

            for (int i = 0; i < listKtupleX.Count; i++)
            {
                //public
                double cXi     = listKtupleX[i];
                double cYi     = listKtupleY[i];
                double pXi     = listPosX[i];
                double pYi     = listPosY[i];
                double tmpX    = totalX * pXi;
                double tmpY    = totalY * pYi;
                double cXi_bar = cXi - tmpX;
                double cYi_bar = cYi - tmpY;
                double tmp1    = cXi_bar * cXi_bar;
                double tmp2    = cYi_bar * cYi_bar;


                double tmp3 = Math.Sqrt(tmpX * tmpY);
                if (tmpX == 0)
                {
                    tmpX = tmp3 = 1;
                }
                if (tmpY == 0)
                {
                    tmpX = tmp3 = 1;
                }
                resultD2Star += cXi_bar * cYi_bar / tmp3;
                tmpXD2Star   += tmp1 / tmpX;
                tmpYD2Star   += tmp2 / tmpY;
            }

            //D2Star

            tmpXD2Star   = Math.Sqrt(tmpXD2Star);
            tmpYD2Star   = Math.Sqrt(tmpYD2Star);
            resultD2Star = 0.5 * (1 - resultD2Star / (tmpXD2Star * tmpYD2Star));
            SaveResult("D2Star_k" + k + "_M" + m, seqX, seqY, result, resultD2Star);
            //result.AddToMatrix("D2Star_k" + k + "_M" + m, seqX.ID, seqY.ID, resultD2Star);
            //result.AddToMatrix("D2Star_k" + k + "_M" + m, seqY.ID, seqX.ID, resultD2Star);
        }
예제 #3
0
        private void CalD2S(SequenceData seqX, SequenceData seqY, Result result, int k, int m)
        {
            if (k < 3 || k == m)
            {
                return;
            }
            //public
            List <int>    listKtupleX = seqX.GetKtupleData(k);
            List <double> listPosX    = seqX.GetMarkovData(k, m);
            double        totalX      = seqX.GetTotal(k);

            List <int>    listKtupleY = seqY.GetKtupleData(k);
            List <double> listPosY    = seqY.GetMarkovData(k, m);
            double        totalY      = seqY.GetTotal(k);


            //D2S
            double resultD2S = 0;
            double tmpD2S    = 0;

            //double tmpXD2S = 0;
            //double tmpYD2S = 0;

            for (int i = 0; i < listKtupleX.Count; i++)
            {
                //public
                double cXi     = listKtupleX[i];
                double cYi     = listKtupleY[i];
                double pXi     = listPosX[i];
                double pYi     = listPosY[i];
                double tmpX    = totalX * pXi;
                double tmpY    = totalY * pYi;
                double cXi_bar = cXi - tmpX;
                double cYi_bar = cYi - tmpY;
                double tmp1    = cXi_bar * cXi_bar;
                double tmp2    = cYi_bar * cYi_bar;



                tmpD2S = Math.Sqrt(tmp1 + tmp2);
                if (tmpD2S == 0)
                {
                    tmpD2S = 1;
                }
                resultD2S += cXi_bar * cYi_bar / tmpD2S;
                //tmpXD2S += tmp1 / tmpD2S;
                //tmpYD2S += tmp2 / tmpD2S;
            }

            //tmpXD2S = Math.Sqrt(tmpXD2S);
            //tmpYD2S = Math.Sqrt(tmpYD2S);
            //resultD2S = (1 - resultD2S / (tmpXD2S * tmpYD2S)) * 0.5;

            SaveResult("D2S_k" + k + "_M" + m, seqX, seqY, result, resultD2S);

            //result.AddToMatrix("D2S_k" + k + "_M" + m, seqX.ID, seqY.ID, resultD2S);
            //result.AddToMatrix("D2S_k" + k + "_M" + m, seqY.ID, seqX.ID, resultD2S);
        }