//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; }
//------------------------------------- private qData clcACorrVar(double procent) { List<double> tVctr = new List<double>(Vctr.Count); //результат qData tData = new qData(); tData = this; int size = tData.size(); size = (int)(((double)size) / procent); for (int i = 0; i < tVctr.Count; i++) { //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: tVctr[i] = this->clcACorrVar(i, tData, size); tVctr[i] = this.clcACorrVar(i, new qData(tData), size); } tData.set(tVctr); return tData; }
//------------------------------------- /// <summary> /// Частная автокорреляционная функция /// </summary> /// <param name="Fkk"></param> /// <returns></returns> public List<List<double>> clcPCorrelation(qData Fkk) { int size = 0; size = this.Vctr.Count; List<List<double>> F = new List<List<double>>(size); for (int i = 1; i < size; i++) { F[i] = new List<double>(i + 1); } F[0] = new List<double>(size); F[1][1] = Vctr[1]; F[0][1] = F[1][1]; for (int p = 1; p < size - 1; p++) { double S1 = 0; double S2 = 0; for (int j = 1; j <= p; j++) { S1 = S1 + F[p][j] * Vctr[p + 1 - j]; } for (int j = 1; j <= p; j++) { S2 = S2 + F[p][j] * Vctr[j]; } F[p + 1][p + 1] = (Vctr[p + 1] - S1) / (1 - S2); for (int j = 1; j <= p; j++) { F[p + 1][j] = F[p][j] - F[p + 1][p + 1] * F[p][p + 1 - j]; S1 = F[p][j] - F[p + 1][p + 1] * F[p][p + 1 - j]; } F[0][p + 1] = F[p + 1][p + 1]; } List<double> tmp = F[0]; qData tData = new qData(tmp); Fkk.set(tData); return F; }
//------------------------------------- public qData clcMCovariation(double procent, qData aX, qData aY) { int sizeX; int sizeY; int size; sizeX = aX.size(); sizeY = aY.size(); size = (sizeX <= sizeY) ? sizeX : sizeY; size = (int)(((double)size) * procent + 0.5); List<double> tVctr = new List<double>(size); //вектор результата double C = 0; for (int i = 0; i < size; i++) { //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: C = clcMCovariation(i, aX, aY); C = clcMCovariation(i, new qData(aX), new qData(aY)); tVctr[i] = C; } qData tData = new qData(); tData.set(tVctr); return tData; }
//------------------------------------- //difference //------------------------------------- public qData clcDifference() { int size = this.Vctr.Count; List<double> tVctr = new List<double>(size); for (int i = 1; i < size; i++) { tVctr[i] = Vctr[i] - Vctr[i - 1]; } tVctr[0] = Vctr[0]; qData tData = new qData(); tData.set(tVctr); return tData; }
//------------------------------------- public qData clcDiffSeason(int s) { int size = this.Vctr.Count; List<double> tVctr = new List<double>(size); for (int i = s; i < size; i++) { tVctr[i] = Vctr[i] - Vctr[i - s]; } for (int i = 0; i < s; i++) { tVctr[i] = Vctr[i]; } qData tData = new qData(); tData.set(tVctr); return tData; }
//--------------------------------------------------------------------------- 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("Размер модели и маски не совпадает"); } }
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- 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; }
//--------------------------------------------------------------------------- /// <summary> /// Параметры модели /// </summary> /// <returns></returns> public qData getParam() { qData tData = new qData(); tData.set(Param); return tData; }
//--------------------------------------------------------------------------- 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(); // умножил маски на модели/???????????????????????????? }
//--------------------------------------------------------------------------- public qData getParamB() { qData tData = new qData(); tData.set(kB); return tData; }
//--------------------------------------------------------------------------- public qData getF(int k) { qData tData = new qData(); tData.set(F[k]); return tData; }
//--------------------------------------------------------------------------- //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#: //ORIGINAL LINE: qData getDis() const private qData getDis() { List<double> tVctr = new List<double>(); tVctr = DisD[DisD.Count - 1]; for (int i = 1; i < DisD.Count; i++) { for (int j = 0; j < S; j++) { // erase the 6th element //myvector.erase(myvector.begin() + 5); // erase the first 3 elements: //myvector.erase(myvector.begin(), myvector.begin() + 3); //tVctr.erase(tVctr.GetEnumerator()); tVctr.RemoveAt(0); } } qData tData = new qData(); tData.set(tVctr); return tData; }
//--------------------------------------------------------------------------- //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; } }
//--------------------------------------------------------------------------- private qData getDif() { List<double> tVctr = new List<double>(); tVctr = DifD[DifD.Count - 1]; for (int i = 1; i < DifD.Count; i++) { //tVctr.erase(tVctr.GetEnumerator()); tVctr.RemoveAt(0); } qData tData = new qData(); tData.set(tVctr); return tData; }