示例#1
0
文件: qMatrix.cs 项目: wouldyougo/EMD
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
 //ORIGINAL LINE: qMData operator + (qMData aMData) const
 public static qMData operator +(qMData ImpliedObject, qMData aMData)
 {
     qMData tMData = new qMData();
     tMData = ImpliedObject;
     tMData.mkAdd(aMData.get());
     return tMData;
 }
示例#2
0
文件: qMatrix.cs 项目: wouldyougo/EMD
 //---------------------------------------------------------------------------
 //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
 //ORIGINAL LINE: qMData operator * (double aD) const
 public static qMData operator *(qMData ImpliedObject, double aD)
 {
     List<List<double>> tMtrx = new List<List<double>>();
     tMtrx = ImpliedObject.get();
     int row = 0;
     int col = 0;
     row = tMtrx.Count;
     if (row != 0)
     {
         col = tMtrx[0].Count;
     }
     for (int i = 0; i < row; i++)
     {
         for (int j = 0; j < col; j++)
         {
             tMtrx[i][j] = tMtrx[i][j] * aD;
         }
     }
     qMData tMData = new qMData();
     tMData.set(tMtrx);
     return tMData;
 }
示例#3
0
        //---------------------------------------------------------------------------
        //---------------------------------------------------------------------------
        public qData revisionParam()
        {
            //для каждого Betta вычислить производную
            //сформировать матрицы А и g
            // нормировать матрицы А и g
            // найти h
            // вычислить поправки
            //oooooooooooooooooooooooooooooo
            //ofstream @out = new ofstream("tmpModArm.rpt");
            //@out << "Вычисление параметров модели АРСС";
            //@out << "\n";
            //oooooooooooooooooooooooooooooo

            double delta = 0.1;
            double cf_P = 0.1;
            // double cf_P = 2.0;
            double cf_E = 0.0001;
            double cf_F2 = 1.8;
            int p;
            int q;
            int k;
            int n;
            List<double> Zdm = new List<double>(); // ряд исхлдный

            p = this.Np;
            q = this.Nq;
            k = p + q;

            //   p = ModelAR.size();
            //   q = ModelMA.size();
            //   k = Model.size();

            Zdm = this.ZDM.get();
            n = Zdm.Count;
            List<double> A0 = new List<double>(n);
            List<double> Ab = new List<double>(n);
            List<double> B0 = new List<double>();
            List<double> Bd = new List<double>();
            List<double> BZero = new List<double>();
            BZero = this.Model.get();
            B0 = delZero(BZero, Mask);
            //Удалить 3 посл. значения - tetta0 SgmA2, M;   //B0.pop_back();   B0.pop_back();   B0.pop_back();
            //создал Х
            //List<List<double> > X = new List<List<double> >(k, List<double> (n, 0));
            List<List<double>> X = new List<List<double>>(k);
            for (int i = 0; i < k; i++)
            {
                X[i] = new List<double>(n);
            }

            // матрицы
            qMData MA = new qMData();
            qMData MG = new qMData(); // MG.set( MG.clcMtrx( G, G.size() ) );
            qMData MH = new qMData(); // MH.set( MH.clcMtrx( H, H.size() ) );
            try
            {
                for (int c = 0; c <= 100; c++)
                {
                    // заполнение Х-------------
                    BZero = addZero(B0, Mask);
                    this.forecast(BZero, Zdm, ref A0, 0);

                    for (int i = 0; i < k; i++)
                    {
                        Bd = B0;
                        Bd[i] = Bd[i] + delta;
                        BZero = addZero(Bd, Mask);
                        this.forecast(BZero, Zdm, ref Ab, 0);
                        for (int j = 0; j < n; j++)
                        {
                            X[i][j] = (A0[j] - Ab[j]) / delta;
                        }
                    }
                    // Заполнение А
                    //List<List<double> > A = new List<List<double> >(k, List<double> (k, 0));
                    List<List<double>> A = new List<List<double>>(k);
                    for (int i = 0; i < k; i++)
                    {
                        A[i] = new List<double>(k);
                    }

                    for (int i = 0; i < k; i++)
                    {
                        for (int j = 0; j < k; j++)
                        {
                            double S = 0;
                            for (int t = 0; t < n; t++)
                            {
                                S += X[i][t] * X[j][t];
                            }
                            A[i][j] = S;
                        }
                    }
                    // Заполнение G
                    List<double> G = new List<double>(k);
                    for (int i = 0; i < k; i++)
                    {
                        double S = 0;
                        for (int t = 0; t < n; t++)
                        {
                            S += X[i][t] * A0[t]; //+++++++++++++++++++++++
                        }
                        G[i] = S;
                    }
                    // нормирующие величины
                    List<double> D = new List<double>(k);
                    for (int i = 0; i < k; i++)
                    {
                        D[i] = Math.Sqrt(A[i][i]);
                    }
                    // модифицировать
                    for (int i = 0; i < k; i++)
                    {
                        for (int j = 0; j < k; j++)
                        {
                            if (i != j)
                            {
                                double delitel;
                                delitel = D[i] * D[j];
                                if (delitel != 0)
                                {
                                    A[i][j] = A[i][j] / delitel;
                                }
                            }
                            else
                            {
                                A[i][j] = 1 + cf_P;
                            }
                        }
                    }
                    for (int i = 0; i < k; i++)
                    {
                        if (D[i] != 0)
                        {
                            G[i] = G[i] / D[i];
                        }
                    }
                    //решение ур-Ыния Ah = g   // заполнить матр А и обратить   // умножить на g: H = Аобр*G
                    MA.set(A);
                    MG.set(MG.clcMtrx(G, G.Count));
                    //MA = MA.clcPIMatrix(MA.get());
                    throw new System.NotImplementedException();
                    MH = MA * MG;
                    List<double> H = new List<double>(k);
                    H = MH.clcVctr(MH.get());
                    for (int i = 0; i < k; i++)
                    {
                        if (D[i] != 0)
                        {
                            H[i] = H[i] / D[i];
                        }
                    }
                    for (int i = 0; i < k; i++)
                    {
                        Bd[i] = B0[i] + H[i];
                    }
                    // оценка остаточных ошибок
                    double Sb = 0;
                    double S0 = 0;
                    BZero = addZero(Bd, Mask);
                    this.forecast(BZero, Zdm, ref Ab, 0);
                    qData tClc = new qData();
                    S0 = tClc.clcAmountSquare(ref A0);
                    Sb = tClc.clcAmountSquare(ref Ab);

                    /*
                    @out << "Итерация:";
                    @out << "\t";
                    @out << c;
                    @out << "\n";
                    @out << "Текущие параметры:";
                    @out << "\n";
                    for(int i = 0; i < k; i++)
                    {
                       @out << "K[";
                       @out << i;
                       @out << "]:\t";
                       @out << B0[i];
                       @out << "\n";
                    }
                    @out << "Var(a): ";
                    @out << S0;
                    @out << "\n";
                    @out << "Вычисленные параметры:";
                    @out << "\n";
                    for(int i = 0; i < k; i++)
                    {
                       @out << "K[";
                       @out << i;
                       @out << "]:\t";
                       @out << Bd[i];
                       @out << "\n";
                    }
                    @out << "Var(a): ";
                    @out << Sb;
                    @out << "\n";
                       @out << "k_p: ";
                       @out << cf_P;
                       @out << "\n";
                       @out << "k_d: ";
                       @out << delta;
                       @out << "\n";
                    */

                    if (Sb < S0)
                    {
                        B0 = Bd;
                        //oooooooooooooooooooooooooooooo
                        //@out << "Параметры обновлены";
                        //@out << "\n";
                        //oooooooooooooooooooooooooooooo
                        // достигнута сходимость если: H[i] < e
                        bool flag = true;
                        for (int i = 0; i < k; i++)
                        {
                            if (!((H[i] > -cf_E) && (H[i] < cf_E)))
                            {
                                flag = false;
                            }
                        }
                        if (flag == true)
                        {
                            //++++++++++++++++
                            // запомнить А матрицу
                            // запомнить а для расчета автокорреляций
                            //ShowMessage("Число итераций:"+IntToStr(c));
                            break;
                        }
                        else
                        {
                            cf_P = cf_P / cf_F2;
                            if (cf_P < 0.001)
                            {
                                cf_P = 0.001;
                            }
                            //qwooooooooooooooooo
                            //delta = delta/cf_F2;
                            //if( delta < 0.001){
                            //    delta = 0.001;
                            //}//qwooooooooooooooooo
                        }
                    }
                    else
                    {
                        cf_P = cf_P * cf_F2;
                        if (cf_P > 8)
                        {
                            //cf_P = 5;
                            break;
                        }
                        //qwooooooooooooooooo
                        //delta = delta*cf_F2;
                        //if( delta > 0.1){
                        //   delta = 0.1;
                        //}//qwooooooooooooooooo
                    }
                }
                //------------------------------
            }
            catch
            {
                throw new System.ApplicationException("Исключение при уточнении параметров");
                //oooooooooooooooooooooooooooooo
                //@out.close();
                //oooooooooooooooooooooooooooooo
                return Model;
            }
            //------------------------
            List<double> PPar = new List<double>();
            List<double> QPar = new List<double>();
            BZero = addZero(B0, Mask);
            //PPar.AddRange(BZero.GetEnumerator(), BZero.GetEnumerator() + P);
            //QPar.AddRange(BZero.GetEnumerator()+P, BZero.GetEnumerator() + P+Q);
            throw new System.NotImplementedException();
            ModelAR.set(PPar);
            ModelMA.set(QPar);
            //------------------------
            //oooooooooooooooooooooooooooooo
            //@out.close();
            //oooooooooooooooooooooooooooooo
            qData tData = new qData();
            tData.set(BZero);
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
            //ORIGINAL LINE: Model = tData;
            Model.set(tData);
            return tData;
        }
示例#4
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;
        }
示例#5
0
        /*
        public List<List<double> > read(ref std.ifstream @in, int NPoint)
        {
              double TmpValue;
              int ColCount;
              List<List<double> > TmpMtrx = new List<List<double> >();
              TmpMtrx = new List<List<double> > (NPoint +2, List<double> (NPoint +2,0));

              ColCount = (NPoint/2) + 2;
              for(int i = 0; i< ColCount; i++)
              {
                 @in >> TmpValue;
              }
              //--------------------------
              for(int i = 0; i < NPoint +2; i++)
              {
                 for(int j = 0; j< ColCount; j++)
                 {
                    @in >> TmpValue;
                    TmpMtrx[i][j] = TmpValue;
                 }
              }
              for(int j = 0; j < ColCount-1; j++)
              {
                 List<double> TmpVctr = new List<double>(NPoint);
                 for(int i = 0; i < NPoint; i++)
                 {
                    TmpVctr[NPoint-1-i] = TmpMtrx[i][j];
                 }
                 for(int i = 0; i < NPoint; i++)
                 {
                    TmpMtrx[i][NPoint+2-1-j] = TmpVctr[i];
                 }
                 TmpMtrx[NPoint][NPoint+2-1-j] = TmpMtrx[NPoint][j];
                 TmpMtrx[NPoint+1][NPoint+2-1-j] = TmpMtrx[NPoint+1][j];
              }
              //--------------------------
              return TmpMtrx;
        }
         */
        public bool get(int a, int b, ref qMData aTableSs)
        {
            //проверка соответстви¤ параметров
            //да то ветнуть таблицу
            //иначе "по минимуму"
            try
            {
                //aTableSs = MultiSs[a-1].at(b-1);
                aTableSs = MultiSs[a - 1][b - 1];
                return true;
            }
            catch
            {
                aTableSs = MultiSs[0][2];
                return false;
            }
        }
示例#6
0
 public void setTbl(ref qMData aMData)
 {
     this.TblSs = aMData;
 }
示例#7
0
 public List<double> getVTblSs(int point)
 {
     List<List<double>> TblSs = new List<List<double>>();
     //TblSs = qModelSs.TblSs.get();
     TblSs = this.TblSs.get();
     List<double> VTblSs = new List<double>(TblSs.Count);
     for (int i = 0; i < TblSs.Count; i++)
     {
         VTblSs[i] = TblSs[i][point];
     }
     return VTblSs;
 }
示例#8
0
        //---------------------------------------------------------------------------
        //---------------------------------------------------------------------------
        private void clcPolParam()
        {
            int Low = 0; // Минимальная степень полинома
            int Degree = Poryd; // Степень полинома
            int n; // Число пар значений
            int Code; // Код ошибки
            //   double arg[] = {5,15,30,45,50};	      // Массив абсцисс
            //   double data[] = {37,34,33,29,20};	   // Массив ординат
            //   double *coeff;	                        // Массив коэффициентов
            //   double err = 0;	                     // Ошибка
            //   double buf;	                           // Рабочая переменная

            List<double> arg = new List<double>();
            List<double> data = new List<double>();
            List<double> coeff = new List<double>(Degree + 1);
            List<double> VData = new List<double>();

            VData = this.Data.get();
            //data.AddRange(VData.GetEnumerator(),VData.end());
            data.AddRange(VData);
            arg = new List<double>(data.Count);
            int MaxI = arg.Count + 1;
            for (int i = 1; i < MaxI; i++)
            {
                arg[i - 1] = i;
            }
            n = data.Count;
            qMData tMtrx = new qMData();
            //Code = tMtrx.Polynomial(data[0], arg[0], Low, Degree, n, coeff[0]);
            Code = tMtrx.Polynomial(data, arg, Low, Degree, n, coeff);
            //throw new System.NotImplementedException();
            if ((Code == -1) || (Code == -2))
            {
                //ShowMessage("Ошибка при построении полинома");
                throw new System.ApplicationException("Ошибка при построении полинома");
            }
            //результат
            Param.AddRange(coeff);
        }
示例#9
0
文件: qMatrix.cs 项目: wouldyougo/EMD
 //---------------------------------------------------------------------------
 public qMData(qMData aMData)
 {
     this.Mtrx = aMData.get();
 }
示例#10
0
文件: qMatrix.cs 项目: wouldyougo/EMD
        public List<List<double>> clcPIMatrix2(List<List<double>> aMtrx)
        {
            qMData A = new qMData();
            qMData B = new qMData();
            qMData F = new qMData();
            qMData C = new qMData();
            qMData I = new qMData();
            A.set(aMtrx);
            A.set(clcMtrx(clcVctr(A.get()), A.getCol()));

            int i;
            int n = A.getRow();
            int m = A.getCol();
            I.set(clcI(m, m));
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
            //ORIGINAL LINE: F = I;
            F = I;
            C.set(clcTrnsp(A.get()));
            C = C * A;
            double f = clcTrace(C.get());
            for (i = 0; i < m && i < n; i++)
            {
                qMData F1 = new qMData();
                qMData D1 = new qMData();
                F1 = I * f;
                D1 = C * F;
                F1 = F1 - D1;
                D1 = C * F1;
                double f1 = clcTrace(D1.get());
                f1 = f1 / (i + 2);
                if (f1 < 0.000000001 && f1 > -0.000000001)
                    break;
                f = f1;
                //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
                //ORIGINAL LINE: F = F1;
                F = F1;
            }
            qMData D = new qMData();
            D.set(clcTrnsp(A.get()));
            B = F * D;
            B = B * (1.0 / f);
            List<List<double>> tMtrx = new List<List<double>>(); //--
            B.set(clcMtrx(clcVctr(B.get()), B.getCol()));
            tMtrx = B.get(); //--
            int mm = tMtrx.Count; //--
            int nn = tMtrx[0].Count; //--
            return B.get();
        }
示例#11
0
文件: qMatrix.cs 项目: wouldyougo/EMD
 public void set(qMData aMData)
 {
     this.Mtrx = aMData.get();
 }