Пример #1
0
 //---------------------------------------------------------------------------
 public qData(qData aData)
 {
     //    int size = 0;
     //    size = aData.get().size();
     this.Vctr = aData.get();
     //    size = this->Vctr.size();
 }
Пример #2
0
 //copy
 //---------------------------------------------------------------------------
 public qData AddRange(qData aData)
 {
     List<double> tVctr1 = new List<double>();
     List<double> tVctr2 = new List<double>();
     tVctr1 = aData.get();
     tVctr2 = this.Vctr;
     tVctr2.AddRange(tVctr1);
     qData tData = new qData();
     tData.set(tVctr2);
     return tData;
 }
Пример #3
0
 public void set(qData aData)
 {
     this.Vctr = aData.get();
 }
Пример #4
0
 //-------------------------------------
 //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
 //ORIGINAL LINE: double clcMCovariation(int k, qData aX, qData aY)const
 public double clcMCovariation(int k, qData aX, qData aY)
 {
     int sizeX;
     int sizeY;
     int size;
     sizeX = aX.size();
     sizeY = aY.size();
     size = (sizeX <= sizeY) ? sizeX : sizeY;
     if (size != 0)
     {
         double MX;
         double MY;
         List<double> X = new List<double>();
         List<double> Y = new List<double>();
         if (k >= 0)
         {
             X = aX.get();
             Y = aY.get();
             MX = aX.clcMid();
             MY = aY.clcMid();
         }
         else
         {
             k = -k;
             X = aY.get();
             Y = aX.get();
             MX = aY.clcMid();
             MY = aX.clcMid();
         }
         //int sizeX;
         //int sizeY;
         //int size;
         sizeX = X.Count;
         sizeY = Y.Count;
         size = (sizeX <= sizeY) ? sizeX : sizeY;
         double C = 0;
         for (int i = 0; i < size - k; i++)
         {
             C += (X[i] - MX) * (Y[i + k] - MY);
         }
         C /= (double)size;
         return C;
     }
     else
     {
         return 0;
     }
 }
Пример #5
0
 //-------------------------------------
 public qData clcACorrSgmMin(qData aACSgm)
 {
     List<double> tVctr = new List<double>(); //результат
     tVctr = aACSgm.get();
     for (int i = 0; i < tVctr.Count; i++)
     {
         tVctr[i] = -tVctr[i];
     }
     qData tData = new qData(tVctr);
     return tData;
 }
Пример #6
0
 //-------------------------------------
 /// <summary>
 /// вычислит сезонную разность  
 /// </summary>
 /// <param name="s">s - порядок сезона</param>
 /// <param name="d">d - порядок разности</param>
 /// <returns></returns>
 public List<List<double>> clcDiffMatrix(int s, int d)
 {
     List<List<double>> tM = new List<List<double>>(d + 1);
     qData tData = new qData();
     tData = this;
     tM[0] = Vctr;
     for (int i = 1; i <= d; i++)
     {
         tData = tData.clcDiffSeason(s);
         tM[i] = tData.get();
     } // tData.difference().get();
     return tM;
 }
Пример #7
0
 //---------------------------------------------------------------------------
 //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
 //ORIGINAL LINE: qData clcParamMAL2(int p, int q, qData aF) const
 private qData clcParamMAL2(int p, int q, qData aF)
 {
     List<double> F = new List<double>();
     F = aF.get();
     List<double> newACov = new List<double>(q + 1);
     //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
     //ORIGINAL LINE: newACov = clcNewCov(p,q,aF);
     newACov = clcNewCov(p, q, new qData(aF));
     //------------------------------    //------------------------------
     //линейно сходящийся процесс
     //Sgm(a)2
     List<double> Tetta = new List<double>(q + 1); // Tetta[0] = Sgm(a)2
     Tetta[0] = newACov[0];
     for (int j = q; j > 0; j--)
     {
         double S1 = 0;
         for (int i = 1; i <= q - j; i++)
         {
             S1 = Tetta[i] * Tetta[j + i];
         }
         Tetta[j] = -(newACov[j] / Tetta[0] - S1);
     }
     //------------------------------    //------------------------------
     //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent to the STL vector 'erase' method in C#:
     Tetta.RemoveAt(0);
     qData tData = new qData(Tetta);
     return tData;
 }
Пример #8
0
        //---------------------------------------------------------------------------
        public void clcMCov()
        {
            qData tData = new qData();
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
            //ORIGINAL LINE: tData = tData.clcMCovariation(Procent, X, Y);
            tData = tData.clcMCovariation(Procent, new qData(X), new qData(Y));
            List<double> tVctr = new List<double>();
            tVctr = tData.get();
            this.Data.set(tVctr);

            //   qACorr ACorr;
            //   ACorr.set( X, Koeff, Procent);
            //   this->Prognos.set(ACorr.getAcorrSgm());
            //   this->A.set(ACorr.getAcorrSgmM());
            //   ACorr.clear();
        }
Пример #9
0
 //---------------------------------------------------------------------------
 public void clcModel(int metod)
 {
     ModelMA.clear();
     if (Q > 0)
     {
         if (metod == 0) // квадратически сход.
         {
             ModelMA = clcParamMAK(P, Q, this.PCorr.getF(P));
         }
         else
             if (metod == 1) // линейно сход.
             {
                 ModelMA = clcParamMAL(P, Q, this.PCorr.getF(P));
             }
             else
                 if (metod == 2) // линейно сход.
                 {
                     ModelMA = clcParamMAL2(P, Q, this.PCorr.getF(P));
                 }
     }
     // убрать первый 0 из модели АР
     ModelAR.clear();
     if (P > 0)
     {
         ModelAR = this.PCorr.getF(P);
         List<double> tVctr = new List<double>();
         tVctr = ModelAR.get();
         //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent to the STL vector 'erase' method in C#:
         tVctr.RemoveAt(0);
         ModelAR.set(tVctr);
     }
     else
     {
         ModelAR.clear();
     }
     //this->Model = ModelAR.add(ModelMA);
     this.updateMask(); // создал маску /????????????????????????????
     this.mkMaskModel(); // умножил маски на модели/????????????????????????????
 }
Пример #10
0
        //---------------------------------------------------------------------------
        //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
        //ORIGINAL LINE: qData clcParamMAL(int ap, int aq, qData aF) const
        private qData clcParamMAL(int ap, int aq, qData aF)
        {
            int p = ap;
            int q = aq;

            List<double> F = new List<double>();
            F = aF.get();

            List<double> newACov = new List<double>(q + 1);
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
            //ORIGINAL LINE: newACov = clcNewCov(p,q,aF);
            newACov = clcNewCov(p, q, new qData(aF));
            /*
            ofstream @out = new ofstream("tmpModArm.rpt");
            @out << "Предварительные оценки параметров скользящего среднего";
            @out << "\n";
            @out << "Линейно сходящийся процесс";
            @out << "\n";
            */
            //------------------------------    //------------------------------
            //линейно сходящийся процесс
            //Sgm(a)2
            List<double> Tetta = new List<double>(q + 1);
            List<double> TettaBk = new List<double>(q + 1);
            try
            {
                int MaxCount = 20;
                for (int i = 0; i < MaxCount; i++)
                {
                    //-------------------------
                    // Выч. SgmA2
                    double S = 0;
                    double SgmA2 = 0;
                    for (int j = 1; j <= q; j++)
                    {
                        S += Tetta[j] * Tetta[j];
                    }
                    SgmA2 = newACov[0] / (1 + S);
                    //-------------------------
                    // Выч. TeTTы
                    for (int j = q; j > 0; j--)
                    {
                        double S1 = 0;
                        for (int k = 1; k <= q - j; k++)
                        {
                            S1 += Tetta[k] * Tetta[j + k]; ///????????????
                        }
                        double drob = 0;
                        if (SgmA2 != 0)
                        {
                            drob = newACov[j] / SgmA2;
                        }
                        Tetta[j] = -(drob - S1);
                    }
                    //-------------------------
                    bool flag = true;
                    for (int j = 1; j <= q; j++)
                    {
                        double delta = 0;
                        delta = TettaBk[j] - Tetta[j];
                        if (!((delta > -0.0001) && (delta < 0.0001)))
                        {
                            flag = false;
                            break;
                        }
                    }
                    TettaBk = Tetta;
                    /*
                       @out << "Итерация:";
                       @out << "\t";
                       @out << i;
                       @out << "\n";
                    for(int j = 1; j <= q; j++)
                    {
                       @out << "Тетта[";
                       @out << j;
                       @out << "]:\t";
                       @out << Tetta[j];
                       @out << "\n";
                    }
                       @out << "Var(a): ";
                       @out << SgmA2;
                       @out << "\n";
                    */
                    if (flag)
                    {
                        //ShowMessage("ЛСП число итераций:"+IntToStr(i)); ///////////////////////////
                        break;
                    }
                    if (i == MaxCount - 1)
                    {
                        throw new System.ApplicationException();
                    }
                }
                //------------------------------    //------------------------------
            }
            catch
            {
                //ShowMessage("clcParamMAL исключение: линейно сходящийся процесс"); ///////
                //oooooooooooooooooooooooooooooo
                //@out.close();
                //oooooooooooooooooooooooooooooo
                //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
                //ORIGINAL LINE: return clcParamMAL2(p,q,aF);
                return clcParamMAL2(p, q, new qData(aF));
            }
            //------------------------------    //------------------------------
            //oooooooooooooooooooooooooooooo
            //@out.close();
            //oooooooooooooooooooooooooooooo
            //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent to the STL vector 'erase' method in C#:
            Tetta.RemoveAt(0); // удалить Tetta0
            qData tData = new qData(Tetta);
            return tData;
        }
Пример #11
0
        //---------------------------------------------------------------------------
        //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
        //ORIGINAL LINE: qData clcParamMAK(int ap, int aq, qData aF) const
        private qData clcParamMAK(int ap, int aq, qData aF)
        {
            int p = ap;
            int q = aq;

            List<double> F = new List<double>();
            F = aF.get();

            List<double> newACov = new List<double>(q + 1);
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
            //ORIGINAL LINE: newACov = clcNewCov(p,q,aF);
            newACov = clcNewCov(p, q, new qData(aF));
            /*
            ofstream @out = new ofstream("tmpModArm.rpt");
            @out << "Предварительные оценки параметров скользящего среднего";
            @out << "\n";
            @out << "Квадратически сходящийся процесс";
            @out << "\n";
            */
            //------------------------------    //------------------------------
            //квадратически сходящийся процесс
            //------------------------------    // newACov[0] = 1.25; // newACov[1] = -0.5;
            List<double> Tau = new List<double>(q + 1);
            Tau[0] = Math.Sqrt(newACov[0]); // Tau[0] = Sgm(a)
            List<double> f = new List<double>(q + 1);
            //List<List<double> > T1 = new List<List<double> >(q+1, List<double> (q+1,0));
            List<List<double>> T1 = new List<List<double>>(q + 1);
            for (int i = 0; i < q + 1; i++)
            {
                T1[i] = new List<double>(q + 1);
            }
            //List<List<double> > T2 = new List<List<double> >(q+1, List<double> (q+1,0));
            List<List<double>> T2 = new List<List<double>>(q + 1);
            for (int i = 0; i < q + 1; i++)
            {
                T2[i] = new List<double>(q + 1);
            }
            qMData TAU = new qMData();
            TAU.set(TAU.clcMtrx(Tau, Tau.Count));
            qMData t1 = new qMData();
            qMData t2 = new qMData();
            qMData T = new qMData();
            qMData FF = new qMData();
            //------------------------------
            List<double> Tetta;
            try
            {
                int MaxCount = 30;
                for (int i = 0; i < MaxCount; i++)
                {
                    //------------------------------
                    for (int j = 0; j <= q; j++)
                    {
                        double s = 0;
                        for (int k = 0; k <= q - j; k++)
                        {
                            s += Tau[k] * Tau[k + j];
                        }
                        f[j] = s - newACov[j];
                    }
                    FF.set(FF.clcMtrx(f, f.Count));
                    //------------------------------
                    //T1 = new List<List<double> > (q+1, List<double> (q+1,0));
                    T1 = new List<List<double>>(q + 1);
                    for (int j = 0; j < q + 1; j++)
                    {
                        T1[j] = new List<double>(q + 1);
                    }
                    //T2 = new List<List<double> > (q+1, List<double> (q+1,0));
                    T2 = new List<List<double>>(q + 1);
                    for (int j = 0; j < q + 1; j++)
                    {
                        T2[j] = new List<double>(q + 1);
                    }

                    for (int j = 0; j <= q; j++)
                    {
                        //std.copy(Tau.GetEnumerator()+j,Tau.end(), T1[j].GetEnumerator());
                        //std.copy(Tau.GetEnumerator(), Tau.end()-i,T2[j].GetEnumerator()+j);
                        throw new System.NotImplementedException();
                        ;
                    }
                    t1.set(T1);
                    t2.set(T2);
                    T = t1 + t2;
                    //T = T.clcPIMatrix(T.get()); // T1 = T.get();//++++++++++++++
                    throw new System.NotImplementedException();

                    ////T = T.clcInverseMatrix( T.get() );   //      T1 = T.get();//++++++++++++++
                    //------------------------------
                    FF = T * FF; // h = FF // T1 = FF.get();//++++++++++++++
                    TAU = TAU - FF; // Tau = Tau - h // T1 = TAU.get();//++++++++++++++
                    Tau = TAU.clcVctr(TAU.get());
                    //------------------------------
                    /*
                    @out << "Итерация:";
                    @out << "\t";
                    @out << i;
                    @out << "\n";
                     */
                    Tetta = new List<double>(q + 1);
                    for (int j = 1; j <= q; j++)
                    {
                        Tetta[j] = -(Tau[j] / Tau[0]);
                        /*
                        @out << "Тетта[";
                        @out << i;
                        @out << "]:\t";
                        @out << Tetta[i];
                        @out << "\n";
                         */
                    }
                    //@out << "Var(a): ";
                    //@out << Tau[0]*Tau[0];
                    //@out << "\n";
                    //oooooooooooooooooooooooooooooo
                    bool flag = true;
                    for (int j = 0; j <= q; j++)
                    {
                        if (!((f[j] > -0.005) && (f[j] < 0.005)))
                        {
                            flag = false;
                        }
                    }
                    if (flag)
                    {
                        //ShowMessage("КСП число итераций:"+IntToStr(i)); ////////////////////////////
                        break;
                    }
                    if (i == MaxCount - 1)
                    {
                        throw new System.ApplicationException();
                    }
                }
                //------------------------------
            }
            catch
            {
                //ShowMessage("clcParamMAK исключение: квадратически сходящийся процесс");///
                //oooooooooooooooooooooooooooooo
                //@out.close();
                //oooooooooooooooooooooooooooooo
                //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
                //ORIGINAL LINE: return clcParamMAL2(p,q,aF);
                return clcParamMAL2(p, q, new qData(aF));
            }
            //------------------------------   //------------------------------
            Tetta = new List<double>(q + 1);
            Tetta = new List<double>(q + 1);
            for (int i = 1; i <= q; i++)
            {
                Tetta[i] = -(Tau[i] / Tau[0]);
            }
            //------------------------------   //------------------------------
            //oooooooooooooooooooooooooooooo
            //@out.close();
            //oooooooooooooooooooooooooooooo
            //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent to the STL vector 'erase' method in C#:
            Tetta.RemoveAt(0); // удалить Tetta0
            qData tData = new qData(Tetta);
            return tData;
        }
Пример #12
0
        //---------------------------------------------------------------------------
        private List<double> clcNewCov2(int p, int q, qData aF)
        {
            List<double> aACov = new List<double>();
            List<double> F = new List<double>();
            aACov = ZDM.clcACovariation().get();
            F = aF.get();
            if (F.Count < p + 1)
            {
                throw new System.ApplicationException("Недопустимая операция qModelArm::clcParamMAK");
            }

            //вычислени новых ковариаций
            List<double> newACov = new List<double>(q + 1);
            if (p == 0)
            {
                newACov = aACov;
            }
            else
            {
                F[0] = -1;
                for (int j = 0; j <= q; j++)
                {
                    double S1 = 0;
                    for (int i = 0; i <= p; i++)
                    {
                        S1 += F[i] * F[i] * aACov[j];
                    }
                    double S2 = 0;
                    for (int i = 1; i <= p; i++)
                    {
                        double S3 = 0;
                        for (int k = 0; k <= p - i; k++)
                        {
                            S3 += F[k] * F[i + k];
                        }
                        S3 *= (aACov[j + i] + aACov[j - i]);
                        S2 += S3;
                    }
                    newACov[j] = S1 + S2;
                }
            }
            //------------------------------   //------------------------------
            //    s += F[i]*aACov[i]; } SgmA2 = aACov[0] - s; }else{ SgmA2 = newACov[0]; }
            // оценка SgmA2
            if (q == 0)
            {
                double s = 0;
                for (int i = 1; i <= p; i++)
                {
                    s += F[i] * newACov[i];
                }
                stSgmA2 = newACov[0] - s;
            }
            else
            {
                stSgmA2 = newACov[0];
            }
            //------------------------------   //------------------------------
            // оценка Tetta0
            if (p == 0)
            {
                stTetta = ZDM.clcMid();
            }
            else
            {
                double Wstrh = ZDM.clcMid();
                double s = 0;
                for (int i = 1; i <= p; i++)
                {
                    s += F[i];
                }
                stTetta = Wstrh * (1 - s);
            }
            //------------------------------   //------------------------------
            return newACov;
        }
Пример #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="aData"></param>
 public virtual void set(qData aData)
 {
     List<double> tVctr = new List<double>();
     tVctr = aData.get();
     Data.set(aData);
 }
Пример #14
0
 //-------------------------------------
 private qData clcACorrSgm(qData aCorr, double k)
 {
     List<double> tVctr = new List<double>(); //результат
     tVctr = aCorr.get();
     for (int i = 0; i < tVctr.Count; i++)
     {
         tVctr[i] = Math.Sqrt(k * tVctr[i]);
     }
     qData tData = new qData(tVctr);
     return tData;
 }
Пример #15
0
        //---------------------------------------------------------------------------
        public void mkMaskModel()
        {
            List<double> mdl = new List<double>();
            List<double> mdlAR = new List<double>();
            List<double> mdlMA = new List<double>();

            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
            //ORIGINAL LINE: this->Model = ModelAR.add(ModelMA);
            this.Model = ModelAR.AddRange(new qData(ModelMA));
            mdl = Model.get();
            mdlAR = ModelAR.get();
            mdlMA = ModelMA.get();

            try
            {
                int size;
                size = Mask.Count;
                for (int i = 0; i < size; i++)
                {
                    mdl[i] = mdl[i] * Mask[i];
                }
                size = MaskAR.Count;
                for (int i = 0; i < size; i++)
                {
                    mdlAR[i] = mdlAR[i] * MaskAR[i];
                }
                size = MaskMA.Count;
                for (int i = 0; i < size; i++)
                {
                    mdlMA[i] = mdlMA[i] * MaskMA[i];
                }

                Model.set(mdl);
                ModelAR.set(mdlAR);
                ModelMA.set(mdlMA);

            }
            catch
            {
                throw new System.ApplicationException("Размер модели и маски не совпадает");
            }
        }
Пример #16
0
 //-------------------------------------
 private double clcACorrVar(int k, qData aData, int size)
 {
     double Var = 0;
     if (k < aData.size())
     {
         List<double> tVctr = new List<double>(aData.get());
         for (int i = 1; i < k; i++)
         {
             Var += (tVctr[i]) * (tVctr[i]);
         }
         Var = (1 + 2 * Var) / size;
     }
     else
     {
         //ShowMessage("Недопустимая операция 2 qData");
         ;
     }
     return Var;
 }
Пример #17
0
        //---------------------------------------------------------------------------
        //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
        //ORIGINAL LINE: qData clcPrognos(qData DisFor) const
        private qData clcPrognos(qData DisFor)
        {
            List<List<double>> tDisD = new List<List<double>>(DisD);
            List<List<double>> tDisN = new List<List<double>>(DisD);
            List<double> tVDisFor = DisFor.get();
            if (D > 0)
            {
                int sizeF = DisFor.get().Count;
                int sizeD = tDisD[D].Count;
                int sizeDmD = sizeD - D * S;
                int distance = sizeF - (sizeD - D * S);
                if (sizeF >= sizeDmD)
                {
                    for (int i = D * S; i < sizeD; i++)
                    {
                        tDisN[D][i] = tVDisFor[i - D * S];
                        for (int j = 1; j <= D; j++)
                        {
                            tDisN[D - j][i] = tDisD[D - j][i - S] + tDisN[D - j + 1][i];
                        }
                    }

                    for (int i = 0; i < distance; i++)
                    {
                        tDisN[D].Add(tVDisFor[sizeDmD + i]);
                        for (int j = 1; j <= D; j++)
                        {
                            //               tDisN[D-j].push_back( tDisD[D-j].back()+ tDisN[D-j+1].back() );
                            int ind = tDisD[D - j].Count - S;
                            tDisN[D - j].Add(tDisN[D - j][ind] + tDisN[D - j + 1][tDisN[D - j + 1].Count - 1]);
                        }
                    }
                }
                qData tData = new qData();
                tData.set(tDisN[0]);
                return tData;
            }
            else
            {
                return DisFor;
            }
        }