Changeset dc76e58 in tol
- Timestamp:
- Sep 24, 2012, 7:00:08 PM (14 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- d404d85
- Parents:
- 411b46c
- File:
-
- 1 edited
-
tol/btol/bmodel/estim.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/btol/bmodel/estim.cpp
r411b46c rdc76e58 1597 1597 1598 1598 //-------------------------------------------------------------------- 1599 void BuildArimaFactor( 1600 const BSet& s, 1601 BArray<BARIMAFactor>& factor, 1602 int& p, 1603 int& q) 1604 //-------------------------------------------------------------------- 1605 { 1606 factor.ReallocBuffer(s.Card()); 1607 int i; 1608 for(i=p=q=0; i<s.Card(); i++) 1609 { 1610 BSet& si = Set(s[i+1]); 1611 factor(i).s_ = (BInt)Real(si.Field("Periodicity")); 1612 factor(i).dif_ = Pol(si.Field("DIF")); 1613 factor(i).ar_ = Pol(si.Field("AR")); 1614 factor(i).ma_ = Pol(si.Field("MA")); 1615 p += factor(i).ar_.Degree(); 1616 q += factor(i).ma_.Degree(); 1617 } 1618 } 1619 1620 //-------------------------------------------------------------------- 1599 1621 DeclareContensClass(BSet, BSetTemporary, BSetARIMALevinsonEval); 1600 1622 DefExtOpr(1, BSetARIMALevinsonEval, "ARIMALevinsonEval", 2, 4, "Set Matrix Real Real", … … 1649 1671 BDat sigma = (Arg(4))?Dat(Arg(4)):1.0; 1650 1672 BArray<BARIMAFactor> factor; 1651 factor.ReallocBuffer(s.Card()); 1652 1653 for(i=p=q=0; i<s.Card(); i++) 1654 { 1655 BSet& si = Set(s[i+1]); 1656 factor(i).s_ = (BInt)Real(si.Field("Periodicity")); 1657 factor(i).dif_ = Pol(si.Field("DIF")); 1658 factor(i).ar_ = Pol(si.Field("AR")); 1659 factor(i).ma_ = Pol(si.Field("MA")); 1660 p += factor(i).ar_.Degree(); 1661 q += factor(i).ma_.Degree(); 1662 } 1673 BuildArimaFactor(s,factor,p,q); 1663 1674 if(!(p+q)) 1664 1675 { … … 2403 2414 } 2404 2415 2416 2417 //-------------------------------------------------------------------- 2418 DeclareContensClass(BPol, BPolTemporary, BPolVec2Pol); 2419 DefExtOpr(1, BPolVec2Pol, "Vec2Pol", 2, 2, 2420 "Matrix Real", 2421 "(Matrix v, Real p)", 2422 "Returns the polynomial 'p' represented by a vector 'v' in this way:\n" 2423 "p(B) = 1 - v[1]*B^p - v[2]*B^2*p - ... \n" 2424 "The inverse function is Pol2Vec.", 2425 BOperClassify::Sthocastic_); 2426 //-------------------------------------------------------------------- 2427 void BPolVec2Pol::CalcContens() 2428 //-------------------------------------------------------------------- 2429 { 2430 BMatrix<BDat>& V = Mat(Arg(1)); 2431 const BArray<BDat>& vec = V.Data(); 2432 int d,n = vec.Size(); 2433 if(n==0) { contens_ = BPolyn<BDat>::One(); } 2434 else 2435 { 2436 int period = (int)Real(Arg(2)); 2437 contens_.AllocBuffer(n+1); 2438 contens_[0].PutDegree(0); 2439 contens_[0].PutCoef(1); 2440 for(d = 1; d<=n; d++) 2441 { 2442 contens_[d].PutDegree(d*period); 2443 contens_[d].PutCoef(-vec[d-1]); 2444 } 2445 } 2446 } 2447 2448 2449 //-------------------------------------------------------------------- 2450 DeclareContensClass(BMat, BMatTemporary, BMatPol2Vec); 2451 DefExtOpr(1, BMatPol2Vec, "Pol2Vec", 2, 2, "Polyn Real", 2452 "(Polyn p, Real p)", 2453 "Returns the column vector 'v' representing a polynomial 'p' in this way:\n " 2454 " p(B) = 1 - v[1]*B^p - v[2]*B^2*p - ... \n" 2455 "The inverse function is Vec2Pol.", 2456 BOperClassify::Sthocastic_); 2457 //-------------------------------------------------------------------- 2458 void BMatPol2Vec::CalcContens() 2459 //-------------------------------------------------------------------- 2460 { 2461 BPolyn<BDat>& pol = Pol(Arg(1)); 2462 int period =(int)Real(Arg(2)); 2463 int d,n = pol.Degree()/period; 2464 if(n<=0) 2465 { 2466 contens_.Alloc(0,1); 2467 } 2468 else 2469 { 2470 contens_.Alloc(n,1); 2471 BArray<BDat>& vec = contens_.GetData(); 2472 for(d = 1; d<=n; d++) { vec[d-1] = -pol.Coef(period*d); } 2473 } 2474 } 2475 2476 /* 2477 //-------------------------------------------------------------------- 2478 DeclareContensClass(BSet, BSetTemporary, BSetARIMAConditionalEstimate); 2479 DefExtOpr(1, BSetARIMAConditionalEstimate, "ARMAConditionalEstimate", 1, 4, "Set Date Date Set", 2480 "(Set arima, Matrix z [, Matrix w0, Matrix a0])", 2481 I2("Estimates by least squares approximation an ARIMA model " 2482 "conditioned by initial values", 2483 "Estima por la aproximación de mínimos cuadrados un modelo ARIMA " 2484 "condicionado por los valores iniciales"), 2485 BOperClassify::Sthocastic_); 2486 //-------------------------------------------------------------------- 2487 void BSetARIMAConditionalEstimate::CalcContens() 2488 //-------------------------------------------------------------------- 2489 { 2490 BInt i, p, q; 2491 BSet& s = Set(Arg(1)); 2492 BMat& z = Mat(Arg(2)); 2493 BMat w0, a0; 2494 if(Arg(3)) { w0 = Mat(Arg(3)); } 2495 if(Arg(4)) { a0 = Mat(Arg(4)); } 2496 BArray<BARIMAFactor> factor; 2497 BuildArimaFactor(s,factor,p,q); 2498 if(!(p+q)) 2499 { 2500 return; 2501 } 2502 BARIMA model; 2503 model.PutFactors(factor); 2504 model.PutOutputData(z); 2505 model.w0_ = w0; 2506 model.a0_ = a0; 2507 2508 BARIMAConditionalEstimation est(@model); 2509 est.Marquardt(); 2510 return; 2511 } 2512 2513 */
Note: See TracChangeset
for help on using the changeset viewer.
