示例#1
0
 static public double[,] Correlation(params double[][] dataAr)
 {
     double[,] resCor = new double[1, 1];
     resCor[0, 0]     = double.NaN;
     if (dataAr.Length < 2)
     {
         return(resCor);
     }
     foreach (double[] el in dataAr)
     {
         if (el.Length != dataAr[0].Length || DataConvertationClass.IsUndefinedElement(el))
         {
             return(resCor);
         }
     }
     resCor = Covariation(dataAr);
     for (int i = 0; i < resCor.GetLength(0); i++)
     {
         double dsp1 = Dispersion(dataAr[i]);
         for (int j = 0; j < resCor.GetLength(1); j++)
         {
             if (i != j)
             {
                 double dsp2 = Dispersion(dataAr[j]);
                 resCor[i, j] = resCor[i, j] / (Math.Sqrt(dsp1 * dsp2));
             }
             else
             {
                 resCor[i, j] = 1;
             }
         }
     }
     return(resCor);
 }
示例#2
0
        static public double[] ACF(double[] dataAr, int degree)
        {
            double[] ACArray;
            if (degree < 0 || DataConvertationClass.IsUndefinedElement(dataAr))
            {
                ACArray = new double[] { double.NaN };
                return(ACArray);
            }
            ACArray    = new double[degree + 1];
            ACArray[0] = 1;
            double midd = Middle(dataAr);
            double c0   = 0;

            foreach (double el in dataAr)
            {
                c0 = c0 + Math.Pow((el - midd), 2);
            }
            double ck;

            for (int k = 1; k <= degree; k++)
            {
                ck = 0;
                for (int i = 0; i < dataAr.Length - k; i++)
                {
                    ck += (dataAr[i] - midd) * (dataAr[i + k] - midd);
                }
                ACArray[k] = ck / c0;
            }
            return(ACArray);
        }
示例#3
0
 static public double[] PACF(double[] dataAr, int degree)
 {
     double[] PACFArray;
     if (degree < 1 || DataConvertationClass.IsUndefinedElement(dataAr))
     {
         PACFArray = new double[] { double.NaN };
         return(PACFArray);
     }
     PACFArray = new double[degree + 1];
     double[] ACFArray = ACF(dataAr, degree);
     PACFArray[1] = ACFArray[1];
     for (int k = 2; k <= degree; k++)
     {
         double ch = 0;
         double zn = 0;
         for (int j = 1; j < k; j++)
         {
             ch += PACFij(PACFArray, k - 1, j) * ACFArray[k - j];
             zn += PACFij(PACFArray, k - 1, j) * ACFArray[j];
         }
         ch           = ACFArray[k] - ch;
         zn           = 1 - zn;
         PACFArray[k] = ch / zn;
     }
     return(PACFArray);
 }
示例#4
0
        static public double Middle(double[] dataAr)
        {
            if (DataConvertationClass.IsUndefinedElement(dataAr))
            {
                return(double.NaN);
            }
            double temp = 0;

            foreach (double el in dataAr)
            {
                temp = temp + el;
            }
            temp = temp / dataAr.Length;
            return(temp);
        }
示例#5
0
        static public double Dispersion(double[] dataAr)
        {
            if (DataConvertationClass.IsUndefinedElement(dataAr))
            {
                return(double.NaN);
            }
            double middl = Middle(dataAr);
            double disp  = 0;

            foreach (double el in dataAr)
            {
                disp = disp + Math.Pow((el - middl), 2);
            }
            disp = disp / (dataAr.Length - 1);
            return(disp);
        }
示例#6
0
        static private double Cov(double[] x, double[] y)
        {
            if (x.Length != y.Length || DataConvertationClass.IsUndefinedElement(x) || DataConvertationClass.IsUndefinedElement(y))
            {
                return(double.NaN);
            }
            double middX = Middle(x);
            double middY = Middle(y);

            double[] diffXY = new double[x.Length];
            for (int i = 0; i < x.Length; i++)
            {
                diffXY[i] = (x[i] - middX) * (y[i] - middY);
            }
            return(Middle(diffXY));
        }
示例#7
0
        static public double Kurtosis(double[] dataAr)
        {
            if (DataConvertationClass.IsUndefinedElement(dataAr))
            {
                return(double.NaN);
            }
            double dis   = Math.Sqrt(Dispersion(dataAr));
            double middl = Middle(dataAr);
            double kurt  = 0;

            foreach (double el in dataAr)
            {
                kurt = kurt + Math.Pow((el - middl) / dis, 4);
            }
            kurt = kurt / dataAr.Length;
            return(kurt);
        }
示例#8
0
        static public double Skewness(double[] dataAr)
        {
            if (DataConvertationClass.IsUndefinedElement(dataAr))
            {
                return(double.NaN);
            }
            double dis   = Math.Sqrt(Dispersion(dataAr));
            double middl = Middle(dataAr);
            double skew  = 0;

            foreach (double el in dataAr)
            {
                skew = skew + Math.Pow((el - middl) / dis, 3);
            }
            skew = skew / dataAr.Length;
            return(skew);
        }
示例#9
0
 static public double[,] Covariation(params double[][] dataAr)
 {
     double[,] resCov = new double[1, 1];
     resCov[0, 0]     = double.NaN;
     foreach (double[] el in dataAr)
     {
         if (el.Length != dataAr[0].Length || DataConvertationClass.IsUndefinedElement(el))
         {
             return(resCov);
         }
     }
     resCov = new double[dataAr.Length, dataAr.Length];
     for (int i = 0; i < dataAr.Length; i++)
     {
         for (int j = 0; j < i; j++)
         {
             resCov[i, j] = Cov(dataAr[i], dataAr[j]);
             resCov[j, i] = resCov[i, j];
         }
         resCov[i, i] = Cov(dataAr[i], dataAr[i]);
     }
     return(resCov);
 }