Changeset 7427dd4c in tol
- Timestamp:
- Mar 27, 2012, 5:40:33 PM (15 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- c8a5446
- Parents:
- d072dc9
- Location:
- tol/btol
- Files:
-
- 3 edited
-
bmodel/estim.cpp (modified) (4 diffs)
-
polynomial_type/polgra.cpp (modified) (3 diffs)
-
polynomial_type/tol_bpolgra.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tol/btol/bmodel/estim.cpp
rd072dc9 r7427dd4c 1369 1369 { 1370 1370 cov.Alloc(n,n); 1371 int i,j,k,s ;1371 int i,j,k,s=s_; 1372 1372 BArray<BDat> bf(n); 1373 for(s=s_; s> 10; s--)1373 for(s=s_; s>=n+1; s--) 1374 1374 { 1375 1375 if(Abs(rho.Data()(s-1))>1.E-6) { break; } … … 1387 1387 { 1388 1388 bf(i) = _getACF_BartlettFactor(rho,k,i+1); 1389 //Std(BText("\nTRACE _covACF_Bartlett bf(")+i+")="+bf(i)) 1389 1390 } 1390 1391 for(i=0; i<n; i++) … … 1432 1433 1433 1434 //-------------------------------------------------------------------- 1434 DeclareContensClass(BDat, BDatTemporary, BDatARMAACFBartlettLLH); 1435 DefExtOpr(1, BDatARMAACFBartlettLLH, "ARMA.ACF.Bartlett.LLH", 4, 4, 1436 "Polyn Polyn Matrix Real", 1437 "(Polyn ar, Polyn ma, Matrix acf, Real T)", 1438 I2("Calculates the log-likelihood of asymptotic distribution of sample " 1439 "autocorrelation of orders from 1 to n of an ARMA noise of size T.", 1440 "Calcula la log-verosimilitud de la distribución aintótica " 1441 "de las autocorrelaciones muestrales de órdenes 1 a n de un ruido " 1442 "ARMA de tamañlo T"), 1443 BOperClassify::Sthocastic_); 1444 //-------------------------------------------------------------------- 1445 void BDatARMAACFBartlettLLH::CalcContens() 1435 static BDat ARMAACFBartlettLLH_Theorical( 1436 const BPol& ar, 1437 const BPol& ma, 1438 const BMat& acf, 1439 int T, 1440 int n, 1441 int s) 1446 1442 //-------------------------------------------------------------------- 1447 1443 { 1448 1444 static double _05log2pi = 0.5*log(2*3.14159265358979323846); 1449 BPol& ar = Pol(Arg(1));1450 BPol& ma = Pol(Arg(2));1451 BMat& acf = Mat(Arg(3));1452 int T = (int)Real(Arg(4));1453 int n = acf.Data().Size();1454 int s = T*2;1455 1445 int res; 1456 1446 BMat rho, rho_, dif, cov, L, eps; … … 1476 1466 eps_sumSqr += *eps_i * *eps_i; 1477 1467 } 1478 contens_ = -n*_05log2pi-0.5*eps_sumSqr- 0.5*log_det; 1468 return(- n*_05log2pi - 0.5*eps_sumSqr - log_det); 1469 } 1470 1471 //-------------------------------------------------------------------- 1472 static BDat ARMAACFBartlettLLH_Sampling( 1473 const BPol& ar, 1474 const BPol& ma, 1475 const BMat& acf, 1476 int T, 1477 int n, 1478 int s, 1479 const BMat& L) 1480 //-------------------------------------------------------------------- 1481 { 1482 static double _05log2pi = 0.5*log(2*3.14159265358979323846); 1483 int res; 1484 BMat rho, dif, eps; 1485 BDat alpha = 1.0; 1486 BArray<BDat> gn; 1487 int i; 1488 1489 ARMAAutoCovarianzeVector(gn,ar,ma,n+1,1); 1490 rho = BMatrix<BDat>(n,1,gn.Buffer()+1) / gn[0]; 1491 dif = acf-rho; 1492 1493 res = TolBlas::dtrsm(CblasLeft,CblasLower,CblasNoTrans,CblasNonUnit,alpha, 1494 L,dif,eps); 1495 1496 const BDat* eps_i = eps.Data().Buffer(); 1497 BDat eps_sumSqr = 0; 1498 BDat log_det_L = 0; 1499 for(i=0; i<n; i++, eps_i++) 1500 { 1501 log_det_L += Log(L(i,i)); 1502 eps_sumSqr += *eps_i * *eps_i; 1503 } 1504 return(- n*_05log2pi - 0.5*eps_sumSqr - log_det_L); 1505 } 1506 1507 //-------------------------------------------------------------------- 1508 DeclareContensClass(BDat, BDatTemporary, BDatARMAACFBartlettLLH); 1509 DefExtOpr(1, BDatARMAACFBartlettLLH, "ARMA.ACF.Bartlett.LLH", 4, 4, 1510 "Polyn Polyn Matrix Real", 1511 "(Polyn ar, Polyn ma, Matrix acf, Real T)", 1512 I2("Calculates the log-likelihood of asymptotic distribution of sample " 1513 "autocorrelation acf of an ARMA noise z of size T and equations " 1514 "ar(B)*z= ma(B)*e", 1515 "Calcula la log-verosimilitud de la distribución aintótica " 1516 "de las autocorrelaciones muestrales de un ruido " 1517 "ARMA z de tamaño T y ecuaciones " 1518 "ar(B)*z= ma(B)*e"), 1519 BOperClassify::Sthocastic_); 1520 //-------------------------------------------------------------------- 1521 void BDatARMAACFBartlettLLH::CalcContens() 1522 //-------------------------------------------------------------------- 1523 { 1524 BPol& ar = Pol(Arg(1)); 1525 BPol& ma = Pol(Arg(2)); 1526 BMat& acf = Mat(Arg(3)); 1527 int T = (int)Real(Arg(4)); 1528 int n = acf.Data().Size(); 1529 int s = T*2; 1530 contens_ = ARMAACFBartlettLLH_Theorical(ar,ma,acf,T,n,s); 1531 } 1532 1533 1534 //-------------------------------------------------------------------- 1535 DeclareContensClass(BMat, BMatTemporary, BMatARMAACFBartlettLLHRandStationary); 1536 DefExtOpr(1, BMatARMAACFBartlettLLHRandStationary, 1537 "ARMA.ACF.Bartlett.LLH.RandStationary", 6, 6, 1538 "Real Real Matrix Real Real Real", 1539 "(Real p, Real q, Matrix acf, Real T, Real sampleSize, Real exact)", 1540 I2("Draws the log-likelihood of asymptotic distribution of sample " 1541 "autocorrelation of orders from 1 to n of an ARMA noise of size T." 1542 "Generates stationary polynomials AR and MA of degrees p and q " 1543 "with uniform distributed modules of roots.", 1544 "Simula la log-verosimilitud de la distribución aintótica " 1545 "de las autocorrelaciones muestrales de órdenes 1 a n de un ruido " 1546 "ARMA de tamaño T.\n" 1547 "Genera polinomios AR y MA estacionarios de grados p y q de forma " 1548 "uniforme en el módulo de las raíces."), 1549 BOperClassify::Sthocastic_); 1550 //-------------------------------------------------------------------- 1551 void BMatARMAACFBartlettLLHRandStationary::CalcContens() 1552 //-------------------------------------------------------------------- 1553 { 1554 int p = (int)Real(Arg(1)); 1555 int q = (int)Real(Arg(2)); 1556 BMat& acf = Mat(Arg(3)); 1557 int T = (int)Real(Arg(4)); 1558 int sampleSize = (int)Real(Arg(5)); 1559 bool exact = (int)Real(Arg(6)); 1560 int n = acf.Data().Size(); 1561 int s = T*2; 1562 contens_.Alloc(sampleSize,1); 1563 int k; 1564 int res; 1565 BPol ar, ma; 1566 BMat cov, L; 1567 if(!exact) 1568 { 1569 _covACF_Bartlett(cov,acf,n,T,s); 1570 res = TolLapack::dpotrf(CblasLower,cov,L); 1571 }; 1572 for(k=0; k<sampleSize; k++) 1573 { 1574 ar = RandStationary(p,1); 1575 ma = RandStationary(q,1); 1576 if(exact) 1577 { 1578 contens_(k,0) = ARMAACFBartlettLLH_Theorical(ar,ma,acf,T,n,s); 1579 } 1580 else 1581 { 1582 contens_(k,0) = ARMAACFBartlettLLH_Sampling(ar,ma,acf,T,n,s,L); 1583 } 1584 } 1479 1585 } 1480 1586 -
tol/btol/polynomial_type/polgra.cpp
rd072dc9 r7427dd4c 492 492 493 493 //-------------------------------------------------------------------- 494 DeclareContensClass(BPol, BPolTemporary, BPolRandStationary); 495 DefExtOpr(1, BPolRandStationary, "RandStationary", 1, 2, "Real Real", 496 "(Real d [, Real p = 1])", 497 I2("Returns a random stationary polinomial as \n", 498 "Devuelve un polinomio estacionario aleatorio de la forma \n") + 499 " 1 - C1 * B^p - C2 * B^(2*p) - ... - Cd * B^(d*p).", 500 BOperClassify::RetardPolynomial_); 501 //-------------------------------------------------------------------- 502 void BPolRandStationary::CalcContens() 503 //-------------------------------------------------------------------- 504 { 505 BInt degree = (BInt)Real(Arg(1)); 506 BInt period = 1; 494 BPol RandStationary(BInt degree, BInt period) 495 //-------------------------------------------------------------------- 496 { 507 497 BInt n2 = degree/2; 508 498 BInt n1 = degree-2*n2; … … 511 501 BUniformDist u(-1+2*DEpsilon(),1-2*DEpsilon()); 512 502 BDat a, b; 513 514 if(Arg(2)) { period = (BInt)Real(Arg(2)); }515 503 BPol BP = BPol::X() ^ period; 516 504 if(n1) … … 527 515 p2 *= (BPol::One()-b*BP-a*(BP^2)); 528 516 } 529 contens_ = p1 * p2; 517 return(p1 * p2); 518 } 519 520 //-------------------------------------------------------------------- 521 DeclareContensClass(BPol, BPolTemporary, BPolRandStationary); 522 DefExtOpr(1, BPolRandStationary, "RandStationary", 1, 2, "Real Real", 523 "(Real d [, Real p = 1])", 524 I2("Returns a random stationary polinomial as \n", 525 "Devuelve un polinomio estacionario aleatorio de la forma \n") + 526 " 1 - C1 * B^p - C2 * B^(2*p) - ... - Cd * B^(d*p).", 527 BOperClassify::RetardPolynomial_); 528 //-------------------------------------------------------------------- 529 void BPolRandStationary::CalcContens() 530 //-------------------------------------------------------------------- 531 { 532 BInt degree = (BInt)Real(Arg(1)); 533 BInt period = 1; 534 if(Arg(2)) { period = (BInt)Real(Arg(2)); } 535 contens_ = RandStationary(degree, period); 530 536 } 531 537 -
tol/btol/polynomial_type/tol_bpolgra.h
rd072dc9 r7427dd4c 40 40 template class TOL_API BGraContens < BPol >; 41 41 42 TOL_API BPol EvalPolyn(const BText& expr, const BPol& defVal); 42 TOL_API BPol EvalPolyn(const BText& expr, const BPol& defVal); 43 TOL_API BPol RandStationary(BInt degree, BInt period); 44 43 45 44 46 //--------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.
